Commit dc682150 authored by 王曜嵚 Wang Yaoqin's avatar 王曜嵚 Wang Yaoqin

dev: websocket

parent 5b640397
...@@ -2,5 +2,10 @@ ...@@ -2,5 +2,10 @@
export default defineNuxtConfig({ export default defineNuxtConfig({
devtools: { enabled: true }, devtools: { enabled: true },
modules: ['@pinia/nuxt'], modules: ['@pinia/nuxt'],
css: ['~/assets/css/main.css', '~/assets/css/color.css'] css: ['~/assets/css/main.css', '~/assets/css/color.css'],
nitro: {
experimental: {
websocket: true
}
}
}) })
...@@ -9,10 +9,13 @@ ...@@ -9,10 +9,13 @@
"dependencies": { "dependencies": {
"@pinia/nuxt": "^0.5.1", "@pinia/nuxt": "^0.5.1",
"dockerode": "^3.3.5", "dockerode": "^3.3.5",
"engine.io": "^6.5.4",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"nuxt": "^3.11.1", "nuxt": "^3.11.1",
"pg": "^8.11.5", "pg": "^8.11.5",
"pinia": "^2.1.7", "pinia": "^2.1.7",
"socket.io": "^4.7.5",
"socket.io-client": "^4.7.5",
"tar-fs": "^3.0.5", "tar-fs": "^3.0.5",
"telnet-client": "^2.2.0", "telnet-client": "^2.2.0",
"vue": "^3.4.21", "vue": "^3.4.21",
...@@ -2474,6 +2477,11 @@ ...@@ -2474,6 +2477,11 @@
"node": ">=18" "node": ">=18"
} }
}, },
"node_modules/@socket.io/component-emitter": {
"version": "3.1.0",
"resolved": "https://registry.npmmirror.com/@socket.io/component-emitter/-/component-emitter-3.1.0.tgz",
"integrity": "sha512-+9jVqKhRSpsc591z5vX+X5Yyw+he/HCB4iQ/RYxw35CEPaY1gnsNE43nf9n9AaYjAQrTiI/mOwKUKdUs9vf7Xg=="
},
"node_modules/@trysound/sax": { "node_modules/@trysound/sax": {
"version": "0.2.0", "version": "0.2.0",
"resolved": "https://registry.npmmirror.com/@trysound/sax/-/sax-0.2.0.tgz", "resolved": "https://registry.npmmirror.com/@trysound/sax/-/sax-0.2.0.tgz",
...@@ -2513,6 +2521,19 @@ ...@@ -2513,6 +2521,19 @@
"node": ">=16 || 14 >=14.17" "node": ">=16 || 14 >=14.17"
} }
}, },
"node_modules/@types/cookie": {
"version": "0.4.1",
"resolved": "https://registry.npmmirror.com/@types/cookie/-/cookie-0.4.1.tgz",
"integrity": "sha512-XW/Aa8APYr6jSVVA1y/DEIZX0/GMKLEVekNG727R8cs56ahETkRAy/3DR7+fJyh7oUgGwNQaRfXCun0+KbWY7Q=="
},
"node_modules/@types/cors": {
"version": "2.8.17",
"resolved": "https://registry.npmmirror.com/@types/cors/-/cors-2.8.17.tgz",
"integrity": "sha512-8CGDvrBj1zgo2qE+oS3pOCyYNqCPryMWY2bGfwA0dcfopWGgxs+78df0Rs3rc9THP4JkOhLsAa+15VdpAqkcUA==",
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@types/docker-modem": { "node_modules/@types/docker-modem": {
"version": "3.0.6", "version": "3.0.6",
"resolved": "https://registry.npmmirror.com/@types/docker-modem/-/docker-modem-3.0.6.tgz", "resolved": "https://registry.npmmirror.com/@types/docker-modem/-/docker-modem-3.0.6.tgz",
...@@ -3609,6 +3630,18 @@ ...@@ -3609,6 +3630,18 @@
"node": ">=6.5" "node": ">=6.5"
} }
}, },
"node_modules/accepts": {
"version": "1.3.8",
"resolved": "https://registry.npmmirror.com/accepts/-/accepts-1.3.8.tgz",
"integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==",
"dependencies": {
"mime-types": "~2.1.34",
"negotiator": "0.6.3"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/acorn": { "node_modules/acorn": {
"version": "8.11.3", "version": "8.11.3",
"resolved": "https://registry.npmmirror.com/acorn/-/acorn-8.11.3.tgz", "resolved": "https://registry.npmmirror.com/acorn/-/acorn-8.11.3.tgz",
...@@ -3939,6 +3972,14 @@ ...@@ -3939,6 +3972,14 @@
"resolved": "https://registry.npmmirror.com/base64-js/-/base64-js-1.5.1.tgz", "resolved": "https://registry.npmmirror.com/base64-js/-/base64-js-1.5.1.tgz",
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==" "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA=="
}, },
"node_modules/base64id": {
"version": "2.0.0",
"resolved": "https://registry.npmmirror.com/base64id/-/base64id-2.0.0.tgz",
"integrity": "sha512-lGe34o6EHj9y3Kts9R4ZYs/Gr+6N7MCaMlIFA3F1R2O5/m7K06AxfSeO5530PEERE6/WyEg3lsuyw4GHlPZHog==",
"engines": {
"node": "^4.5.0 || >= 5.9"
}
},
"node_modules/bcrypt-pbkdf": { "node_modules/bcrypt-pbkdf": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmmirror.com/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz", "resolved": "https://registry.npmmirror.com/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz",
...@@ -4463,6 +4504,14 @@ ...@@ -4463,6 +4504,14 @@
"resolved": "https://registry.npmmirror.com/convert-source-map/-/convert-source-map-2.0.0.tgz", "resolved": "https://registry.npmmirror.com/convert-source-map/-/convert-source-map-2.0.0.tgz",
"integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==" "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg=="
}, },
"node_modules/cookie": {
"version": "0.4.2",
"resolved": "https://registry.npmmirror.com/cookie/-/cookie-0.4.2.tgz",
"integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/cookie-es": { "node_modules/cookie-es": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmmirror.com/cookie-es/-/cookie-es-1.1.0.tgz", "resolved": "https://registry.npmmirror.com/cookie-es/-/cookie-es-1.1.0.tgz",
...@@ -4473,6 +4522,18 @@ ...@@ -4473,6 +4522,18 @@
"resolved": "https://registry.npmmirror.com/core-util-is/-/core-util-is-1.0.3.tgz", "resolved": "https://registry.npmmirror.com/core-util-is/-/core-util-is-1.0.3.tgz",
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==" "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
}, },
"node_modules/cors": {
"version": "2.8.5",
"resolved": "https://registry.npmmirror.com/cors/-/cors-2.8.5.tgz",
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
"dependencies": {
"object-assign": "^4",
"vary": "^1"
},
"engines": {
"node": ">= 0.10"
}
},
"node_modules/cpu-features": { "node_modules/cpu-features": {
"version": "0.0.9", "version": "0.0.9",
"resolved": "https://registry.npmmirror.com/cpu-features/-/cpu-features-0.0.9.tgz", "resolved": "https://registry.npmmirror.com/cpu-features/-/cpu-features-0.0.9.tgz",
...@@ -5057,6 +5118,86 @@ ...@@ -5057,6 +5118,86 @@
"once": "^1.4.0" "once": "^1.4.0"
} }
}, },
"node_modules/engine.io": {
"version": "6.5.4",
"resolved": "https://registry.npmmirror.com/engine.io/-/engine.io-6.5.4.tgz",
"integrity": "sha512-KdVSDKhVKyOi+r5uEabrDLZw2qXStVvCsEB/LN3mw4WFi6Gx50jTyuxYVCwAAC0U46FdnzP/ScKRBTXb/NiEOg==",
"dependencies": {
"@types/cookie": "^0.4.1",
"@types/cors": "^2.8.12",
"@types/node": ">=10.0.0",
"accepts": "~1.3.4",
"base64id": "2.0.0",
"cookie": "~0.4.1",
"cors": "~2.8.5",
"debug": "~4.3.1",
"engine.io-parser": "~5.2.1",
"ws": "~8.11.0"
},
"engines": {
"node": ">=10.2.0"
}
},
"node_modules/engine.io-client": {
"version": "6.5.3",
"resolved": "https://registry.npmmirror.com/engine.io-client/-/engine.io-client-6.5.3.tgz",
"integrity": "sha512-9Z0qLB0NIisTRt1DZ/8U2k12RJn8yls/nXMZLn+/N8hANT3TcYjKFKcwbw5zFQiN4NTde3TSY9zb79e1ij6j9Q==",
"dependencies": {
"@socket.io/component-emitter": "~3.1.0",
"debug": "~4.3.1",
"engine.io-parser": "~5.2.1",
"ws": "~8.11.0",
"xmlhttprequest-ssl": "~2.0.0"
}
},
"node_modules/engine.io-client/node_modules/ws": {
"version": "8.11.0",
"resolved": "https://registry.npmmirror.com/ws/-/ws-8.11.0.tgz",
"integrity": "sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==",
"engines": {
"node": ">=10.0.0"
},
"peerDependencies": {
"bufferutil": "^4.0.1",
"utf-8-validate": "^5.0.2"
},
"peerDependenciesMeta": {
"bufferutil": {
"optional": true
},
"utf-8-validate": {
"optional": true
}
}
},
"node_modules/engine.io-parser": {
"version": "5.2.2",
"resolved": "https://registry.npmmirror.com/engine.io-parser/-/engine.io-parser-5.2.2.tgz",
"integrity": "sha512-RcyUFKA93/CXH20l4SoVvzZfrSDMOTUS3bWVpTt2FuFP+XYrL8i8oonHP7WInRyVHXh0n/ORtoeiE1os+8qkSw==",
"engines": {
"node": ">=10.0.0"
}
},
"node_modules/engine.io/node_modules/ws": {
"version": "8.11.0",
"resolved": "https://registry.npmmirror.com/ws/-/ws-8.11.0.tgz",
"integrity": "sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==",
"engines": {
"node": ">=10.0.0"
},
"peerDependencies": {
"bufferutil": "^4.0.1",
"utf-8-validate": "^5.0.2"
},
"peerDependenciesMeta": {
"bufferutil": {
"optional": true
},
"utf-8-validate": {
"optional": true
}
}
},
"node_modules/enhanced-resolve": { "node_modules/enhanced-resolve": {
"version": "5.16.0", "version": "5.16.0",
"resolved": "https://registry.npmmirror.com/enhanced-resolve/-/enhanced-resolve-5.16.0.tgz", "resolved": "https://registry.npmmirror.com/enhanced-resolve/-/enhanced-resolve-5.16.0.tgz",
...@@ -6415,6 +6556,25 @@ ...@@ -6415,6 +6556,25 @@
"node": ">=16" "node": ">=16"
} }
}, },
"node_modules/mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmmirror.com/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime-types": {
"version": "2.1.35",
"resolved": "https://registry.npmmirror.com/mime-types/-/mime-types-2.1.35.tgz",
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
"dependencies": {
"mime-db": "1.52.0"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mimic-fn": { "node_modules/mimic-fn": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmmirror.com/mimic-fn/-/mimic-fn-4.0.0.tgz", "resolved": "https://registry.npmmirror.com/mimic-fn/-/mimic-fn-4.0.0.tgz",
...@@ -8799,6 +8959,78 @@ ...@@ -8799,6 +8959,78 @@
"resolved": "https://registry.npmmirror.com/smob/-/smob-1.5.0.tgz", "resolved": "https://registry.npmmirror.com/smob/-/smob-1.5.0.tgz",
"integrity": "sha512-g6T+p7QO8npa+/hNx9ohv1E5pVCmWrVCUzUXJyLdMmftX6ER0oiWY/w9knEonLpnOp6b6FenKnMfR8gqwWdwig==" "integrity": "sha512-g6T+p7QO8npa+/hNx9ohv1E5pVCmWrVCUzUXJyLdMmftX6ER0oiWY/w9knEonLpnOp6b6FenKnMfR8gqwWdwig=="
}, },
"node_modules/socket.io": {
"version": "4.7.5",
"resolved": "https://registry.npmmirror.com/socket.io/-/socket.io-4.7.5.tgz",
"integrity": "sha512-DmeAkF6cwM9jSfmp6Dr/5/mfMwb5Z5qRrSXLpo3Fq5SqyU8CMF15jIN4ZhfSwu35ksM1qmHZDQ/DK5XTccSTvA==",
"dependencies": {
"accepts": "~1.3.4",
"base64id": "~2.0.0",
"cors": "~2.8.5",
"debug": "~4.3.2",
"engine.io": "~6.5.2",
"socket.io-adapter": "~2.5.2",
"socket.io-parser": "~4.2.4"
},
"engines": {
"node": ">=10.2.0"
}
},
"node_modules/socket.io-adapter": {
"version": "2.5.4",
"resolved": "https://registry.npmmirror.com/socket.io-adapter/-/socket.io-adapter-2.5.4.tgz",
"integrity": "sha512-wDNHGXGewWAjQPt3pyeYBtpWSq9cLE5UW1ZUPL/2eGK9jtse/FpXib7epSTsz0Q0m+6sg6Y4KtcFTlah1bdOVg==",
"dependencies": {
"debug": "~4.3.4",
"ws": "~8.11.0"
}
},
"node_modules/socket.io-adapter/node_modules/ws": {
"version": "8.11.0",
"resolved": "https://registry.npmmirror.com/ws/-/ws-8.11.0.tgz",
"integrity": "sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==",
"engines": {
"node": ">=10.0.0"
},
"peerDependencies": {
"bufferutil": "^4.0.1",
"utf-8-validate": "^5.0.2"
},
"peerDependenciesMeta": {
"bufferutil": {
"optional": true
},
"utf-8-validate": {
"optional": true
}
}
},
"node_modules/socket.io-client": {
"version": "4.7.5",
"resolved": "https://registry.npmmirror.com/socket.io-client/-/socket.io-client-4.7.5.tgz",
"integrity": "sha512-sJ/tqHOCe7Z50JCBCXrsY3I2k03iOiUe+tj1OmKeD2lXPiGH/RUCdTZFoqVyN7l1MnpIzPrGtLcijffmeouNlQ==",
"dependencies": {
"@socket.io/component-emitter": "~3.1.0",
"debug": "~4.3.2",
"engine.io-client": "~6.5.2",
"socket.io-parser": "~4.2.4"
},
"engines": {
"node": ">=10.0.0"
}
},
"node_modules/socket.io-parser": {
"version": "4.2.4",
"resolved": "https://registry.npmmirror.com/socket.io-parser/-/socket.io-parser-4.2.4.tgz",
"integrity": "sha512-/GbIKmo8ioc+NIWIhwdecY0ge+qVBSMdgxGygevmdHj24bsfgtCmcUUcQ5ZzcylGFHsN3k4HB4Cgkl96KVnuew==",
"dependencies": {
"@socket.io/component-emitter": "~3.1.0",
"debug": "~4.3.1"
},
"engines": {
"node": ">=10.0.0"
}
},
"node_modules/socks": { "node_modules/socks": {
"version": "2.8.1", "version": "2.8.1",
"resolved": "https://registry.npmmirror.com/socks/-/socks-2.8.1.tgz", "resolved": "https://registry.npmmirror.com/socks/-/socks-2.8.1.tgz",
...@@ -9750,6 +9982,14 @@ ...@@ -9750,6 +9982,14 @@
"node": "^14.17.0 || ^16.13.0 || >=18.0.0" "node": "^14.17.0 || ^16.13.0 || >=18.0.0"
} }
}, },
"node_modules/vary": {
"version": "1.1.2",
"resolved": "https://registry.npmmirror.com/vary/-/vary-1.1.2.tgz",
"integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/vite": { "node_modules/vite": {
"version": "5.2.7", "version": "5.2.7",
"resolved": "https://registry.npmmirror.com/vite/-/vite-5.2.7.tgz", "resolved": "https://registry.npmmirror.com/vite/-/vite-5.2.7.tgz",
...@@ -10343,6 +10583,14 @@ ...@@ -10343,6 +10583,14 @@
} }
} }
}, },
"node_modules/xmlhttprequest-ssl": {
"version": "2.0.0",
"resolved": "https://registry.npmmirror.com/xmlhttprequest-ssl/-/xmlhttprequest-ssl-2.0.0.tgz",
"integrity": "sha512-QKxVRxiRACQcVuQEYFsI1hhkrMlrXHPegbbd1yn9UHOmRxY+si12nQYzri3vbzt8VdTTRviqcKxcyllFas5z2A==",
"engines": {
"node": ">=0.4.0"
}
},
"node_modules/xtend": { "node_modules/xtend": {
"version": "4.0.2", "version": "4.0.2",
"resolved": "https://registry.npmmirror.com/xtend/-/xtend-4.0.2.tgz", "resolved": "https://registry.npmmirror.com/xtend/-/xtend-4.0.2.tgz",
......
...@@ -12,10 +12,13 @@ ...@@ -12,10 +12,13 @@
"dependencies": { "dependencies": {
"@pinia/nuxt": "^0.5.1", "@pinia/nuxt": "^0.5.1",
"dockerode": "^3.3.5", "dockerode": "^3.3.5",
"engine.io": "^6.5.4",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"nuxt": "^3.11.1", "nuxt": "^3.11.1",
"pg": "^8.11.5", "pg": "^8.11.5",
"pinia": "^2.1.7", "pinia": "^2.1.7",
"socket.io": "^4.7.5",
"socket.io-client": "^4.7.5",
"tar-fs": "^3.0.5", "tar-fs": "^3.0.5",
"telnet-client": "^2.2.0", "telnet-client": "^2.2.0",
"vue": "^3.4.21", "vue": "^3.4.21",
......
...@@ -98,6 +98,7 @@ ...@@ -98,6 +98,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { useUserStore } from '~/store/user'; import { useUserStore } from '~/store/user';
import { io } from 'socket.io-client';
const username = ref(useUserStore().username) const username = ref(useUserStore().username)
...@@ -105,7 +106,7 @@ const status = ref('null') // null | created | stopped | running | creating | co ...@@ -105,7 +106,7 @@ const status = ref('null') // null | created | stopped | running | creating | co
const statusV1 = ref('null') const statusV1 = ref('null')
const loading = ref(false) const loading = ref(false)
const logLevel = ref('progress') // info | progress const logLevel = ref('progress') // info | progress
const logs = ref([]) const logs = ref([] as string[])
const port = ref(0) const port = ref(0)
const renderLogs = computed(() => { const renderLogs = computed(() => {
...@@ -114,29 +115,25 @@ const renderLogs = computed(() => { ...@@ -114,29 +115,25 @@ const renderLogs = computed(() => {
}) })
onMounted(() => { onMounted(() => {
// socket = io({ const socket = io({
// path: '/api/socket', path: '/socket.io',
// auth: { auth: {
// username: username username: username.value
// } }
// }); });
// // eslint-disable-next-line no-control-regex // eslint-disable-next-line no-control-regex
// const removeLogPrefix = (log) => log.replace(/^\[.*?\]\s/, '').replace(/[\u0000-\u0009]/g, '').replace(/[\u000B-\u001F]/g, '') const removeLogPrefix = (log: string) => log.replace(/^\[.*?\]\s/, '').replace(/[\u0000-\u0009]/g, '').replace(/[\u000B-\u001F]/g, '')
// const replaceLineFlag = (log) => log.replaceAll('\n', '<br />') const replaceLineFlag = (log: string) => log.replaceAll('\n', '<br />')
// socket.on('Log', (log) => { socket.on('Log', (log) => {
// if (logLevel === 'info') { if (logLevel.value === 'info') {
// logs.push(replaceLineFlag(removeLogPrefix(log))) logs.value.push(replaceLineFlag(removeLogPrefix(log)))
// } else { } else {
// if (!log.startsWith('[info]')) { if (!log.startsWith('[info]')) {
// logs.push(replaceLineFlag(removeLogPrefix(log))) logs.value.push(replaceLineFlag(removeLogPrefix(log)))
// } }
// } }
// if (log === '[progress] [[1;31mSuccess[m]] installed') { })
// loading = false
// handleGetStatus()
// }
// })
handleGetStatus() handleGetStatus()
checkAndRestartDocker() checkAndRestartDocker()
...@@ -284,7 +281,7 @@ function handleDebug() { ...@@ -284,7 +281,7 @@ function handleDebug() {
}) })
} }
function test() { function test() {
$fetch('/api/test/putArchive', { method: 'post' }).then(() => { $fetch('/api/devops/v2/test').then(() => {
alert('测试成功') alert('测试成功')
}).catch(() => { }).catch(() => {
alert('测试失败') alert('测试失败')
......
...@@ -3,8 +3,6 @@ import LogUtil from "~/server/utils/log" ...@@ -3,8 +3,6 @@ import LogUtil from "~/server/utils/log"
export default defineEventHandler(async (event) => { export default defineEventHandler(async (event) => {
try { try {
let username = event.context.username let username = event.context.username
let docker = createDockerFactory(username)
let container = await docker.checkContainer('logwire_backend_helper.' + username + '.node')
LogUtil.printInfo(username, '测试消息') LogUtil.printInfo(username, '测试消息')
} catch (err) { } catch (err) {
setResponseStatus(event, 500) setResponseStatus(event, 500)
......
import type { NitroApp } from "nitropack";
import { Server as Engine } from "engine.io";
import { Server } from "socket.io";
import { defineEventHandler } from "h3";
import { setWebsocketIo } from "../utils/log";
export default defineNitroPlugin((nitroApp: NitroApp) => {
const engine = new Engine();
const io = new Server();
io.bind(engine);
io.on("connection", (socket: any) => {
let username = socket.handshake.auth['username']
setWebsocketIo(username, socket)
});
nitroApp.router.use("/socket.io/", defineEventHandler({
handler(event) {
engine.handleRequest(event.node.req, event.node.res);
event._handled = true;
},
websocket: {
open(peer) {
const nodeContext = peer.ctx.node;
const req = nodeContext.req;
// @ts-expect-error private method
engine.prepare(req);
const rawSocket = nodeContext.req.socket;
const websocket = nodeContext.ws;
// @ts-expect-error private method
engine.onWebSocket(req, rawSocket, websocket);
}
}
}));
});
\ No newline at end of file
...@@ -5,43 +5,43 @@ ...@@ -5,43 +5,43 @@
import { setUserConfig, getUserConfig } from "./server" import { setUserConfig, getUserConfig } from "./server"
// import { Socket } from "socket.io/dist/socket"; import { Socket } from "socket.io";
// let websocket: Map<string, Socket> = new Map() let websocket: Map<string, Socket> = new Map()
// export function setWebsocketIo (username: string, io: Socket) { export function setWebsocketIo (username: string, io: Socket) {
// websocket.set(username, io) websocket.set(username, io)
// } }
// export function getWebsocketIo (username: string) { export function getWebsocketIo (username: string) {
// return websocket.get(username) as Socket return websocket.get(username) as Socket
// } }
export default class LogUtil { export default class LogUtil {
// 根据 log 判断用户是否已经执行过 // 根据 log 判断用户是否已经执行过
static async run (username: string, log: string, cb: () => Promise<void>) { static async run (username: string, log: string, cb: () => Promise<void>) {
let key = 'InstallSteps' let key = 'InstallSteps'
let steps: string[] = getUserConfig(username, key) || [] let steps: string[] = getUserConfig(username, key) || []
// let socket = getWebsocketIo(username) let socket = getWebsocketIo(username)
// socket.emit('Log', '[progress] [1m[Loading][m ' + log + '中...\n') socket.emit('Log', '[progress] [1m[Loading][m ' + log + '中...\n')
await cb() await cb()
steps.push(log) steps.push(log)
setUserConfig(username, key, steps) setUserConfig(username, key, steps)
// socket.emit('Log', '[progress] [1m[Info][m ' + log + '完成\n') socket.emit('Log', '[progress] [1m[Info][m ' + log + '完成\n')
} }
static async print(username: string, log: string) { static async print(username: string, log: string) {
// let socket = getWebsocketIo(username) let socket = getWebsocketIo(username)
// socket.emit('Log', removeUnreadCharacter(log)) socket.emit('Log', removeUnreadCharacter(log))
} }
static async printInfo(username: string, log: string) { static async printInfo(username: string, log: string) {
// let socket = getWebsocketIo(username) let socket = getWebsocketIo(username)
// socket.emit('Log', removeUnreadCharacter(`[progress] [[1;34mInfo[m] ${log} \n`)) socket.emit('Log', removeUnreadCharacter(`[progress] [[1;34mInfo[m] ${log} \n`))
} }
static async printError(username: string, log: string) { static async printError(username: string, log: string) {
// let socket = getWebsocketIo(username) let socket = getWebsocketIo(username)
// socket.emit('Log', removeUnreadCharacter(`[error] [[1;31mError[m] ${log} \n`)) socket.emit('Log', removeUnreadCharacter(`[error] [[1;31mError[m] ${log} \n`))
} }
static async printSuccess(username: string, log: string) { static async printSuccess(username: string, log: string) {
// let socket = getWebsocketIo(username) let socket = getWebsocketIo(username)
// socket.emit('Log', removeUnreadCharacter(`[progress] [[1;31mSuccess[m] ${log} \n`)) socket.emit('Log', removeUnreadCharacter(`[progress] [[1;31mSuccess[m] ${log} \n`))
} }
static async printWarning (username: string, log: string) { static async printWarning (username: string, log: string) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment