支持自定义客户端端口

This commit is contained in:
chaos-zhu 2024-10-13 23:38:59 +08:00
parent e784092c1a
commit da36ed9d1b
6 changed files with 19 additions and 21 deletions

View File

@ -4,7 +4,7 @@ consola.info('debug日志', process.env.DEBUG === '1' ? '开启' : '关闭')
module.exports = {
httpPort: 8082,
clientPort: 22022, // 暂不支持更改
clientDefaultPort: 22022,
uploadDir: path.join(process.cwd(),'app/db'),
staticDir: path.join(process.cwd(),'app/static'),
sftpCacheDir: path.join(process.cwd(),'app/socket/sftp-cache'),

View File

@ -1,7 +1,7 @@
const { Server: ServerIO } = require('socket.io')
const { io: ClientIO } = require('socket.io-client')
const { readHostList } = require('../utils/storage')
const { clientPort } = require('../config')
const { clientDefaultPort } = require('../config')
const { verifyAuthSync } = require('../utils/verify-auth')
const { isAllowedIp } = require('../utils/tools')
@ -15,9 +15,9 @@ async function getClientsInfo(clientSockets) {
if (!hostList.some(item => item.host === clientItem.host)) clientItem.close && clientItem.close()
})
hostList
.map(({ host, name }) => {
.map(({ host, name, clientPort }) => {
if (clientSockets.some(item => item.host === host)) return { name, isIo: true } // 已经建立io连接(无论是否连接成功)的host不再重复建立连接,因为存在多次(reconnectionAttempts)的重试机制
let clientSocket = ClientIO(`http://${ host }:${ clientPort }`, {
let clientSocket = ClientIO(`http://${ host }:${ clientPort || clientDefaultPort }`, {
path: '/client/os-info',
forceNew: true,
timeout: 5000,

View File

@ -24,7 +24,6 @@ app.config.globalProperties.$store = useStore()
const serviceURI = import.meta.env.DEV ? process.env.serviceURI : location.origin
app.config.globalProperties.$serviceURI = serviceURI
app.config.globalProperties.$clientPort = process.env.clientPort || 22022
app.config.globalProperties.$store.$patch({ serviceURI })
console.warn('ISDEV: ', import.meta.env.DEV)
console.warn('serviceURI: ', serviceURI)

View File

@ -21,7 +21,7 @@ const useStore = defineStore({
}),
actions: {
async setJwtToken(token, isSession = true) {
if(isSession) sessionStorage.setItem('token', token)
if (isSession) sessionStorage.setItem('token', token)
else localStorage.setItem('token', token)
this.$patch({ token })
},
@ -73,7 +73,7 @@ const useStore = defineStore({
// setInterval(() => {
// this.hostList.forEach((item) => {
// const { host } = item
// ping(`http://${ host }:${ this.$clientPort }`)
// ping(`http://${ host }:${ 22022 }`)
// .then((res) => {
// item.ping = res
// })
@ -121,7 +121,7 @@ const useStore = defineStore({
localStorage.setItem('isDark', isDark)
this.$patch({ isDark })
}
if(animate) {
if (animate) {
let transition = document.startViewTransition(() => {
document.documentElement.classList.toggle('dark')
})

View File

@ -301,17 +301,17 @@ const handleColor = (num) => {
if (num <= 100) return '#ff4949'
}
const getHostPing = () => {
pingTimer.value = setInterval(() => {
$tools.ping(`http://${ props.host }:22022`)
.then(res => {
ping.value = res
if (!import.meta.env.DEV) {
console.warn('Please tick \'Preserve Log\'')
}
})
}, 3000)
}
// const getHostPing = () => {
// pingTimer.value = setInterval(() => {
// $tools.ping(`http://${ props.host }:22022`)
// .then(res => {
// ping.value = res
// if (!import.meta.env.DEV) {
// console.warn('Please tick \'Preserve Log\'')
// }
// })
// }, 3000)
// }
onBeforeUnmount(() => {
socket.value && socket.value.close()

View File

@ -37,8 +37,7 @@ export default defineConfig({
define: {
'process.env': {
serviceURI,
serviceApiPrefix,
clientPort: 22022
serviceApiPrefix
}
},
plugins: [