From 07d7a38a1bf023115348c7d097dfeff9f8de2a9b Mon Sep 17 00:00:00 2001 From: undefined Date: Sun, 28 Feb 2021 14:43:53 +0800 Subject: [PATCH] codeql: remove some useless check --- packages/fps-importer/handler.ts | 26 +++++++++----------- packages/hydrojudge/bin/hydrojudge.js | 4 +-- packages/hydrojudge/src/judge/hack.ts | 1 - packages/hydrooj/src/handler/import.syzoj.ts | 2 +- packages/hydrooj/src/handler/remote.ts | 3 +-- packages/hydrooj/src/loader.ts | 3 +-- packages/hydrooj/src/model/contest.ts | 2 +- 7 files changed, 18 insertions(+), 23 deletions(-) diff --git a/packages/fps-importer/handler.ts b/packages/fps-importer/handler.ts index 8513b8291..c783a12fe 100644 --- a/packages/fps-importer/handler.ts +++ b/packages/fps-importer/handler.ts @@ -62,20 +62,18 @@ class FpsProblemImportHandler extends Handler { async post({ domainId }) { if (!this.request.files.file) throw new ValidationError('file'); const tasks = []; - if (this.request.files.file) { - try { - const content = fs.readFile(this.request.files.file.path).toString(); - const result = await xml2js.parseStringPromise(content); - tasks.push(result); - } catch (e) { - const zip = new AdmZip(this.request.files.file.path); - for (const entry of zip.getEntries()) { - try { - const content = entry.getData().toString(); - const result = await xml2js.parseStringPromise(content); - tasks.push(result); - } catch { } // eslint-disable-line no-empty - } + try { + const content = fs.readFile(this.request.files.file.path).toString(); + const result = await xml2js.parseStringPromise(content); + tasks.push(result); + } catch (e) { + const zip = new AdmZip(this.request.files.file.path); + for (const entry of zip.getEntries()) { + try { + const content = entry.getData().toString(); + const result = await xml2js.parseStringPromise(content); + tasks.push(result); + } catch { } // eslint-disable-line no-empty } } if (!tasks.length) throw new ValidationError('file'); diff --git a/packages/hydrojudge/bin/hydrojudge.js b/packages/hydrojudge/bin/hydrojudge.js index 7acdbca26..d84f0bcf7 100755 --- a/packages/hydrojudge/bin/hydrojudge.js +++ b/packages/hydrojudge/bin/hydrojudge.js @@ -2,5 +2,5 @@ const { argv } = require('yargs'); -if (argv._[0] == 'cache') require('../dist/cache')() -else if (!argv._) require('../dist/daemon')(); \ No newline at end of file +if ((argv._ || [])[0] == 'cache') require('../dist/cache')() +else require('../dist/daemon')(); diff --git a/packages/hydrojudge/src/judge/hack.ts b/packages/hydrojudge/src/judge/hack.ts index fd6acce64..8b9e56330 100644 --- a/packages/hydrojudge/src/judge/hack.ts +++ b/packages/hydrojudge/src/judge/hack.ts @@ -106,7 +106,6 @@ export const judge = async (ctx) => { }); } } else if (status === STATUS.STATUS_RUNTIME_ERROR && code) { - status = STATUS.STATUS_RUNTIME_ERROR; if (code < 32) message = signals[code]; else message = `您的程序返回了 ${code}.`; } diff --git a/packages/hydrooj/src/handler/import.syzoj.ts b/packages/hydrooj/src/handler/import.syzoj.ts index 9cdcff4c7..673cd2679 100644 --- a/packages/hydrooj/src/handler/import.syzoj.ts +++ b/packages/hydrooj/src/handler/import.syzoj.ts @@ -114,7 +114,7 @@ class ProblemImportSYZOJHandler extends Handler { // eslint-disable-next-line no-await-in-loop await problem.addTestdata(domainId, docId, entry.entryName, entry.getData()); } - const filename = p.file_io_input_name ? p.file_io_input_name?.split('.')[0] : null; + const filename = p.file_io_input_name ? p.file_io_input_name.split('.')[0] : null; const config = { time: `${p.time_limit}ms`, memory: `${p.memory_limit}m`, diff --git a/packages/hydrooj/src/handler/remote.ts b/packages/hydrooj/src/handler/remote.ts index bea990597..a05c7e328 100644 --- a/packages/hydrooj/src/handler/remote.ts +++ b/packages/hydrooj/src/handler/remote.ts @@ -128,7 +128,6 @@ export class ProblemReceiveHandler extends Handler { pids: filterPid.length ? filterPid.map((i) => (+i ? +i : i)) : data.pids, }).catch(logAndReturn(logger)); if (res instanceof Error) throw new RemoteOnlineJudgeError(res.message); - const tasks = []; const pids = []; const { pdocs } = res.body; const files = res.body.links; @@ -142,7 +141,7 @@ export class ProblemReceiveHandler extends Handler { } const pid = await problem.add(domainId, pdoc.pid, pdoc.title, pdoc.content, this.user._id, pdoc.tag, pdoc.category); pids.push(pid); - tasks.push(this.syncFiles(domainId, baseUrl, pid, files[i])); + this.syncFiles(domainId, baseUrl, pid, files[i]).catch(logAndReturn(logger)); await problem.edit(domainId, pid, { html: pdoc.html }); } this.back(); diff --git a/packages/hydrooj/src/loader.ts b/packages/hydrooj/src/loader.ts index f4c19e5af..281a8bfd3 100644 --- a/packages/hydrooj/src/loader.ts +++ b/packages/hydrooj/src/loader.ts @@ -135,12 +135,11 @@ process.on('uncaughtException', logger.error); const publicTemp = path.resolve(os.tmpdir(), 'hydro', 'public'); export function addon(addonPath: string) { - let modulePath = path.resolve(process.cwd(), addonPath); if (!(fs.existsSync(addonPath) && fs.statSync(addonPath).isFile())) { try { // Is a npm package const packagejson = require.resolve(`${addonPath}/package.json`); - modulePath = path.dirname(packagejson); + const modulePath = path.dirname(packagejson); const publicPath = path.resolve(modulePath, 'public'); if (fs.existsSync(publicPath)) fs.copySync(publicPath, publicTemp); global.addons.push(modulePath); diff --git a/packages/hydrooj/src/model/contest.ts b/packages/hydrooj/src/model/contest.ts index 6d8c47f44..36b19cb52 100644 --- a/packages/hydrooj/src/model/contest.ts +++ b/packages/hydrooj/src/model/contest.ts @@ -325,7 +325,7 @@ const homework: ContestRule = { const colScore = tsddict[pid]?.penaltyScore || '-'; const colOriginalScore = tsddict[pid]?.score || '-'; const colTime = tsddict[pid]?.time || '-'; - const colTimeStr = colTime !== '-' ? misc.formatSeconds(colTime || 0) : '-'; + const colTimeStr = colTime !== '-' ? misc.formatSeconds(colTime) : '-'; if (isExport) { row.push( { type: 'string', value: colScore },