From fb04aaacb926e53326ba5a96fa7b6482419c4be5 Mon Sep 17 00:00:00 2001 From: undefined Date: Wed, 25 Jun 2025 16:25:19 +0800 Subject: [PATCH] core: static: auto cleanup stale file --- packages/hydrooj/src/entry/worker.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/hydrooj/src/entry/worker.ts b/packages/hydrooj/src/entry/worker.ts index 85e304293..a041a57b8 100644 --- a/packages/hydrooj/src/entry/worker.ts +++ b/packages/hydrooj/src/entry/worker.ts @@ -1,4 +1,3 @@ -/* eslint-disable no-await-in-loop */ import os from 'os'; import path from 'path'; import cac from 'cac'; @@ -69,6 +68,12 @@ export async function apply(ctx: Context) { await loadDir(path.resolve(__dirname, '..', 'script')); await ctx.parallel('app/started'); if (process.env.NODE_APP_INSTANCE === '0') { + const staticDir = path.join(os.homedir(), '.hydro/static'); + await fs.emptyDir(staticDir); + await Promise.all(Object.values(global.addons).map(async (f) => { + const dir = path.join(f, 'public'); + if (await fs.pathExists(dir)) await fs.copy(dir, staticDir); + })); await new Promise((resolve, reject) => { ctx.inject(['migration'], async (c) => { c.migration.registerChannel('hydrooj', require('../upgrade').coreScripts); @@ -82,10 +87,6 @@ export async function apply(ctx: Context) { }); }); } - for (const f of Object.values(global.addons)) { - const dir = path.join(f, 'public'); - if (await fs.pathExists(dir)) await fs.copy(dir, path.join(os.homedir(), '.hydro/static')); - } ctx.inject(['server'], async ({ server }) => { await server.listen(); await ctx.parallel('app/listen');