From 260261fcfe2f315828a9fafe1293f5a6f1012f8a Mon Sep 17 00:00:00 2001 From: undefined Date: Mon, 12 Apr 2021 22:32:57 +0800 Subject: [PATCH] core: cli: allow calling with Arg::ObjectId --- packages/hydrooj/src/entry/cli.ts | 8 +++++++- packages/hydrooj/src/entry/master.ts | 8 +------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/hydrooj/src/entry/cli.ts b/packages/hydrooj/src/entry/cli.ts index f50efdddc..d93cde2f9 100644 --- a/packages/hydrooj/src/entry/cli.ts +++ b/packages/hydrooj/src/entry/cli.ts @@ -1,6 +1,7 @@ /* eslint-disable no-await-in-loop */ /* eslint-disable import/no-dynamic-require */ import { argv } from 'yargs'; +import { ObjectID } from 'mongodb'; import { lib, service, model, builtinLib, builtinModel, @@ -21,7 +22,7 @@ function parseParameters(fn: Function) { } async function cli() { - const [, modelName, func, ...args] = argv._; + const [, modelName, func, ...args] = argv._ as [string, string, string, ...any[]]; if (!global.Hydro.model[modelName]) { return console.error(`Model ${modelName} doesn't exist.`); } @@ -45,6 +46,11 @@ async function cli() { console.error(`Too few arguments. Min ${parameterMin}`); return console.error(parameters.join(', ')); } + for (let i = 0; i < args.length; i++) { + if (ObjectID.isValid(args[i])) { + args[i] = new ObjectID(args[i]); + } + } let result = global.Hydro.model[modelName][func](...args); if (result instanceof Promise) result = await result; return console.log(result); diff --git a/packages/hydrooj/src/entry/master.ts b/packages/hydrooj/src/entry/master.ts index 407ddae53..6bca3532a 100644 --- a/packages/hydrooj/src/entry/master.ts +++ b/packages/hydrooj/src/entry/master.ts @@ -75,16 +75,10 @@ export async function load(call: Entry) { while (dbVer < expected) { logger.info('Upgrading database: from %d to %d', dbVer, expected); const func = scripts[dbVer]; - if (typeof func !== 'function') { + if (typeof func !== 'function' || (isFresh && func.toString().includes('_FRESH_INSTALL_IGNORE'))) { dbVer++; continue; } - if (isFresh) { - if (func.toString().includes('_FRESH_INSTALL_IGNORE')) { - dbVer++; - continue; - } - } const result = await func(); if (!result) break; dbVer++;