This commit is contained in:
Akshay
2023-10-08 22:12:13 +05:30
parent 930218c067
commit e5a875856a

View File

@@ -6,6 +6,8 @@ const server = jsonServer.create();
const router = jsonServer.router("./src/mocks/db.json"); const router = jsonServer.router("./src/mocks/db.json");
const middlewares = jsonServer.defaults(); const middlewares = jsonServer.defaults();
const localStorage = [];
server.use(middlewares); server.use(middlewares);
server.use((req, res, next) => { server.use((req, res, next) => {
@@ -14,7 +16,7 @@ server.use((req, res, next) => {
req.method = "DELETE"; req.method = "DELETE";
} else if (req.url === "/upload") { } else if (req.url === "/upload") {
const taskId = uuid(); const taskId = uuid();
localStorage.setItem(taskId, true); localStorage.push(taskId);
} }
} }
next(); next();
@@ -27,7 +29,7 @@ router.render = (req, res) => {
res.status(200).jsonp({ status: "ok" }); res.status(200).jsonp({ status: "ok" });
} else if (req.url.includes("/task_status")) { } else if (req.url.includes("/task_status")) {
const taskId = req.query["task_id"]; const taskId = req.query["task_id"];
const taskIdExists = localStorage.getItem(taskId); const taskIdExists = localStorage.includes(taskId);
if (taskIdExists) { if (taskIdExists) {
res.status(200).jsonp({ res.status(200).jsonp({
result: { result: {
@@ -40,7 +42,7 @@ router.render = (req, res) => {
status: "SUCCESS", status: "SUCCESS",
}); });
} else { } else {
res.status(404); res.status(404).jsonp({});
} }
} }
}; };