better code: removed obsolete code

Massimo Melina committed Jun 5, 2023 at 00:14 UTC 54ae29067e61fc258cd067967ceb95d20e34190c
2 files changed +3 -5
src/api.plugins.ts
+2 -2
@@ -23,7 +23,7 @@ import { ApiError, ApiHandlers, SendListReadable } from './apiMiddleware'
23 import events from './events'
24 import { rm } from 'fs/promises'
25 import { downloadPlugin, getFolder2repo, getRepoInfo, readOnlinePlugin, searchPlugins } from './github'
26 -import { HTTP_SERVER_ERROR } from './const'
26 +import { HTTP_NOT_FOUND, HTTP_SERVER_ERROR } from './const'
27
28 const apis: ApiHandlers = {
29
@@ -155,7 +155,7 @@ const apis: ApiHandlers = {
155 async update_plugin(pl) {
156 const found = findPluginByRepo(pl.id) // github id !== local id
157 if (!found)
158 - return new ApiError(404)
158 + return new ApiError(HTTP_NOT_FOUND)
159 const enabled = isPluginEnabled(found.id)
160 await stopPlugin(found.id)
161 await downloadPlugin(pl.id, pl.branch, true)
src/config.ts
+1 -3
@@ -187,9 +187,7 @@ const saveDebounced = debounceAsync(async () => {
187 if (await stat(bak).then(x => aWeekAgo > Number(x.mtime || x.ctime), () => true))
188 await copyFile(filePath, bak).catch(() => {}) // ignore errors
189
190 - let txt = yaml.stringify({ ...state, version: VERSION }, { lineWidth:1000 })
191 - if (txt.trim() === '{}') // most users wouldn't understand
192 - txt = ''
190 + const txt = yaml.stringify({ ...state, version: VERSION }, { lineWidth:1000 })
191 save(filePath, txt)
192 .catch(err => console.error('Failed at saving config file, please ensure it is writable.', String(err)))
193 })