diff --git a/code/VideoAccess-VCMP/api/app/lib/controllers/mirror/index.js b/code/VideoAccess-VCMP/api/app/lib/controllers/mirror/index.js index d722713..4fa9221 100644 --- a/code/VideoAccess-VCMP/api/app/lib/controllers/mirror/index.js +++ b/code/VideoAccess-VCMP/api/app/lib/controllers/mirror/index.js @@ -62,7 +62,7 @@ async function edit (ctx) { title: data.title, showHeader: Boolean(data.showHeader), publish: false, - mid: timeNow.format(`ssmmHHDDMMYYYY`) + mid: timeNow.format(`ssmmHHDDMMYY${Math.floor(Math.random() * 89 + 10)}`) } if (data.publish) { createData.publish = true @@ -161,6 +161,31 @@ async function edit (ctx) { } } +async function refreshId (ctx) { + try { + const { models } = ctx.fs.dc; + const { mirrorId } = ctx.params + + if (!mirrorId) throw '更新镜像服务ID失败'; + + await models.MirrorTree.update({ + mid: timeNow.format(`ssmmHHDDMMYY${Math.floor(Math.random() * 89 + 10)}`) + }, { + where: { + id: mirrorId + } + }) + + ctx.status = 204; + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: error`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } +} + async function list (ctx) { try { const { models } = ctx.fs.dc; @@ -447,7 +472,7 @@ async function copy (ctx) { title: mirrorRes.title + '-副本', showHeader: mirrorRes.showHeader, publish: mirrorRes.publish, - mid: timeNow.format(`ssmmHHDDMMYYYY`) + mid: timeNow.format(`ssmmHHDDMMYY${Math.floor(Math.random() * 89 + 10)}`) }, { transaction }) @@ -543,6 +568,7 @@ async function copy (ctx) { module.exports = { edit, + refreshId, list, get, del, diff --git a/code/VideoAccess-VCMP/api/app/lib/routes/mirror/index.js b/code/VideoAccess-VCMP/api/app/lib/routes/mirror/index.js index 4beb467..efe1995 100644 --- a/code/VideoAccess-VCMP/api/app/lib/routes/mirror/index.js +++ b/code/VideoAccess-VCMP/api/app/lib/routes/mirror/index.js @@ -6,6 +6,9 @@ module.exports = function (app, router, opts) { app.fs.api.logAttr['PUT/mirror'] = { content: '编辑镜像信息', visible: false }; router.put('/mirror', mirror.edit); + app.fs.api.logAttr['PUT/mirror/:mirrorId/id'] = { content: '更新镜像服务ID', visible: false }; + router.put('/mirror/:mirrorId/id', mirror.refreshId); + app.fs.api.logAttr['GET/mirror/list'] = { content: '获取镜像信息列表', visible: false }; router.get('/mirror/list', mirror.list);