重新调整websocket的配置

This commit is contained in:
2023-02-16 10:34:05 +08:00
parent 1bc5e3b9c4
commit 518efac58a
2 changed files with 45 additions and 44 deletions

View File

@@ -41,16 +41,11 @@ const handleZip = (id, ws) => {
const {signal} = controller;
const progress = new counter(`正在处理 ${info.name} 的打包工作...`)
const buildPath = {
web: 'base-web',
wxwork: 'base-wxcp',
mp: 'dvcp_v2_wxmp'
web: 'base-web', wxwork: 'base-wxcp', mp: 'dvcp_v2_wxmp'
}[info.type] || {}
let path = `../${buildPath}`, {dist} = info
dist = dist || `../zips/${info.name}v${info.version || "1.0.0"}`
Promise.all([
db.query(`update node_custom_config set download=null,error=null,zipTime='${dayjs().format("YYYY-MM-DD HH:mm:ss")}' where ${uniCon}`),
execute(`./shell/update.sh ${info.name} ${path}`, signal)
])
Promise.all([db.query(`update node_custom_config set download=null,error=null,zipTime='${dayjs().format("YYYY-MM-DD HH:mm:ss")}' where ${uniCon}`), execute(`./shell/update.sh ${info.name} ${path}`, signal)])
.then(cmd => progress.set(30, cmd))
.then(() => execute(`cd ${path}&&npm run apps&&node bin/pages.js ${id}&&npm run build`, signal))
.then(cmd => progress.set(70, cmd))
@@ -76,20 +71,13 @@ const handleZip = (id, ws) => {
}
module.exports = {
action: "/custom/getZip",
execute: (ws, request) => {
const {id} = request.query
handleZip(id, ws)
ws.onmessage = res => {
if (res?.data) {
const data = JSON.parse(res.data)
if (data.cid == id) {
action: "/custom/getZip", execute: (ws, request) => {
const {id, cid} = request.params
if (cid) {
controller.abort()
controller = new AbortController()
} else if (id == data.id) {
} else if (id) {
handleZip(id, ws)
}
}
}
},
}

View File

@@ -1,14 +1,27 @@
const {findFile} = require("../utils/fsUtils");
const chalk = require("chalk");
const dayjs = require("dayjs");
const {log} = console
module.exports = {
init: ins => {
ins.ws('/ws', ws => {
log(`${chalk.bgBlue.black(" WEBSOCKET ")} 服务已启动!`)
ins.send('您已成功连接到node websocket')
let heartBeat = setInterval(() => wx.send(`heartBeat at ${dayjs().format("YYYY-MM-DD HH:mm:ss")}`), 5000)
ws.on('close', () => {
log(`${chalk.bgBlue.black(" WEBSOCKET ")} 连接已断开!`)
clearInterval(heartBeat)
})
let actions = {}
return findFile('./src/websocket', file => {
if (!/index\.js/.test(file)) {
const ws = require(file.replace(/src[\\\/]websocket/, '.'))
log(`${chalk.bgBlue.black(" WEBSOCKET ")} ${ws.action}`)
ins.ws(ws.action, ws.execute)
actions[ws.action] = ws.execute
}
}).then(() => ws.on('message', res => {
if (res?.action) {
actions[res.action]?.(ws, JSON.parse(res))
}
}))
})
}
}