core: fix cli usage

This commit is contained in:
undefined committed 2022-09-27 03:28:34 +08:00
1 parent 895d50530a
commit 5f7dae0111
2 files changed
+22 -23

No files matched your search

+13 -8
View File
@@ -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]}`);
+9 -15
View File
@@ -186,21 +186,15 @@ class RemoteStorageService {
async signDownloadLink(target: string, filename?: string, noExpire = false, useAlternativeEndpointFor?: 'user' | 'judge'): Promise<string> {
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) {