From 5f7dae0111899667c070514b3230be35c3e5679c Mon Sep 17 00:00:00 2001 From: undefined Date: Tue, 27 Sep 2022 03:28:34 +0800 Subject: [PATCH] core: fix cli usage --- packages/hydrooj/src/entry/cli.ts | 21 +++++++++++++-------- packages/hydrooj/src/service/storage.ts | 24 +++++++++--------------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/packages/hydrooj/src/entry/cli.ts b/packages/hydrooj/src/entry/cli.ts index 7033d568d..10a9fdc12 100644 --- a/packages/hydrooj/src/entry/cli.ts +++ b/packages/hydrooj/src/entry/cli.ts @@ -6,7 +6,7 @@ import fs from 'fs-extra'; import { ObjectID } from 'mongodb'; import db from '../service/db'; import { - lib, model, script, service, + addon, lib, model, script, service, setting, } from './common'; const argv = cac().parse(); @@ -87,15 +87,20 @@ export async function load(ctx) { require('../error'); await db.start(); await require('../settings').loadConfig(); - const storage = require('../service/storage'); - await storage.loadStorageService(); + await require('../model/system').runConfig(); + await require('../service/storage').loadStorageService(); + await ctx.root.start(); require('../lib/index'); - await lib(pending, fail, ctx); - const systemModel = require('../model/system'); - await systemModel.runConfig(); - await service(pending, fail, ctx); + await Promise.all([ + lib(pending, fail, ctx), + service(pending, fail, ctx), + ]); require('../model/index'); - await model(pending, fail, ctx); + await Promise.all([ + model(pending, fail, ctx), + setting(pending, fail, require('../model/setting')), + ]); + await addon(pending, fail, ctx); const scriptDir = path.resolve(__dirname, '..', 'script'); for (const h of await fs.readdir(scriptDir)) { ctx.loader.reloadPlugin(ctx, path.resolve(scriptDir, h), {}, `hydrooj/script/${h.split('.')[0]}`); diff --git a/packages/hydrooj/src/service/storage.ts b/packages/hydrooj/src/service/storage.ts index 36f8bba4d..6dbb42ae9 100644 --- a/packages/hydrooj/src/service/storage.ts +++ b/packages/hydrooj/src/service/storage.ts @@ -186,21 +186,15 @@ class RemoteStorageService { async signDownloadLink(target: string, filename?: string, noExpire = false, useAlternativeEndpointFor?: 'user' | 'judge'): Promise { if (target.includes('..') || target.includes('//')) throw new Error('Invalid path'); - try { - const url = await getSignedUrl(this.client, new GetObjectCommand({ - Bucket: this.opts.bucket, - Key: target, - ResponseContentDisposition: filename ? `attachment; filename="${encodeRFC5987ValueChars(filename)}"` : '', - }), { - expiresIn: noExpire ? 24 * 60 * 60 * 7 : 10 * 60, - }); - console.log(url); - if (useAlternativeEndpointFor) return this.replaceWithAlternativeUrlFor[useAlternativeEndpointFor](url); - return url; - } catch (e) { - e.stack = new Error().stack; - throw e; - } + const url = await getSignedUrl(this.client, new GetObjectCommand({ + Bucket: this.opts.bucket, + Key: target, + ResponseContentDisposition: filename ? `attachment; filename="${encodeRFC5987ValueChars(filename)}"` : '', + }), { + expiresIn: noExpire ? 24 * 60 * 60 * 7 : 10 * 60, + }); + if (useAlternativeEndpointFor) return this.replaceWithAlternativeUrlFor[useAlternativeEndpointFor](url); + return url; } async signUpload(target: string, size: number) {