修复注册的事件未被清理的问题
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import http from 'node:http'
|
||||
import querystring from 'node:querystring'
|
||||
import type { Socket } from 'node:net'
|
||||
import { getAddress } from '@common/utils/nodejs'
|
||||
|
||||
let status: LX.OpenAPI.Status = {
|
||||
status: false,
|
||||
@@ -198,11 +199,13 @@ export const stopServer = async() => {
|
||||
return status
|
||||
}
|
||||
export const startServer = async(port: number, bindLan: boolean) => {
|
||||
if (status.status) await handleStopServer()
|
||||
if (status.status) await stopServer()
|
||||
await handleStartServer(port, bindLan ? '0.0.0.0' : '127.0.0.1').then(() => {
|
||||
status.status = true
|
||||
status.message = ''
|
||||
status.address = `http://localhost${port == 80 ? '' : ':' + port}`
|
||||
let address = ['127.0.0.1']
|
||||
if (bindLan) address = [...address, ...getAddress()]
|
||||
status.address = address.join(', ')
|
||||
}).catch(err => {
|
||||
console.log(err)
|
||||
status.status = false
|
||||
|
||||
@@ -6,10 +6,11 @@ import { callObj } from './sync'
|
||||
// import registerSyncListHandler from './syncList'
|
||||
import log from '../log'
|
||||
import { dateFormat } from '@common/utils/common'
|
||||
import { aesEncrypt, getAddress } from '../utils'
|
||||
import { aesEncrypt } from '../utils'
|
||||
import { sendClientStatus } from '@main/modules/winMain'
|
||||
import { createMsg2call } from 'message2call'
|
||||
import { SYNC_CLOSE_CODE, SYNC_CODE } from '@common/constants_sync'
|
||||
import { getAddress } from '@common/utils/nodejs'
|
||||
|
||||
let status: LX.Sync.ClientStatus = {
|
||||
status: false,
|
||||
|
||||
@@ -2,7 +2,6 @@ import http, { type IncomingMessage } from 'node:http'
|
||||
import { WebSocketServer } from 'ws'
|
||||
import { registerLocalSyncEvent, callObj, sync, unregisterLocalSyncEvent } from './sync'
|
||||
import { authCode, authConnect } from './auth'
|
||||
import { getAddress } from '../../utils'
|
||||
import { SYNC_CLOSE_CODE, SYNC_CODE } from '@common/constants_sync'
|
||||
import { getUserSpace, releaseUserSpace, getServerId, initServerInfo } from '../user'
|
||||
import { createMsg2call } from 'message2call'
|
||||
@@ -11,6 +10,7 @@ import { sendServerStatus } from '@main/modules/winMain'
|
||||
import { decryptMsg, encryptMsg, generateCode as handleGenerateCode } from '../utils/tools'
|
||||
import migrateData from '../../migrate'
|
||||
import type { Socket } from 'node:net'
|
||||
import { getAddress } from '@common/utils/nodejs'
|
||||
|
||||
|
||||
let status: LX.Sync.ServerStatus = {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { networkInterfaces } from 'node:os'
|
||||
import { createCipheriv, createDecipheriv, publicEncrypt, privateDecrypt, constants } from 'node:crypto'
|
||||
// import { join } from 'node:path'
|
||||
import zlib from 'node:zlib'
|
||||
@@ -8,23 +7,6 @@ import type http from 'node:http'
|
||||
// import { getUserName } from '../user/data'
|
||||
// import { saveClientKeyInfo } from './data'
|
||||
|
||||
export const getAddress = (): string[] => {
|
||||
const nets = networkInterfaces()
|
||||
const results: string[] = []
|
||||
// console.log(nets)
|
||||
|
||||
for (const interfaceInfos of Object.values(nets)) {
|
||||
if (!interfaceInfos) continue
|
||||
// Skip over non-IPv4 and internal (i.e. 127.0.0.1) addresses
|
||||
for (const interfaceInfo of interfaceInfos) {
|
||||
if (interfaceInfo.family === 'IPv4' && !interfaceInfo.internal) {
|
||||
results.push(interfaceInfo.address)
|
||||
}
|
||||
}
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
export const generateCode = (): string => {
|
||||
return Math.random().toString().substring(2, 8)
|
||||
}
|
||||
|
||||
@@ -1,28 +1,10 @@
|
||||
import { createCipheriv, createDecipheriv, publicEncrypt, privateDecrypt, constants } from 'node:crypto'
|
||||
import os, { networkInterfaces } from 'node:os'
|
||||
import os from 'node:os'
|
||||
import fs from 'node:fs'
|
||||
import zlib from 'node:zlib'
|
||||
import cp from 'node:child_process'
|
||||
|
||||
|
||||
export const getAddress = (): string[] => {
|
||||
const nets = networkInterfaces()
|
||||
const results: string[] = []
|
||||
// console.log(nets)
|
||||
|
||||
for (const interfaceInfos of Object.values(nets)) {
|
||||
if (!interfaceInfos) continue
|
||||
// Skip over non-IPv4 and internal (i.e. 127.0.0.1) addresses
|
||||
for (const interfaceInfo of interfaceInfos) {
|
||||
if (interfaceInfo.family === 'IPv4' && !interfaceInfo.internal) {
|
||||
results.push(interfaceInfo.address)
|
||||
}
|
||||
}
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
|
||||
// https://stackoverflow.com/a/75309339
|
||||
export const getComputerName = () => {
|
||||
let name: string | undefined
|
||||
@@ -40,6 +22,7 @@ export const getComputerName = () => {
|
||||
try {
|
||||
name = cp.execSync('hostnamectl --pretty').toString().trim()
|
||||
} catch {}
|
||||
break
|
||||
}
|
||||
if (!name) name = os.hostname()
|
||||
return name
|
||||
|
||||
Reference in New Issue
Block a user