mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-01-22 22:28:14 -05:00
🐛 Fix: server may never start
This commit is contained in:
parent
5f2b7c7802
commit
73870a5326
@ -10,13 +10,30 @@ class Server {
|
||||
private httpServer: http.Server
|
||||
private config: IServerConfig
|
||||
constructor () {
|
||||
this.config = picgo.getConfig('settings.server') || {
|
||||
port: 36677,
|
||||
host: '127.0.0.1',
|
||||
enable: true
|
||||
let config = picgo.getConfig('settings.server')
|
||||
const result = this.checkIfConfigIsValid(config)
|
||||
if (result) {
|
||||
this.config = config
|
||||
} else {
|
||||
config = {
|
||||
port: 36677,
|
||||
host: '127.0.0.1',
|
||||
enable: true
|
||||
}
|
||||
this.config = config
|
||||
picgo.saveConfig({
|
||||
'settings.server': config
|
||||
})
|
||||
}
|
||||
this.httpServer = http.createServer(this.handleRequest)
|
||||
}
|
||||
private checkIfConfigIsValid (config: IObj | undefined) {
|
||||
if (config && config.port && config.host && (config.enable !== undefined)) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
private handleRequest = (request: http.IncomingMessage, response: http.ServerResponse) => {
|
||||
if (request.method === 'POST') {
|
||||
if (!routers.getHandler(request.url!)) {
|
||||
@ -65,7 +82,7 @@ class Server {
|
||||
logger.warn(`[PicGo Server] ${port} is busy, trying with port ${port + 1}`)
|
||||
this.config.port += 1
|
||||
picgo.saveConfig({
|
||||
'settings.server.port': this.config.port
|
||||
'settings.server': this.config
|
||||
})
|
||||
this.listen(this.config.port)
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ class Uploader {
|
||||
})
|
||||
|
||||
picgo.on('uploadProgress', progress => {
|
||||
this.webContents!.send('uploadProgress', progress)
|
||||
this.webContents?.send('uploadProgress', progress)
|
||||
})
|
||||
picgo.on('beforeTransform', ctx => {
|
||||
if (db.get('settings.uploadNotification')) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"target": "es2020",
|
||||
"module": "esnext",
|
||||
"strict": true,
|
||||
"jsx": "preserve",
|
||||
|
Loading…
Reference in New Issue
Block a user