modify add ipcam api
This commit is contained in:
parent
5113518997
commit
af1d96062a
4
app.js
4
app.js
@ -54,6 +54,10 @@ app.get(['/admin', '/admin/*'], (req, res) => {
|
|||||||
res.sendFile(path.resolve(__dirname, 'views', 'admin.html'));
|
res.sendFile(path.resolve(__dirname, 'views', 'admin.html'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get('/camevent', (req, res) => {
|
||||||
|
res.send(0);
|
||||||
|
})
|
||||||
|
|
||||||
app.get('/servcmd', (req, res) => {
|
app.get('/servcmd', (req, res) => {
|
||||||
res.send({ status: `exit time ${Date.now()}` });
|
res.send({ status: `exit time ${Date.now()}` });
|
||||||
setTimeout(() => { process.exit(1) }, 2000);
|
setTimeout(() => { process.exit(1) }, 2000);
|
||||||
|
@ -4,7 +4,8 @@
|
|||||||
},
|
},
|
||||||
"uni_token": "webiounitoken",
|
"uni_token": "webiounitoken",
|
||||||
"perpage": 10,
|
"perpage": 10,
|
||||||
"leone_limie": 40,
|
"leone_limit": 40,
|
||||||
|
"ipcam_limit": 4,
|
||||||
"db": {
|
"db": {
|
||||||
"user": "root",
|
"user": "root",
|
||||||
"pass": "16055536",
|
"pass": "16055536",
|
||||||
@ -46,6 +47,7 @@
|
|||||||
"iocmd": "/home/www/cmd/cmdio",
|
"iocmd": "/home/www/cmd/cmdio",
|
||||||
"leonert": "/home/www/tmp/rtles",
|
"leonert": "/home/www/tmp/rtles",
|
||||||
"htsrt": "/home/www/tmp/rthts",
|
"htsrt": "/home/www/tmp/rthts",
|
||||||
"version": "/factory/webioa_version"
|
"version": "/factory/webioa_version",
|
||||||
|
"ipcamsave": "/home/www/cam"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -69,6 +69,7 @@
|
|||||||
"ERR0067": "型號輸入錯誤",
|
"ERR0067": "型號輸入錯誤",
|
||||||
"ERR0068": "事件數量輸入錯誤",
|
"ERR0068": "事件數量輸入錯誤",
|
||||||
"ERR0069": "圖片數量輸入錯誤",
|
"ERR0069": "圖片數量輸入錯誤",
|
||||||
|
"ERR0070": "IPCam 裝置已達上限",
|
||||||
|
|
||||||
"ERR7000": "命令執行失敗",
|
"ERR7000": "命令執行失敗",
|
||||||
|
|
||||||
|
@ -55,26 +55,69 @@ router
|
|||||||
|
|
||||||
let active = arr.data.active == 1 ? 1 : 0;
|
let active = arr.data.active == 1 ? 1 : 0;
|
||||||
|
|
||||||
let query = "select count(*) as c from ??.?? where `ip` = ?";
|
!async function runSync() {
|
||||||
let param = [config.db.db1, 'jcioccamset', arr.data.ip];
|
// data flag 0 is insert, 1 is update
|
||||||
res.db.query(query, param, (err, row) => {
|
let flag = 0;
|
||||||
if (err || row.length == 0) return rt.err(res, err, n, 'ERR8000');
|
let idx = 1;
|
||||||
|
// query db data
|
||||||
|
try {
|
||||||
|
let query = "select `uid` from ??.?? order by `uid` desc limit 1";
|
||||||
|
let param = [config.db.db1, 'jcioccamset'];
|
||||||
|
let id = await tool.promiseQuery(res, query, param);
|
||||||
|
|
||||||
if (row[0].c >= 1) return n('ERR0027');
|
if (id.data.length > 0 && id.data[0].uid) idx = id.data[0].uid + 1;
|
||||||
|
if (idx > config.ipcam_limit) {
|
||||||
let query = "insert into ??.?? (`ip`, `name`, `model`, `maxevents`, `maximg`, `active`, `cuser`, `muser`, `ctime`, `mtime` ) \
|
query = "select `uid` from ??.?? where `delete` = 1 limit 1";
|
||||||
values (?, ?, ?, ?, ?, ?, ?, ?, unix_timestamp(), unix_timestamp())";
|
flag = 1;
|
||||||
let param = [config.db.db1, 'jcioccamset', arr.data.ip, arr.data.name, arr.data.model, arr.data.maxevents, arr.data.maximg, active, u, u];
|
let id = await tool.promiseQuery(res, query, param);
|
||||||
|
if (id.data.length > 0 && id.data[0].uid) idx = id.data[0].uid;
|
||||||
res.db.query(query, param, (err, row) => {
|
else return n('ERR0070');
|
||||||
if (err) return rt.err(res, err, n, 'ERR8001');
|
|
||||||
|
|
||||||
res.api_res = {
|
|
||||||
record: []
|
|
||||||
}
|
}
|
||||||
n();
|
|
||||||
})
|
query = "select count(*) as c from ??.?? where `ip` = ?";
|
||||||
})
|
param = [config.db.db1, 'jcioccamset', arr.data.ip];
|
||||||
|
let count = await tool.promiseQuery(res, query, param);
|
||||||
|
if (count.data.length == 0) return n('ERR8000');
|
||||||
|
if (count.data[0].c >= 1) return n('ERR0027');
|
||||||
|
} catch (e) {
|
||||||
|
return rt.err(res, e, n, 'ERR8000');
|
||||||
|
}
|
||||||
|
if (flag == 1) {
|
||||||
|
try {
|
||||||
|
let query = "update ??.?? set \
|
||||||
|
`ip` = ?, \
|
||||||
|
`name` = ?, \
|
||||||
|
`model` = ?, \
|
||||||
|
`maxevents` = ?, \
|
||||||
|
`maximg` = ?, \
|
||||||
|
`active` = ?, \
|
||||||
|
`delete` = 0, \
|
||||||
|
`muser` = ?, \
|
||||||
|
`mtime` = unix_timestamp() \
|
||||||
|
where \
|
||||||
|
`uid` = ?";
|
||||||
|
let param = [config.db.db1, 'jcioccamset', arr.data.ip, arr.data.name, arr.data.model, arr.data.maxevents, arr.data.maximg, active, u, arr.data.id];
|
||||||
|
await tool.promiseQuery(res, query, param);
|
||||||
|
} catch (e) {
|
||||||
|
return rt.err(res, e, n, 'ERR8002');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
let query = "insert into ??.?? (`uid`, `ip`, `name`, `model`, `maxevents`, `maximg`, `active`, `cuser`, `muser`, `ctime`, `mtime` ) \
|
||||||
|
values (?, ?, ?, ?, ?, ?, ?, ?, ?, unix_timestamp(), unix_timestamp())";
|
||||||
|
let param = [config.db.db1, 'jcioccamset', idx, arr.data.ip, arr.data.name, arr.data.model, arr.data.maxevents, arr.data.maximg, active, u, u];
|
||||||
|
await tool.promiseQuery(res, query, param);
|
||||||
|
} catch (e) {
|
||||||
|
return rt.err(res, e, n, 'ERR8001');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
res.api_res = {
|
||||||
|
record: []
|
||||||
|
}
|
||||||
|
return n();
|
||||||
|
}()
|
||||||
|
|
||||||
})
|
})
|
||||||
.post('/editipcam', (req, res, n) => {
|
.post('/editipcam', (req, res, n) => {
|
||||||
if (!config.permission.ipcam) return n('ERR9000');
|
if (!config.permission.ipcam) return n('ERR9000');
|
||||||
|
Loading…
Reference in New Issue
Block a user