Remove UI dependance on NBI

This commit is contained in:
Shweelan Samson authored and Zaid Abdulla committed 2019-02-07 00:18:19 -08:00
1 parent 520cc43972
commit d46d133878
5 files changed
+285 -341

No files matched your search

+21 -12
View File
@@ -7,6 +7,7 @@ import * as apiFunctions from "./api-functions";
import { evaluate, and, extractParams } from "../common/expression";
import { parse } from "../common/expression-parser";
import * as logger from "../logger";
import { getConfig } from "../local-cache";
const router = new Router();
export default router;
@@ -400,15 +401,7 @@ router.put("/files/:id", async (ctx, next) => {
return void (ctx.status = 403);
}
const err = await apiFunctions.putFile(id, metadata, ctx.req);
if (err) {
log.message += " failed";
logger.accessWarn(log);
ctx.body = err;
return void (ctx.status = 400);
}
await db.putFile(id, metadata, ctx.req);
log.metadata = metadata;
logger.accessInfo(log);
@@ -439,7 +432,17 @@ router.post("/devices/:id/tasks", async (ctx, next) => {
}
}
const res = await apiFunctions.postTasks(ctx.params.id, ctx.request.body);
// TODO Pass context and timestamp
const onlineThreshold = getConfig(
ctx.state.configSnapshot,
"cwmp.deviceOnlineThreshold"
);
const res = await apiFunctions.postTasks(
ctx.params.id,
ctx.request.body,
onlineThreshold
);
log.tasks = res.tasks.map(t => t._id).join(",");
@@ -472,7 +475,7 @@ router.post("/devices/:id/tags", async (ctx, next) => {
return void (ctx.status = 403);
}
await apiFunctions.updateTags(ctx.params.id, ctx.request.body);
await db.updateDeviceTags(ctx.params.id, ctx.request.body);
logger.accessInfo(log);
@@ -480,5 +483,11 @@ router.post("/devices/:id/tags", async (ctx, next) => {
});
router.get("/ping/:host", async ctx => {
ctx.body = await apiFunctions.ping(ctx.params.host);
try {
ctx.body = await apiFunctions.ping(ctx.params.host);
} catch (err) {
ctx.status = 404;
ctx.response.headers["Cache-Control"] = "no-cache";
ctx.body = `${err.name}: ${err.message}`;
}
});