diff --git a/code/VideoAccess-VCMP/api/app/lib/controllers/camera/create.js b/code/VideoAccess-VCMP/api/app/lib/controllers/camera/create.js
index 5cee93c..bbaf1be 100644
--- a/code/VideoAccess-VCMP/api/app/lib/controllers/camera/create.js
+++ b/code/VideoAccess-VCMP/api/app/lib/controllers/camera/create.js
@@ -350,10 +350,11 @@ async function getCascadeSipList (ctx) {
const { models } = ctx.fs.dc
const sipListRes = await models.GbCamera.findAll({
- attributes: ['id', 'streamid'],
+ attributes: ['id', 'sipip'],
where: {
level: 0,
ipctype: '级联',
+ sipip: { $ne: null }
}
})
ctx.status = 200;
@@ -383,7 +384,9 @@ async function verifyCascadeCamera (ctx) {
async function createCascadeCamera (ctx) {
let errMsg = '添加级联摄像头信息失败'
+ const transaction = await ctx.fs.dc.orm.transaction();
try {
+ const { models } = ctx.fs.dc
const { userId, token } = ctx.fs.api
const { sip, externalDomain, cascadeType } = ctx.request.body
const { utils: { getGbCameraLevel3ByStreamId, verifyCascadeInfo } } = ctx.app.fs
@@ -396,7 +399,8 @@ async function createCascadeCamera (ctx) {
await models.Camera.findAll({
where: {
type: 'cascade',
- serialNo: { $in: allCameraIds }
+ serialNo: { $in: allCameraIds },
+ delete: false
}
}) : []
let addData = []
@@ -410,13 +414,19 @@ async function createCascadeCamera (ctx) {
}
const added = addedCmeraRes.some(ac => ac.streamid == c.streamid)
if (added) {
- updateData.push({
+ let data = {
...storageData,
id: added.id,
+ }
+ updateData.push(data)
+ await models.Camera.update(data, {
+ where: { id: added.id },
+ transaction
})
} else {
addData.push({
...storageData,
+ type: 'cascade',
serialNo: c.streamid,
createTime: moment().format(),
createUserId: userId,
@@ -424,8 +434,13 @@ async function createCascadeCamera (ctx) {
})
}
}
+ await models.Camera.bulkCreate(addData, {
+ transaction
+ })
+ await transaction.commit();
ctx.status = 204;
} catch (error) {
+ await transaction.rollback();
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
diff --git a/code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js b/code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js
index 631f72d..7a65903 100644
--- a/code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js
+++ b/code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js
@@ -5,7 +5,7 @@ const moment = require('moment')
async function getCameraProject (ctx, next) {
try {
const models = ctx.fs.dc.models;
- const { limit, page, orderBy, orderDirection, keyword, abilityId, type, venderId, nvrId } = ctx.query
+ const { limit, page, orderBy, orderDirection, keyword, abilityId, type, venderId, nvrId, externalDomain } = ctx.query
const { userId, token } = ctx.fs.api
let findOption = {
@@ -36,11 +36,14 @@ async function getCameraProject (ctx, next) {
findOption.offset = page * limit
}
if (keyword) {
- findOption.where.$or = [{
- name: { $like: `%${keyword}%` }
- }, {
- serialNo: { $like: `%${keyword}%` }
- }]
+ findOption.where.$or = [
+ {
+ name: { $like: `%${keyword}%` }
+ },
+ // {
+ // serialNo: { $like: `%${keyword}%` }
+ // }
+ ]
}
if (type) {
findOption.where.type = type
@@ -53,6 +56,9 @@ async function getCameraProject (ctx, next) {
abilityId: abilityId
}
}
+ if (externalDomain) {
+ findOption.where.externalDomain = externalDomain
+ }
findOption.include.push(abilityFind)
const cameraRes = await models.Camera.findAll(findOption)
@@ -80,12 +86,10 @@ async function getCameraProject (ctx, next) {
: []
for (let { dataValues: camera } of cameraRes) {
- const corBindCamera = axbindCameraRes.find(b => b.cameraId == camera.id)
- if (corBindCamera) {
- camera.station = corBindCamera.stations
- } else {
- camera.station = []
- }
+ const corBindCamera = axbindCameraRes.filter(b => b.cameraId == camera.id)
+ camera.station = corBindCamera.reduce((station, c) => {
+ return station.concat.apply(station, c.stations)
+ }, [])
const corUser = corUsers.find(u => u.id == camera.createUserId)
camera.createUser = {
diff --git a/code/VideoAccess-VCMP/api/app/lib/controllers/nvr/index.js b/code/VideoAccess-VCMP/api/app/lib/controllers/nvr/index.js
index 6456875..db1f525 100644
--- a/code/VideoAccess-VCMP/api/app/lib/controllers/nvr/index.js
+++ b/code/VideoAccess-VCMP/api/app/lib/controllers/nvr/index.js
@@ -132,7 +132,24 @@ async function get (ctx) {
findOption.where.venderId = venderId
}
if (state) {
+ const onLineMap = {
+ ON: ['ON', 'ONLINE'],
+ OFF: ['OFF'],
+ // UNKONW: [],
+ DISABLED: []
+ }
+
+ let unknowState = []
+ for (let k in onLineMap) {
+ unknowState = unknowState.concat(onLineMap[k])
+ }
+ gbNvrOption.where = {
+ online: state == 'UNKONW' ?
+ { $notIn: unknowState }
+ : { $in: onLineMap[state] }
+ }
+ gbNvrOption.required = true
}
findOption.include.push(gbNvrOption)
diff --git a/code/VideoAccess-VCMP/web/client/src/layout/actions/global.js b/code/VideoAccess-VCMP/web/client/src/layout/actions/global.js
index 0548a95..e9d0305 100644
--- a/code/VideoAccess-VCMP/web/client/src/layout/actions/global.js
+++ b/code/VideoAccess-VCMP/web/client/src/layout/actions/global.js
@@ -4,41 +4,42 @@ import { RouteTable } from '$utils'
export const INIT_LAYOUT = 'INIT_LAYOUT';
export function initLayout (title, copyright, sections, actions) {
- return {
- type: INIT_LAYOUT,
- payload: {
- title,
- copyright,
- sections,
- actions
- }
- };
+ return {
+ type: INIT_LAYOUT,
+ payload: {
+ title,
+ copyright,
+ sections,
+ actions
+ }
+ };
}
export const RESIZE = 'RESIZE';
export function resize (clientHeight, clientWidth) {
- const headerHeight = 60
- const footerHeight = 0
- return {
- type: RESIZE,
- payload: {
- clientHeight: clientHeight - headerHeight - footerHeight,
- clientWidth: clientWidth
- }
- }
+ const headerHeight = 60
+ const footerHeight = 0
+ return {
+ type: RESIZE,
+ payload: {
+ clientHeight: clientHeight - headerHeight - footerHeight,
+ clientWidth: clientWidth
+ }
+ }
}
export const INIT_API_ROOT = 'INIT_API_ROOT';
export function initApiRoot () {
- return dispatch => {
- RouteRequest.get(RouteTable.apiRoot).then(res => {
- localStorage.setItem('apiRoot', res.root);
- dispatch({
- type: INIT_API_ROOT,
- payload: {
- apiRoot: res.root
- }
- })
- });
- }
+ return dispatch => {
+ return RouteRequest.get(RouteTable.apiRoot).then(res => {
+ localStorage.setItem('apiRoot', JSON.stringify(res));
+ return dispatch({
+ type: INIT_API_ROOT,
+ payload: {
+ apiRoot: res.root,
+ iotAuthWeb: res.iotAuthWeb
+ }
+ })
+ });
+ }
}
\ No newline at end of file
diff --git a/code/VideoAccess-VCMP/web/client/src/layout/components/sider/index.jsx b/code/VideoAccess-VCMP/web/client/src/layout/components/sider/index.jsx
index 3424b40..41adbfd 100644
--- a/code/VideoAccess-VCMP/web/client/src/layout/components/sider/index.jsx
+++ b/code/VideoAccess-VCMP/web/client/src/layout/components/sider/index.jsx
@@ -6,7 +6,7 @@ import { push } from 'react-router-redux';
let scrollbar = null
const Sider = props => {
- const { collapsed, clientHeight, dispatch } = props
+ const { collapsed, clientHeight, dispatch, pathname } = props
const [items, setItems] = useState([])
const [selectedKeys, setSelectedKeys] = useState([])
const [openKeys, setOpenKeys] = useState([])
@@ -14,6 +14,27 @@ const Sider = props => {
useEffect(() => {
const { sections, dispatch, user } = props;
let nextItems = []
+ const initKeys = (items, lastKeys) => {
+ for (let it of items) {
+ if (it.to && it.to == pathname) {
+ lastKeys.selectedKeys.push(it.itemKey)
+ return lastKeys
+ } else if (it.items && it.items.length) {
+ const preLastKeys = JSON.parse(JSON.stringify(lastKeys))
+ preLastKeys.openKeys.push(it.itemKey)
+ const nextKeys = initKeys(it.items, JSON.parse(JSON.stringify(preLastKeys)))
+ if (nextKeys.selectedKeys.length > preLastKeys.selectedKeys.length || nextKeys.openKeys.length > preLastKeys.openKeys.length) {
+ return nextKeys
+ }
+ }
+ }
+ return lastKeys
+ return {
+ selectedKeys: [],
+ openKeys: []
+ }
+ }
+
for (let c of sections) {
if (typeof c.getNavItem == 'function') {
let item = c.getNavItem(user, dispatch);
@@ -24,13 +45,25 @@ const Sider = props => {
}
setItems(nextItems)
- const lastSelectedKeys = localStorage.getItem('vcmp_selected_sider')
- if (lastSelectedKeys) {
- setSelectedKeys(JSON.parse(lastSelectedKeys))
- }
- const lastOpenKeys = localStorage.getItem('vcmp_open_sider')
- if (lastOpenKeys) {
- setOpenKeys(JSON.parse(lastOpenKeys))
+ const { selectedKeys, openKeys } = initKeys(
+ nextItems,
+ {
+ selectedKeys: [],
+ openKeys: []
+ }
+ )
+ if (selectedKeys.length || openKeys.length) {
+ setSelectedKeys(selectedKeys)
+ setOpenKeys(openKeys)
+ } else {
+ const lastSelectedKeys = localStorage.getItem('vcmp_selected_sider')
+ if (lastSelectedKeys) {
+ setSelectedKeys(JSON.parse(lastSelectedKeys))
+ }
+ const lastOpenKeys = localStorage.getItem('vcmp_open_sider')
+ if (lastOpenKeys) {
+ setOpenKeys(JSON.parse(lastOpenKeys))
+ }
}
scrollbar = new PerfectScrollbar('#page-slider', { suppressScrollX: true });
diff --git a/code/VideoAccess-VCMP/web/client/src/layout/containers/layout/index.jsx b/code/VideoAccess-VCMP/web/client/src/layout/containers/layout/index.jsx
index 6d597fe..8f68235 100644
--- a/code/VideoAccess-VCMP/web/client/src/layout/containers/layout/index.jsx
+++ b/code/VideoAccess-VCMP/web/client/src/layout/containers/layout/index.jsx
@@ -90,9 +90,7 @@ const LayoutContainer = props => {
}}>
diff --git a/code/VideoAccess-VCMP/web/client/src/layout/index.jsx b/code/VideoAccess-VCMP/web/client/src/layout/index.jsx
index 8877810..9e34ef3 100644
--- a/code/VideoAccess-VCMP/web/client/src/layout/index.jsx
+++ b/code/VideoAccess-VCMP/web/client/src/layout/index.jsx
@@ -83,7 +83,7 @@ const Root = props => {
}
}
- useEffect(() => {
+ useEffect(async () => {
let innerRoutes = []
let outerRoutes = []
let reducers = {}
@@ -126,8 +126,8 @@ const Root = props => {
store.dispatch(resize(document.body.clientHeight, document.body.clientWidth));
store.dispatch(actions.auth.initAuth());
store.dispatch(initWebSocket({}))
- store.dispatch(initApiRoot())
-
+ const resourceRoot = await store.dispatch(initApiRoot())
+ console.log(resourceRoot);
const combineRoutes = flatRoutes(innerRoutes);
setInnerRoutes(combineRoutes)
@@ -163,12 +163,12 @@ const Root = props => {
setAuthCrossLoading(false)
});
- setAuthCrossLoading(false)
+ setAuthCrossLoading(false)
}, [])
return (
<>
- {
+ {
store ?
diff --git a/code/VideoAccess-VCMP/web/client/src/sections/auth/actions/auth.js b/code/VideoAccess-VCMP/web/client/src/sections/auth/actions/auth.js
index 6a37007..536a274 100644
--- a/code/VideoAccess-VCMP/web/client/src/sections/auth/actions/auth.js
+++ b/code/VideoAccess-VCMP/web/client/src/sections/auth/actions/auth.js
@@ -1,6 +1,6 @@
'use strict';
-import { ApiTable, AuthRequest } from '$utils'
+import { ApiTable, AxyRequest } from '$utils'
export const INIT_AUTH = 'INIT_AUTH';
export function initAuth (userData) {
@@ -42,7 +42,7 @@ export function login (username, password) {
// },
// });
- return AuthRequest.post(ApiTable.login, { username, password })
+ return AxyRequest.post(ApiTable.login, { username, password, domain: 'anxinyun' })
.then(user => {
sessionStorage.setItem('user', JSON.stringify(user));
return dispatch({
@@ -64,7 +64,7 @@ export function login (username, password) {
export const LOGOUT = 'LOGOUT';
export function logout () {
const user = JSON.parse(sessionStorage.getItem('user'))
- AuthRequest.put(ApiTable.logout, {
+ AxyRequest.put(ApiTable.logout, {
token: user.token
});
sessionStorage.removeItem('user');
diff --git a/code/VideoAccess-VCMP/web/client/src/sections/auth/containers/login.jsx b/code/VideoAccess-VCMP/web/client/src/sections/auth/containers/login.jsx
index f5c07b0..cd6e73e 100644
--- a/code/VideoAccess-VCMP/web/client/src/sections/auth/containers/login.jsx
+++ b/code/VideoAccess-VCMP/web/client/src/sections/auth/containers/login.jsx
@@ -48,9 +48,10 @@ const Login = props => {
width: 446,
height: 348,
padding: '45px 60px',
- backgroundImage: "url('/assets/images/background/loginbg.png')",
- backgroundSize: '100% 100%',
- backgroundRepeat: 'no-repeat',
+ // backgroundImage: "url('/assets/images/background/loginbg.png')",
+ // backgroundSize: '100% 100%',
+ // backgroundRepeat: 'no-repeat',
+ background: 'linear-gradient(rgba(255,255,255,1),rgba(255,255,255,.3))',
position: 'absolute',
top: '33.89%',
right: '16.43%',
diff --git a/code/VideoAccess-VCMP/web/client/src/utils/index.js b/code/VideoAccess-VCMP/web/client/src/utils/index.js
index d3348a4..bd4b243 100644
--- a/code/VideoAccess-VCMP/web/client/src/utils/index.js
+++ b/code/VideoAccess-VCMP/web/client/src/utils/index.js
@@ -1,7 +1,7 @@
'use strict';
import { isAuthorized } from './func';
import { AuthorizationCode } from './authCode';
-import { ApiTable, RouteTable, AuthRequest } from './webapi'
+import { ApiTable, RouteTable, AuthRequest, AxyRequest } from './webapi'
export {
isAuthorized,
@@ -11,4 +11,5 @@ export {
ApiTable,
RouteTable,
AuthRequest,
+ AxyRequest,
}
\ No newline at end of file
diff --git a/code/VideoAccess-VCMP/web/client/src/utils/webapi.js b/code/VideoAccess-VCMP/web/client/src/utils/webapi.js
index 0631522..066960d 100644
--- a/code/VideoAccess-VCMP/web/client/src/utils/webapi.js
+++ b/code/VideoAccess-VCMP/web/client/src/utils/webapi.js
@@ -2,38 +2,39 @@
import { ProxyRequest } from "@peace/utils";
export const AuthRequest = new ProxyRequest("_auth");
+export const AxyRequest = new ProxyRequest("_axy");
export const ApiTable = {
- login: "login",
- logout: "logout",
+ login: "login",
+ logout: "logout",
- getEnterprisesMembers: "enterprises/{enterpriseId}/members",
+ getEnterprisesMembers: "enterprises/{enterpriseId}/members",
- getNvr: "nvr",
- getVender: "vender",
- nvr: "nvr",
- delNvr: "nvr/{nvrId}",
- getNvrDetails: "nvr/detail/{nvrId}", //获取nvr详情
- getExport: "camera/export", //nvr表格数据导出
- getCheck:"nvr/verify", //校验nvr信息
+ getNvr: "nvr",
+ getVender: "vender",
+ nvr: "nvr",
+ delNvr: "nvr/{nvrId}",
+ getNvrDetails: "nvr/detail/{nvrId}", //获取nvr详情
+ getExport: "camera/export", //nvr表格数据导出
+ getCheck: "nvr/verify", //校验nvr信息
- getCamera: "camera/project", // 获取摄像头列表
- putForbidden: "camera/banned", //禁用摄像头
- delCamera:"camera/{cameraId}", //删除摄像头
- getCameraDetails: "camera/{cameraId}/detail", //获取摄像头详情
- getCameraKind: "camera/kind", //获取摄像头种类列表
- getAbility: "/camera/ability", //获取摄像头能力列表
- postCameraYingshi: "camera/create/yingshi", //创建萤石摄像头
- postCameraIpc: "camera/create/ipc", //创建IPC摄像头
- getVideoStreaming:"camera/nvr_stream", //获取NVR视频流
- postCameraNvr:"camera/create/nvr", //记录NVR摄像头
- getCascadeSIP:"camera/sip_list/cascade", //获取级联摄像头sip列表
- postAddCascade:"camera/create/cascade" , //添加级联摄像头
+ getCamera: "camera/project", // 获取摄像头列表
+ putForbidden: "camera/banned", //禁用摄像头
+ delCamera: "camera/{cameraId}", //删除摄像头
+ getCameraDetails: "camera/{cameraId}/detail", //获取摄像头详情
+ getCameraKind: "camera/kind", //获取摄像头种类列表
+ getAbility: "/camera/ability", //获取摄像头能力列表
+ postCameraYingshi: "camera/create/yingshi", //创建萤石摄像头
+ postCameraIpc: "camera/create/ipc", //创建IPC摄像头
+ getVideoStreaming: "camera/nvr_stream", //获取NVR视频流
+ postCameraNvr: "camera/create/nvr", //记录NVR摄像头
+ getCascadeSIP: "camera/sip_list/cascade", //获取级联摄像头sip列表
+ postAddCascade: "camera/create/cascade", //添加级联摄像头
};
export const RouteTable = {
- apiRoot: "/api/root",
- fileUpload: "/_upload/new",
- cleanUpUploadTrash: "/_upload/cleanup",
+ apiRoot: "/api/root",
+ fileUpload: "/_upload/new",
+ cleanUpUploadTrash: "/_upload/cleanup",
};
diff --git a/code/VideoAccess-VCMP/web/config.js b/code/VideoAccess-VCMP/web/config.js
index 2f9a214..45f66f7 100644
--- a/code/VideoAccess-VCMP/web/config.js
+++ b/code/VideoAccess-VCMP/web/config.js
@@ -13,87 +13,98 @@ dev && console.log('\x1B[33m%s\x1b[0m', '请遵循并及时更新 readme.md,
args.option(['p', 'port'], '启动端口');
args.option(['u', 'api-url'], 'webapi的URL');
args.option('apiAuthUrl', 'IOT 鉴权 api');
+args.option('apiAnxinyunUrl', '安心云 api');
+args.option('iotAuthWeb', 'IOT 鉴权 web');
const flags = args.parse(process.argv);
const API_URL = process.env.API_URL || flags.apiUrl;
const API_AUTH_URL = process.env.API_AUTH_URL || flags.apiAuthUrl;
+const IOT_AUTH_WEB = process.env.IOT_AUTH_WEB || flags.iotAuthWeb;
+const API_ANXINYUN_URL = process.env.API_ANXINYUN_URL || flags.apiAnxinyunUrl;
-if (!API_URL) {
- console.log('缺少启动参数,异常退出');
- args.showHelp();
- process.exit(-1);
+if (!API_URL || !API_ANXINYUN_URL || !API_AUTH_URL) {
+ console.log('缺少启动参数,异常退出');
+ args.showHelp();
+ process.exit(-1);
}
const product = {
- port: flags.port || 8080,
- staticDirs: [path.join(__dirname, './client')],
- mws: [{
- entry: require('./middlewares/proxy').entry,
- opts: {
- host: API_URL,
- match: /^\/_api\//,
- }
- }, {
- entry: require('./middlewares/proxy').entry,
- opts: {
- host: API_AUTH_URL,
- match: /^\/_auth\//,
- }
- }, {
- entry: require('./routes').entry,
- opts: {
- apiUrl: API_URL,
- staticRoot: './client',
- }
- }, {
- entry: require('./client').entry,// 静态信息
- opts: {}
- }],
- logger: {
- level: 'debug',
- json: false,
- filename: path.join(__dirname, 'log', 'runtime.txt'),
- colorize: true,
- maxsize: 1024 * 1024 * 5,
- rotationFormat: false,
- zippedArchive: true,
- maxFiles: 10,
- prettyPrint: true,
- label: '',
- timestamp: () => moment().format('YYYY-MM-DD HH:mm:ss.SSS'),
- eol: os.EOL,
- tailable: true,
- depth: null,
- showLevel: true,
- maxRetries: 1
- }
+ port: flags.port || 8080,
+ staticDirs: [path.join(__dirname, './client')],
+ mws: [{
+ entry: require('./middlewares/proxy').entry,
+ opts: {
+ host: API_URL,
+ match: /^\/_api\//,
+ }
+ }, {
+ entry: require('./middlewares/proxy').entry,
+ opts: {
+ host: API_AUTH_URL,
+ match: /^\/_auth\//,
+ }
+ }, {
+ entry: require('./middlewares/proxy').entry,
+ opts: {
+ host: API_ANXINYUN_URL,
+ match: /^\/_axy\//,
+ }
+ }, {
+ entry: require('./routes').entry,
+ opts: {
+ apiUrl: API_URL,
+ iotAuthWeb: IOT_AUTH_WEB,
+ staticRoot: './client',
+ }
+ }, {
+ entry: require('./client').entry,// 静态信息
+ opts: {}
+ }],
+ logger: {
+ level: 'debug',
+ json: false,
+ filename: path.join(__dirname, 'log', 'runtime.txt'),
+ colorize: true,
+ maxsize: 1024 * 1024 * 5,
+ rotationFormat: false,
+ zippedArchive: true,
+ maxFiles: 10,
+ prettyPrint: true,
+ label: '',
+ timestamp: () => moment().format('YYYY-MM-DD HH:mm:ss.SSS'),
+ eol: os.EOL,
+ tailable: true,
+ depth: null,
+ showLevel: true,
+ maxRetries: 1
+ }
};
let config;
if (dev) {
- config = {
- port: product.port,
- staticDirs: product.staticDirs,
- mws: product.mws
- .concat([
- vite ?
- {
- entry: require('./middlewares/vite-dev').entry,
- opts: {}
- }
- :
- {
- entry: require('./middlewares/webpack-dev').entry,
- opts: {}
- }
- ])
- ,
- logger: product.logger
- }
- config.logger.filename = path.join(__dirname, 'log', 'development.txt');
+ config = {
+ port: product.port,
+ staticDirs: product.staticDirs,
+ mws: product.mws
+ .concat([
+ vite ?
+ {
+ entry: require('./middlewares/vite-dev').entry,
+ opts: {}
+ }
+ :
+ {
+ entry: require('./middlewares/webpack-dev').entry,
+ opts: {}
+ }
+ ])
+ ,
+ logger: product.logger
+ }
+ config.logger.filename = path.join(__dirname, 'log', 'development.txt');
} else {
- config = product;
+ config = product;
}
module.exports = config;//区分开发和发布
\ No newline at end of file
diff --git a/code/VideoAccess-VCMP/web/package.json b/code/VideoAccess-VCMP/web/package.json
index c711259..edd6de2 100644
--- a/code/VideoAccess-VCMP/web/package.json
+++ b/code/VideoAccess-VCMP/web/package.json
@@ -7,7 +7,7 @@
"test": "mocha",
"start-vite": "cross-env NODE_ENV=developmentVite npm run start-params",
"start": "cross-env NODE_ENV=development npm run start-params",
- "start-params": "node server -p 5000 -u http://10.8.30.7:4000 --apiAuthUrl http://10.8.30.7:4200",
+ "start-params": "node server -p 5000 -u http://10.8.30.7:4000 --apiAuthUrl http://10.8.30.7:4200 --apiAnxinyunUrl http://10.8.30.7:4100 --iotAuthWeb http://10.8.30.7:5200",
"deploy": "export NODE_ENV=production&& npm run build && node server",
"build-dev": "cross-env NODE_ENV=development&&webpack --config webpack.config.js",
"build": "export NODE_ENV=production&&webpack --config webpack.config.prod.js"
diff --git a/code/VideoAccess-VCMP/web/routes/attachment/index.js b/code/VideoAccess-VCMP/web/routes/attachment/index.js
index 65061e0..03f159f 100644
--- a/code/VideoAccess-VCMP/web/routes/attachment/index.js
+++ b/code/VideoAccess-VCMP/web/routes/attachment/index.js
@@ -5,88 +5,91 @@ const path = require('path')
const fs = require('fs');
const ext = {
- project: [".txt", ".dwg", ".doc", ".docx", ".xls", ".xlsx", ".pdf", ".png", ".jpg", ".svg"],
- report: [".doc", ".docx", ".xls", ".xlsx", ".pdf"],
- data: [".txt", ".xls", ".xlsx"],
- image: [".png", ".jpg", ".svg"],
- three: [".js"],
- video: [".mp4"],
- bpmn: [".bpmn", ".bpmn20.xml", ".zip", ".bar"],
- app: [".apk"]
+ project: [".txt", ".dwg", ".doc", ".docx", ".xls", ".xlsx", ".pdf", ".png", ".jpg", ".svg"],
+ report: [".doc", ".docx", ".xls", ".xlsx", ".pdf"],
+ data: [".txt", ".xls", ".xlsx"],
+ image: [".png", ".jpg", ".svg"],
+ three: [".js"],
+ video: [".mp4"],
+ bpmn: [".bpmn", ".bpmn20.xml", ".zip", ".bar"],
+ app: [".apk"]
}
module.exports = {
- entry: function (app, router, opts) {
+ entry: function (app, router, opts) {
- const getApiRoot = async function (ctx) {
- const { apiUrl } = opts;
+ const getApiRoot = async function (ctx) {
+ const { apiUrl, iotAuthWeb } = opts;
- ctx.status = 200;
- ctx.body = { root: apiUrl };
- };
-
- let upload = async function (ctx, next) {
- try {
- const { files } = await parse(ctx.req);
- const file = files[0];
- const extname = path.extname(file.filename).toLowerCase();
- const fileType = ctx.query.type || "image";
- const fileFolder = ctx.query.fileFolder || 'common';
- if (ext[fileType].indexOf(extname) < 0) {
- ctx.status = 400;
- ctx.body = JSON.stringify({ name: 'UploadFailed', message: '文件格式无效' });
- return;
- }
- const date = new Date().toLocaleDateString();
- const time = new Date().getTime();
- let fileName = time + '_' + file.filename;
- let saveFile = path.join(__dirname, '../../', `/client/assets/files/${fileFolder}`, fileName);
- const pathUrl = `./client/assets/files/${fileFolder}`;
+ ctx.status = 200;
+ ctx.body = {
+ root: apiUrl,
+ iotAuthWeb
+ };
+ };
- const res1 = fs.existsSync(`./client/assets/files/${fileFolder}`);
- !res1 && fs.mkdirSync(`./client/assets/files/${fileFolder}`);
- const res = fs.existsSync(pathUrl);
- !res && fs.mkdirSync(pathUrl);
- let stream = fs.createWriteStream(saveFile);
- fs.createReadStream(file.path).pipe(stream);
- stream.on('error', function (err) {
- app.fs.logger.log('error', '[Upload Heatmap]', err);
- });
- ctx.status = 200;
- ctx.body = { filename: path.join(`/assets/files/${fileFolder}`, fileName), name: 'UploadSuccess', message: '上传成功' };
- } catch (err) {
- ctx.status = 500;
- ctx.fs.logger.error(err);
- ctx.body = { err: 'upload error.' };
+ let upload = async function (ctx, next) {
+ try {
+ const { files } = await parse(ctx.req);
+ const file = files[0];
+ const extname = path.extname(file.filename).toLowerCase();
+ const fileType = ctx.query.type || "image";
+ const fileFolder = ctx.query.fileFolder || 'common';
+ if (ext[fileType].indexOf(extname) < 0) {
+ ctx.status = 400;
+ ctx.body = JSON.stringify({ name: 'UploadFailed', message: '文件格式无效' });
+ return;
}
- }
+ const date = new Date().toLocaleDateString();
+ const time = new Date().getTime();
+ let fileName = time + '_' + file.filename;
+ let saveFile = path.join(__dirname, '../../', `/client/assets/files/${fileFolder}`, fileName);
+ const pathUrl = `./client/assets/files/${fileFolder}`;
- let remove = async function (ctx, next) {
- try {
- const fkeys = ctx.request.body;
- let removeUrl = path.join(__dirname, '../../', './client', fkeys.url);
- const res = fs.existsSync(removeUrl);
- if (!res) {
- ctx.status = 400;
- ctx.body = JSON.stringify({ name: 'DeleteFailed', message: '文件地址不存在' });
- return;
- }
- fs.unlink(removeUrl, function (error) {
- if (error) {
- console.log(error);
- }
- })
- ctx.status = 200;
- ctx.body = { name: 'DeleteSuccess.', message: '删除成功' };
- } catch (err) {
- ctx.status = 500;
- ctx.fs.logger.error(err);
- ctx.body = { err: 'upload cleanup error.' };
+ const res1 = fs.existsSync(`./client/assets/files/${fileFolder}`);
+ !res1 && fs.mkdirSync(`./client/assets/files/${fileFolder}`);
+ const res = fs.existsSync(pathUrl);
+ !res && fs.mkdirSync(pathUrl);
+ let stream = fs.createWriteStream(saveFile);
+ fs.createReadStream(file.path).pipe(stream);
+ stream.on('error', function (err) {
+ app.fs.logger.log('error', '[Upload Heatmap]', err);
+ });
+ ctx.status = 200;
+ ctx.body = { filename: path.join(`/assets/files/${fileFolder}`, fileName), name: 'UploadSuccess', message: '上传成功' };
+ } catch (err) {
+ ctx.status = 500;
+ ctx.fs.logger.error(err);
+ ctx.body = { err: 'upload error.' };
+ }
+ }
+
+ let remove = async function (ctx, next) {
+ try {
+ const fkeys = ctx.request.body;
+ let removeUrl = path.join(__dirname, '../../', './client', fkeys.url);
+ const res = fs.existsSync(removeUrl);
+ if (!res) {
+ ctx.status = 400;
+ ctx.body = JSON.stringify({ name: 'DeleteFailed', message: '文件地址不存在' });
+ return;
}
- }
+ fs.unlink(removeUrl, function (error) {
+ if (error) {
+ console.log(error);
+ }
+ })
+ ctx.status = 200;
+ ctx.body = { name: 'DeleteSuccess.', message: '删除成功' };
+ } catch (err) {
+ ctx.status = 500;
+ ctx.fs.logger.error(err);
+ ctx.body = { err: 'upload cleanup error.' };
+ }
+ }
- router.get('/api/root', getApiRoot);
- router.post('/_upload/new', upload);
- router.delete('/_upload/cleanup', remove);
- }
+ router.get('/api/root', getApiRoot);
+ router.post('/_upload/new', upload);
+ router.delete('/_upload/cleanup', remove);
+ }
};