diff --git a/src/main/server/index.ts b/src/main/server/index.ts index 919fe2e1..57a229af 100644 --- a/src/main/server/index.ts +++ b/src/main/server/index.ts @@ -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) } diff --git a/src/main/utils/uploader.ts b/src/main/utils/uploader.ts index 8cfa18f4..00c61b08 100644 --- a/src/main/utils/uploader.ts +++ b/src/main/utils/uploader.ts @@ -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')) { diff --git a/tsconfig.json b/tsconfig.json index e3d66c89..5ab1d8d0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "esnext", + "target": "es2020", "module": "esnext", "strict": true, "jsx": "preserve",