diff --git a/server/app/controller/host.js b/server/app/controller/host.js index f5283bf..d836388 100644 --- a/server/app/controller/host.js +++ b/server/app/controller/host.js @@ -1,30 +1,30 @@ const { readHostList, writeHostList, readSSHRecord, writeSSHRecord } = require('../utils') async function getHostList({ res }) { - console.log('get - host - list') + // console.log('get-host-list') const data = await readHostList() res.success({ data }) } async function saveHost({ res, request }) { - let { body: { host: newHost, name, expired, expiredNotify, group, consoleUrl, remark } } = request - console.log(request) + let { body: { host: newHost, name, index, expired, expiredNotify, group, consoleUrl, remark } } = request + // console.log(request) if (!newHost || !name) return res.fail({ msg: 'missing params: name or host' }) let hostList = await readHostList() if (hostList?.some(({ host }) => host === newHost)) return res.fail({ msg: `主机${ newHost }已存在` }) if (!Array.isArray(hostList)) hostList = [] - hostList.push({ host: newHost, name, expired, expiredNotify, group, consoleUrl, remark }) + hostList.push({ host: newHost, name, index, expired, expiredNotify, group, consoleUrl, remark }) await writeHostList(hostList) res.success() } async function updateHost({ res, request }) { - let { body: { host: newHost, name: newName, oldHost, expired, expiredNotify, group, consoleUrl, remark } } = request + let { body: { host: newHost, name: newName, index, oldHost, expired, expiredNotify, group, consoleUrl, remark } } = request if (!newHost || !newName || !oldHost) return res.fail({ msg: '参数错误' }) let hostList = await readHostList() if (!hostList.some(({ host }) => host === oldHost)) return res.fail({ msg: `主机${ newHost }不存在` }) let targetIdx = hostList.findIndex(({ host }) => host === oldHost) - hostList.splice(targetIdx, 1, { name: newName, host: newHost, expired, expiredNotify, group, consoleUrl, remark }) + hostList.splice(targetIdx, 1, { name: newName, host: newHost, index, expired, expiredNotify, group, consoleUrl, remark }) writeHostList(hostList) res.success() } @@ -46,26 +46,27 @@ async function removeHost({ res, request }) { res.success({ data: `${ host }已移除, ${ flag ? '并移除ssh记录' : '' }` }) } -async function updateHostSort({ res, request }) { - let { body: { list } } = request - if (!list) return res.fail({ msg: '参数错误' }) - let hostList = await readHostList() - if (hostList.length !== list.length) return res.fail({ msg: '失败: host数量不匹配' }) - let sortResult = [] - for (let i = 0; i < list.length; i++) { - const curHost = list[i] - let temp = hostList.find(({ host }) => curHost.host === host) - if (!temp) return res.fail({ msg: `查找失败: ${ curHost.name }` }) - sortResult.push(temp) - } - writeHostList(sortResult) - res.success({ msg: 'success' }) -} +// 原手动排序接口-废弃 +// async function updateHostSort({ res, request }) { +// let { body: { list } } = request +// if (!list) return res.fail({ msg: '参数错误' }) +// let hostList = await readHostList() +// if (hostList.length !== list.length) return res.fail({ msg: '失败: host数量不匹配' }) +// let sortResult = [] +// for (let i = 0; i < list.length; i++) { +// const curHost = list[i] +// let temp = hostList.find(({ host }) => curHost.host === host) +// if (!temp) return res.fail({ msg: `查找失败: ${ curHost.name }` }) +// sortResult.push(temp) +// } +// writeHostList(sortResult) +// res.success({ msg: 'success' }) +// } module.exports = { getHostList, saveHost, updateHost, - removeHost, - updateHostSort + removeHost + // updateHostSort } diff --git a/server/app/router/routes.js b/server/app/router/routes.js index 52d2d49..d8d19d2 100644 --- a/server/app/router/routes.js +++ b/server/app/router/routes.js @@ -1,5 +1,5 @@ const { updateSSH, removeSSH, existSSH, getCommand } = require('../controller/ssh') -const { getHostList, saveHost, updateHost, removeHost, updateHostSort } = require('../controller/host') +const { getHostList, saveHost, updateHost, removeHost } = require('../controller/host') const { login, getpublicKey, updatePwd, getLoginRecord } = require('../controller/user') const { getSupportEmailList, getUserEmailList, updateUserEmailList, removeUserEmail, pushEmail, getNotifyList, updateNotifyList } = require('../controller/notify') const { getGroupList, addGroupList, updateGroupList, removeGroup } = require('../controller/group') @@ -46,12 +46,12 @@ const host = [ method: 'post', path: '/host-remove', controller: removeHost - }, - { - method: 'put', - path: '/host-sort', - controller: updateHostSort } + // { + // method: 'put', + // path: '/host-sort', + // controller: updateHostSort + // } ] const user = [ { diff --git a/web/index.html b/web/index.html index 0f4c10c..58e00dd 100644 --- a/web/index.html +++ b/web/index.html @@ -4,7 +4,7 @@