add ipcam api
This commit is contained in:
parent
493dd36e18
commit
e2040a181e
@ -11,24 +11,10 @@ const crypt = require('../../libs/crypto');
|
|||||||
|
|
||||||
router
|
router
|
||||||
.get('/', (req, res, n) => {
|
.get('/', (req, res, n) => {
|
||||||
// res.db = new mysql();
|
|
||||||
// res.db.user = config.db.user;
|
|
||||||
// res.db.password = config.db.pass;
|
|
||||||
// res.db.host = config.db.host;
|
|
||||||
// res.db.port = config.db.port;
|
|
||||||
// res.db.database = config.db.db1;
|
|
||||||
// res.db.connect();
|
|
||||||
|
|
||||||
res.send({ name: 'WebIO IPCam API' });
|
res.send({ name: 'WebIO IPCam API' });
|
||||||
})
|
})
|
||||||
.post('/getipcamlist', async (req,res,n) => {
|
.post('/getipcamlist', (req,res,n) => {
|
||||||
if(!config.permission.ipcam) return n('ERR9000');
|
if(!config.permission.ipcam) return n('ERR9000');
|
||||||
|
|
||||||
try{
|
|
||||||
res.db = await mysql.getConn();
|
|
||||||
}catch(e){
|
|
||||||
return n('ERR8100');
|
|
||||||
}
|
|
||||||
|
|
||||||
let query = "select * from ??.??";
|
let query = "select * from ??.??";
|
||||||
let param = [config.db.db1, 'ipcam'];
|
let param = [config.db.db1, 'ipcam'];
|
||||||
@ -52,14 +38,57 @@ router
|
|||||||
|
|
||||||
if(!/^\d{1,3}\.\d{1,3}.\d{1,3}.\d{1,3}$/.test(arr.data.ip)) return n('ERR0025');
|
if(!/^\d{1,3}\.\d{1,3}.\d{1,3}.\d{1,3}$/.test(arr.data.ip)) return n('ERR0025');
|
||||||
|
|
||||||
// res.db = new mysql();
|
let query = "select count(*) as c from ??.?? where `ip` = ?";
|
||||||
// res.db.user = config.db.user;
|
let param = [config.db.db1, 'ipcam', arr.data.ip];
|
||||||
// res.db.password = config.db.pass;
|
res.db.query(query, param, (err, row) => {
|
||||||
// res.db.host = config.db.host;
|
if(err || row.length == 0) return n('ERR8000');
|
||||||
// res.db.port = config.db.port;
|
if(row[0]['c'] > 0) return n('ERR0027');
|
||||||
// res.db.database = config.db.db1;
|
|
||||||
// res.db.connect();
|
let query = "insert into ??.?? (`name`, `ip`) values (?,?)";
|
||||||
res.send('aaa');
|
let param = [config.db.db1, 'ipcam', arr.data.name, arr.data.ip];
|
||||||
|
res.db.query(query, param, (err, row) => {
|
||||||
|
if(err) return n('ERR8001');
|
||||||
|
res.api_res = {
|
||||||
|
record: []
|
||||||
|
};
|
||||||
|
n();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.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');
|
||||||
|
|
||||||
|
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 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');
|
||||||
|
let arr = req.body;
|
||||||
|
if(!arr.data) return n('ERR0000');
|
||||||
|
if(!arr.data.id) return n('ERR0028');
|
||||||
|
if(!arr.data.name) return n('ERR0026');
|
||||||
|
|
||||||
|
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 n('ERR8002');
|
||||||
|
res.api_res = {
|
||||||
|
record: []
|
||||||
|
}
|
||||||
|
n();
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.all('*', rt.send);
|
.all('*', rt.send);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user