Browse Source

摄像头获取接口

pull/3/head
yuan_yi 3 years ago
parent
commit
9dc3554c7d
  1. 45
      code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js
  2. 9
      code/VideoAccess-VCMP/api/app/lib/models/camera.js
  3. 8
      code/VideoAccess-VCMP/api/app/lib/routes/camera/index.js
  4. 6
      code/VideoAccess-VCMP/web/webpack.config.js

45
code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js

@ -0,0 +1,45 @@
'use strict';
async function get (ctx, next) {
try {
const models = ctx.fs.dc.models;
const { limit, page, orderBy, orderDirection } = ctx.query
const { userId } = ctx.fs.api
let findOption = {
attributes: { exclude: ['delete', 'recycleTime',] },
where: {
createUserId: userId,
recycleTime: null,
delete: false
},
order: [
[orderBy || 'id', orderDirection || 'DESC']
],
include: [{
model: models.CameraAbility
}, {
model: models.CameraKind
}]
}
if (limit) {
findOption.limit = limit
}
if (page && limit) {
findOption.offset = page * limit
}
const cameraRes = await models.Camera.findAll(findOption)
ctx.status = 200;
ctx.body = cameraRes
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {}
}
}
module.exports = {
get,
};

9
code/VideoAccess-VCMP/api/app/lib/models/camera.js

@ -253,5 +253,14 @@ module.exports = dc => {
indexes: []
});
dc.models.Camera = Camera;
const CameraKind = dc.models.CameraKind;
Camera.belongsTo(CameraKind, { foreignKey: 'kindId', targetKey: 'id' });
CameraKind.hasMany(Camera, { foreignKey: 'kindId', sourceKey: 'id' });
const CameraAbility = dc.models.CameraAbility;
Camera.belongsTo(CameraAbility, { foreignKey: 'abilityId', targetKey: 'id' });
CameraAbility.hasMany(Camera, { foreignKey: 'abilityId', sourceKey: 'id' });
return Camera;
};

8
code/VideoAccess-VCMP/api/app/lib/routes/camera/index.js

@ -0,0 +1,8 @@
'use strict';
const camera = require('../../controllers/camera');
module.exports = function (app, router, opts) {
app.fs.api.logAttr['GET/camera'] = { content: '获取摄像头列表', visible: false };
router.get('/camera', camera.get);
};

6
code/VideoAccess-VCMP/web/webpack.config.js

@ -59,9 +59,11 @@ module.exports = {
test: /\.(js|jsx)$/,
use: 'babel-loader',
include: [PATHS.app, path.resolve(__dirname, 'node_modules', '@peace')],
}, {
},
{
test: /\.(eot|woff|woff2|svg|ttf)([\?]?.*)$/,
loader: "file-loader"
}]
}
]
}
};
Loading…
Cancel
Save