fix copy tracker empty
This commit is contained in:
parent
da8d811c68
commit
f9fa110208
@ -3,7 +3,7 @@ const glob = require("glob");
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`);
|
||||
const currentmod="Trackings"
|
||||
const currentmod = "Trackings";
|
||||
const log = conf.api.activelog.includes(currentmod);
|
||||
const Odmdb = require("../models/Odmdb.js");
|
||||
// Middlewares
|
||||
@ -11,7 +11,6 @@ const checkHeaders = require("../middlewares/checkHeaders");
|
||||
const isAuthenticated = require("../middlewares/isAuthenticated");
|
||||
const router = express.Router();
|
||||
|
||||
|
||||
/**
|
||||
* @api {post} adminapi/trackings/newdevice - Post new device
|
||||
* @apiName adddevice
|
||||
@ -32,47 +31,71 @@ const router = express.Router();
|
||||
* HTTP/1.1 200 OK
|
||||
* {"status":200, "ref":"Trackings", "msg":"successfullupdate", "data":{}}
|
||||
*/
|
||||
router.post("/newdevice", checkHeaders, async (req, res) => {
|
||||
router.post("/newdevice", checkHeaders, async (req, res) => {
|
||||
if (log) console.log(currentmod, "post new device with", req.body);
|
||||
const newdevice= {status: 200,
|
||||
ref: "Trackings",
|
||||
msg: "success",
|
||||
data: {},
|
||||
};
|
||||
const newdevice = { status: 200, ref: "Trackings", msg: "success", data: {} };
|
||||
const role = {
|
||||
xalias: req.session.header.xalias,
|
||||
xprofils: req.session.header.xprofils,
|
||||
};
|
||||
const devicepath=`../${req.session.header.xtribe}/objects/devices/itm/${req.session.header.xuuid}.json`;
|
||||
const device=req.body;
|
||||
device.xuuid=req.session.header.xuuid
|
||||
if (req.session.header.xalias!="anonymous"){
|
||||
device.alias=req.session.header.xalias
|
||||
if (!fs.pathExistsSync(`../${req.session.header.xtribe}/objects/devices`)) {
|
||||
fs.mkdirSync(`../${req.session.header.xtribe}/objects/devices/itm/`, {
|
||||
recursive: true,
|
||||
});
|
||||
fs.mkdirSync(`../${req.session.header.xtribe}/objects/devices/idx/`, {
|
||||
recursive: true,
|
||||
});
|
||||
const confdevice = {
|
||||
name: "devices",
|
||||
schema: "adminapi/schema/devices.json",
|
||||
lastupdate: 0,
|
||||
lastupdatedata: "2025-02-23T09:23:56.266Z",
|
||||
};
|
||||
fs.outputFileSync(
|
||||
`../${req.session.header.xtribe}/objects/devices/conf.json`,
|
||||
confdevice
|
||||
);
|
||||
}
|
||||
if (await fs.pathExists(devicepath)){
|
||||
const updatedevice=Odmdb.cud(`../${req.session.header.xtribe}/objects/devices`,"U",device,role);
|
||||
if (updatedevice.status==200){
|
||||
newdevice.msg="successfullupdate"
|
||||
}else{
|
||||
newdevice.status=updatedevice.status
|
||||
newdevice.msg=updatedevice.msg
|
||||
newdevice.data=updatedevice.data
|
||||
if (updatedevice.multimsg) newdevice.multimsg=updatedevice.multimsg
|
||||
const devicepath = `../${req.session.header.xtribe}/objects/devices/itm/${req.session.header.xuuid}.json`;
|
||||
const device = req.body;
|
||||
device.xuuid = req.session.header.xuuid;
|
||||
if (req.session.header.xalias != "anonymous") {
|
||||
device.alias = req.session.header.xalias;
|
||||
}
|
||||
}else{
|
||||
const createdevice = Odmdb.cud(`../${req.session.header.xtribe}/objects/devices`,"C",device,role);
|
||||
console.log(createdevice)
|
||||
if (createdevice.status==200) {
|
||||
newdevice.msg="successfullcreate"
|
||||
}else{
|
||||
newdevice.status=createdevice.status
|
||||
newdevice.msg=createdevice.msg
|
||||
newdevice.data=createdevice.data
|
||||
if (createdevice.multimsg) newdevice.multimsg=createdevice.multimsg
|
||||
if (await fs.pathExists(devicepath)) {
|
||||
const updatedevice = Odmdb.cud(
|
||||
`../${req.session.header.xtribe}/objects/devices`,
|
||||
"U",
|
||||
device,
|
||||
role
|
||||
);
|
||||
if (updatedevice.status == 200) {
|
||||
newdevice.msg = "successfullupdate";
|
||||
} else {
|
||||
newdevice.status = updatedevice.status;
|
||||
newdevice.msg = updatedevice.msg;
|
||||
newdevice.data = updatedevice.data;
|
||||
if (updatedevice.multimsg) newdevice.multimsg = updatedevice.multimsg;
|
||||
}
|
||||
} else {
|
||||
const createdevice = Odmdb.cud(
|
||||
`../${req.session.header.xtribe}/objects/devices`,
|
||||
"C",
|
||||
device,
|
||||
role
|
||||
);
|
||||
console.log(createdevice);
|
||||
if (createdevice.status == 200) {
|
||||
newdevice.msg = "successfullcreate";
|
||||
} else {
|
||||
newdevice.status = createdevice.status;
|
||||
newdevice.msg = createdevice.msg;
|
||||
newdevice.data = createdevice.data;
|
||||
if (createdevice.multimsg) newdevice.multimsg = createdevice.multimsg;
|
||||
}
|
||||
}
|
||||
res.status(newdevice.status).json(newdevice);
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* @api {get} https://dns.xx/trk/pathtofile? - tracking system
|
||||
@ -132,5 +155,4 @@ const router = express.Router();
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
module.exports=router;
|
||||
module.exports = router;
|
||||
|
Loading…
x
Reference in New Issue
Block a user