core&ui: add setting provider

This commit is contained in:
undefined committed 2024-01-15 15:58:28 +08:00
1 parent 886fa6821d
commit 5d2ac74b04
10 files changed
+56 -28

No files matched your search

+1 -8
View File
@@ -1,7 +1,7 @@
import esbuild from 'esbuild';
import {
Context, fs, Handler, Logger, NotFoundError, param, SettingModel, sha1,
size, SystemModel, Types, UiContextBase,
size, Types, UiContextBase,
} from 'hydrooj';
import { debounce } from 'lodash';
import { tmpdir } from 'os';
@@ -17,15 +17,10 @@ declare module 'hydrooj' {
'ui-default.nav_logo_dark': string;
}
interface UiContextBase {
nav_logo_dark?: string;
constantVersion?: string;
}
}
function updateLogo() {
UiContextBase.nav_logo_dark = SystemModel.get('ui-default.nav_logo_dark');
}
const vfs: Record<string, string> = {};
const hashes: Record<string, string> = {};
const logger = new Logger('ui');
@@ -140,13 +135,11 @@ export async function apply(ctx: Context) {
ctx.Route('constant', '/constant/:version', UiConstantsHandler);
ctx.Route('constant', '/lazy/:version/:name', UiConstantsHandler);
ctx.Route('constant', '/resource/:version/:name', UiConstantsHandler);
ctx.on('app/started', updateLogo);
ctx.on('app/started', buildUI);
const debouncedBuildUI = debounce(buildUI, 2000, { trailing: true });
const triggerHotUpdate = (path?: string) => {
if (path && !path.includes('/ui-default/') && !path.includes('/public/')) return;
debouncedBuildUI();
updateLogo();
};
ctx.on('system/setting', () => triggerHotUpdate());
ctx.on('app/watch/change', triggerHotUpdate);
@@ -170,6 +170,7 @@ const render = (name: string, state: any) => new Promise<string>((resolve, rejec
return state._(text.message).format(...text.params || []) + ((process.env.DEV && text.stack) ? `\n${text.stack}` : '');
}).join('\n'),
datetimeSpan: (arg0, arg1, arg2) => misc.datetimeSpan(arg0, arg1, arg2, state.handler.user?.timeZone),
ctx: state.handler?.ctx,
perm: PERM,
PRIV,
STATUS,