From a2ea3812df2125f9ab0ac62796f2e2115ceaa407 Mon Sep 17 00:00:00 2001 From: undefined Date: Sat, 26 Nov 2022 20:28:11 +0800 Subject: [PATCH] core: allow homepage config injection --- build/prepare.js | 1 + install/install.sh | 2 +- packages/hydrooj/src/handler/home.ts | 2 +- packages/hydrooj/src/service/server.ts | 9 +++------ test/main.ts | 13 +++++-------- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/build/prepare.js b/build/prepare.js index 6d59ad0b..8029fe80 100644 --- a/build/prepare.js +++ b/build/prepare.js @@ -9,6 +9,7 @@ const compilerOptionsBase = { module: 'commonjs', esModuleInterop: true, moduleResolution: 'node', + jsx: 'react', sourceMap: false, composite: true, strictBindCallApply: true, diff --git a/install/install.sh b/install/install.sh index 895eeb27..947ce03d 100644 --- a/install/install.sh +++ b/install/install.sh @@ -9,7 +9,7 @@ if [ $EUID != 0 ]; then fi set -e echo "Executing Hydro install script v3.0.0" -echo "Hydro includes anonymous system telemetry, +echo "Hydro includes system telemetry, which helps developers figure out the most commonly used operating system and platform. To disable this feature, checkout our sourcecode." mkdir -p /data/db /data/file ~/.hydro diff --git a/packages/hydrooj/src/handler/home.ts b/packages/hydrooj/src/handler/home.ts index e2085ab9..a44c8035 100644 --- a/packages/hydrooj/src/handler/home.ts +++ b/packages/hydrooj/src/handler/home.ts @@ -114,7 +114,7 @@ export class HomeHandler extends Handler { } async get({ domainId }) { - const homepageConfig = system.get('hydrooj.homepage'); + const homepageConfig = this.domain.homepage || system.get('hydrooj.homepage'); const info = yaml.load(homepageConfig) as any; const contents = []; for (const column of info) { diff --git a/packages/hydrooj/src/service/server.ts b/packages/hydrooj/src/service/server.ts index f8f17c9e..52cfac91 100644 --- a/packages/hydrooj/src/service/server.ts +++ b/packages/hydrooj/src/service/server.ts @@ -453,18 +453,15 @@ export async function apply(pluginContext: Context) { rewrite: (p) => p.replace('/fs', ''), }); app.use(async (ctx, next) => { + for (const key in captureAllRoutes) { + if (ctx.path.startsWith(key)) return captureAllRoutes[key](ctx, next); + } if (!ctx.path.startsWith('/fs/')) return await next(); if (ctx.request.search.toLowerCase().includes('x-amz-credential')) return await proxyMiddleware(ctx, next); ctx.request.path = ctx.path = ctx.path.split('/fs')[1]; return await next(); }); app.use(Compress()); - app.use(async (ctx, next) => { - for (const key in captureAllRoutes) { - if (ctx.path.startsWith(key)) return captureAllRoutes[key](ctx, next); - } - return next(); - }); for (const addon of [...global.addons].reverse()) { const dir = resolve(addon, 'public'); if (!fs.existsSync(dir)) continue; diff --git a/test/main.ts b/test/main.ts index 791a2d44..d529d66c 100644 --- a/test/main.ts +++ b/test/main.ts @@ -70,14 +70,11 @@ describe('App', () => { } after(() => { - const metrics = []; - for (const key in results) { - metrics.push({ - name: `Benchmark - ${key} - Req/sec`, - unit: 'Req/sec', - value: results[key].requests.average, - }); - } + const metrics = Object.entries(([k, v]) => ({ + name: `Benchmark - ${k} - Req/sec`, + unit: 'Req/sec', + value: v.requests.average, + })); writeFileSync('./benchmark.json', JSON.stringify(metrics, null, 2)); setTimeout(() => process.exit(0), 1000); });