add ipcam set page
This commit is contained in:
+111
-42
@@ -13,22 +13,22 @@ router
|
||||
.get('/', (req, res, n) => {
|
||||
res.send({ name: 'WebIO IPCam API' });
|
||||
})
|
||||
.post('*', async(req,res,n) => {
|
||||
try{
|
||||
.post('*', async(req, res, n) => {
|
||||
try {
|
||||
res.db = await mysql.getConn();
|
||||
}catch(e){
|
||||
} catch (e) {
|
||||
console.log(`Get DB Connection ERROR ${e}`);
|
||||
return n('ERR8100');
|
||||
}
|
||||
n();
|
||||
})
|
||||
.post('/getipcamlist', (req,res,n) => {
|
||||
if(!config.permission.ipcam) return n('ERR9000');
|
||||
.post('/getipcamlist', (req, res, n) => {
|
||||
if (!config.permission.ipcam) return n('ERR9000');
|
||||
|
||||
let query = "select * from ??.??";
|
||||
let param = [config.db.db1, 'ipcam'];
|
||||
let param = [config.db.db1, 'jcioccamset'];
|
||||
res.db.query(query, param, (err, row) => {
|
||||
if(err) return rt.err(res,err,n,'ERR8000');
|
||||
if (err) return rt.err(res, err, n, 'ERR8000');
|
||||
|
||||
res.api_res = {
|
||||
record: tool.checkArray(row)
|
||||
@@ -37,62 +37,131 @@ router
|
||||
n();
|
||||
});
|
||||
})
|
||||
.post('/addipcam', (req,res,n) => {
|
||||
if(!config.permission.ipcam) return n('ERR9000');
|
||||
if(!tool.checkPermission(req)) return n('ERR9000');
|
||||
.post('/addipcam', (req, res, n) => {
|
||||
if (!config.permission.ipcam) return n('ERR9000');
|
||||
if (!tool.checkPermission(req)) return n('ERR9000');
|
||||
let arr = req.body;
|
||||
if(!arr.data) return n('ERR0000');
|
||||
if(!arr.data.ip) return n('ERR0010');
|
||||
if(!arr.data.name) return n('ERR0026');
|
||||
|
||||
if(!/^\d{1,3}\.\d{1,3}.\d{1,3}.\d{1,3}$/.test(arr.data.ip)) return n('ERR0025');
|
||||
if (!arr.data) return n('ERR0000');
|
||||
if (!arr.data.ip) return n("ERR0010");
|
||||
if (!arr.data.name) return n('ERR0026');
|
||||
if (!arr.data.model) return n('ERR0067');
|
||||
if (!arr.data.maxevents) return n('ERR0068');
|
||||
if (!arr.data.maximg) return n('ERR0069');
|
||||
if (!/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(arr.data.ip)) return n('ERR0025');
|
||||
|
||||
let u = '';
|
||||
let obj = so.get(req.headers['x-auth-token'] || '');
|
||||
if (obj != null && 'user' in obj && 'account' in obj.user) u = obj.user.account;
|
||||
|
||||
let active = arr.data.active == 1 ? 1 : 0;
|
||||
|
||||
let query = "select count(*) as c from ??.?? where `ip` = ?";
|
||||
let param = [config.db.db1, 'ipcam', arr.data.ip];
|
||||
let param = [config.db.db1, 'jcioccamset', arr.data.ip];
|
||||
res.db.query(query, param, (err, row) => {
|
||||
if(err || row.length == 0) return rt.err(res,err,n,'ERR8000');
|
||||
if(row[0]['c'] > 0) return n('ERR0027');
|
||||
if (err || row.length == 0) return rt.err(res, err, n, 'ERR8000');
|
||||
|
||||
if (row[0].c >= 1) return n('ERR0027');
|
||||
|
||||
let query = "insert into ??.?? (`ip`, `name`, `model`, `maxevents`, `maximg`, `active`, `cuser`, `muser`, `ctime`, `mtime` ) \
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?, unix_timestamp(), unix_timestamp())";
|
||||
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 query = "insert into ??.?? (`name`, `ip`) values (?,?)";
|
||||
let param = [config.db.db1, 'ipcam', arr.data.name, arr.data.ip];
|
||||
res.db.query(query, param, (err, row) => {
|
||||
if(err) return rt.err(res,err,n,'ERR8001');
|
||||
if (err) return rt.err(res, err, n, 'ERR8001');
|
||||
|
||||
res.api_res = {
|
||||
record: []
|
||||
};
|
||||
}
|
||||
n();
|
||||
});
|
||||
})
|
||||
})
|
||||
})
|
||||
.post('/editipcam', (req, res, n) => {
|
||||
if (!config.permission.ipcam) return n('ERR9000');
|
||||
if (!tool.checkPermission(req)) return n('ERR9000');
|
||||
let arr = req.body;
|
||||
if (!arr.data) return n('ERR0000');
|
||||
if (!arr.data.id) return n('ERR0028');
|
||||
if (!arr.data.ip) return n("ERR0010");
|
||||
if (!arr.data.name) return n('ERR0026');
|
||||
if (!arr.data.model) return n('ERR0067');
|
||||
if (!arr.data.maxevents) return n('ERR0068');
|
||||
if (!arr.data.maximg) return n('ERR0069');
|
||||
if (!/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(arr.data.ip)) return n('ERR0025');
|
||||
|
||||
let u = '';
|
||||
let obj = so.get(req.headers['x-auth-token'] || '');
|
||||
if (obj != null && 'user' in obj && 'account' in obj.user) u = obj.user.account;
|
||||
|
||||
let active = arr.data.active == 1 ? 1 : 0;
|
||||
|
||||
let query = "select count(*) as c from ??.?? where `ip` = ? and `uid` != ?";
|
||||
let param = [config.db.db1, 'jcioccamset', arr.data.ip, arr.data.id];
|
||||
|
||||
res.db.query(query, param, (err, row) => {
|
||||
if (err || row.length == 0) return rt.err(res, err, n, 'ERR8000');
|
||||
|
||||
if (row[0].c >= 1) return n('ERR0027');
|
||||
|
||||
let query = "update ??.?? set \
|
||||
`ip` = ?, \
|
||||
`name` = ?, \
|
||||
`model` = ?, \
|
||||
`maxevents` = ?, \
|
||||
`maximg` = ?, \
|
||||
`active` = ?, \
|
||||
`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];
|
||||
res.db.query(query, param, (err, row) => {
|
||||
if (err) return rt.err(res, err, n, 'ERR8002');
|
||||
|
||||
res.api_res = {
|
||||
record: []
|
||||
}
|
||||
n();
|
||||
})
|
||||
});
|
||||
})
|
||||
.post('/delipcam', (req,res,n) => {
|
||||
if(!config.permission.ipcam) return n('ERR9000');
|
||||
if(!tool.checkPermission(req)) return n('ERR9000');
|
||||
.post('/delipcam', (req, res, n) => {
|
||||
if (!config.permission.ipcam) return n('ERR9000');
|
||||
if (!tool.checkPermission(req)) return n('ERR9000');
|
||||
let arr = req.body;
|
||||
if(!arr.data) return n('ERR0000');
|
||||
if(!arr.data.id) return n('ERR0028');
|
||||
if (!arr.data) return n('ERR0000');
|
||||
if (!arr.data.id) return n('ERR0028');
|
||||
|
||||
res.db.query(`use ${config.db.db1}`);
|
||||
let query = "delete from ??.?? \
|
||||
where `uid` = ?";
|
||||
let param = [config.db.db1, 'jcioccamset', arr.data.id];
|
||||
|
||||
let query = "delete from ??.?? where `uid` = ?";
|
||||
let param = [config.db.db1, 'ipcam', arr.data.id];
|
||||
res.db.query(query, param, (err, row) => {
|
||||
if(err) return rt.err(res,err,n,'ERR8003');
|
||||
if (err) return rt.err(res, err, n, 'ERR8003');
|
||||
|
||||
res.api_res = {
|
||||
record: []
|
||||
};
|
||||
}
|
||||
n();
|
||||
})
|
||||
})
|
||||
.post('/editipcam', (req,res,n) => {
|
||||
if(!config.permission.ipcam) return n('ERR9000');
|
||||
if(!tool.checkPermission(req)) return n('ERR9000');
|
||||
.post('/swipcamactive', (req, res, n) => {
|
||||
if (!config.permission.ipcam) return n('ERR9000');
|
||||
if (!tool.checkPermission(req)) return n('ERR9000');
|
||||
let arr = req.body;
|
||||
if(!arr.data) return n('ERR0000');
|
||||
if(!arr.data.id) return n('ERR0028');
|
||||
if(!arr.data.name) return n('ERR0026');
|
||||
if (!arr.data) return n('ERR0000');
|
||||
if (!arr.data.id) return n('ERR0028');
|
||||
|
||||
let query = "update ??.?? set \
|
||||
`active` = case when `active` = 1 then 0 else 1 end \
|
||||
where \
|
||||
`uid` = ?";
|
||||
let param = [config.db.db1, 'jcioccamset', arr.data.id];
|
||||
|
||||
res.db.query(query, param, (err, row) => {
|
||||
if (err) return rt.err(res, err, n, 'ERR8002');
|
||||
|
||||
let query = "update ??.?? set `name` = ? where `uid` = ?";
|
||||
let param = [config.db.db1, 'ipcam', arr.data.name, arr.data.id];
|
||||
res.db.query(query, param, (err,row) => {
|
||||
if(err) return rt.err(res,err,n,'ERR8002');
|
||||
res.api_res = {
|
||||
record: []
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user