mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
core&ui: langs load fix
This commit is contained in:
1 parent
50cb3eaab5
commit
49693c27d4
8 files changed
+30
-46
No files matched your search
@@ -69,6 +69,7 @@ const UIConfig = {
|
||||
],
|
||||
compilerOptions: {
|
||||
experimentalDecorators: true,
|
||||
esModuleInterop: true,
|
||||
resolveJsonModule: true,
|
||||
jsx: 'react',
|
||||
module: 'commonjs',
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "4.0.0",
|
||||
"version": "4.0.1",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "src/plugin-api",
|
||||
"module": "src/plugin-api",
|
||||
|
||||
@@ -59,9 +59,10 @@ export const service = getLoader('service', 'service');
|
||||
|
||||
export async function builtinModel(ctx: Context) {
|
||||
const modelDir = path.resolve(__dirname, '..', 'model');
|
||||
const models = ['task', 'blacklist', 'discussion', 'document'];
|
||||
const models = await fs.readdir(modelDir);
|
||||
for (const t of models) {
|
||||
ctx.loader.reloadPlugin(ctx, path.resolve(modelDir, t), {}, `hydrooj/model/${t}`);
|
||||
const q = path.resolve(modelDir, t);
|
||||
if ('apply' in require(q)) ctx.loader.reloadPlugin(ctx, q, {}, `hydrooj/model/${t.split('.')[0]}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import fs from 'fs-extra';
|
||||
import { Context } from '../context';
|
||||
import { Logger } from '../logger';
|
||||
import db from '../service/db';
|
||||
import { sleep } from '../utils';
|
||||
import {
|
||||
addon, builtinModel, handler, lib, locale, model,
|
||||
script, service, setting, template,
|
||||
@@ -67,6 +68,7 @@ export async function apply(ctx: Context) {
|
||||
await ctx.lifecycle.flush();
|
||||
await script(pending, fail, ctx);
|
||||
await ctx.lifecycle.flush();
|
||||
await sleep(1000); // lifecycle.flush won't wait for async function
|
||||
await ctx.parallel('app/started');
|
||||
if (process.env.NODE_APP_INSTANCE === '0') {
|
||||
const scripts = require('../upgrade').default;
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
import './builtin';
|
||||
import './document';
|
||||
import './domain';
|
||||
import './blacklist';
|
||||
import './opcount';
|
||||
import './setting';
|
||||
import './token';
|
||||
import './user';
|
||||
import './storage';
|
||||
import './problem';
|
||||
import './record';
|
||||
import './contest';
|
||||
import './message';
|
||||
import './solution';
|
||||
import './training';
|
||||
import './discussion';
|
||||
import './system';
|
||||
import './oplog';
|
||||
import './blog';
|
||||
@@ -3,11 +3,11 @@
|
||||
import yaml from 'js-yaml';
|
||||
import { Dictionary } from 'lodash';
|
||||
import moment from 'moment-timezone';
|
||||
import { parseLang } from '@hydrooj/utils/lib/lang';
|
||||
import { LangConfig, parseLang } from '@hydrooj/utils/lib/lang';
|
||||
import { retry } from '@hydrooj/utils/lib/utils';
|
||||
import { Context } from '../context';
|
||||
import { Setting as _Setting } from '../interface';
|
||||
import { Logger } from '../logger';
|
||||
import * as bus from '../service/bus';
|
||||
import * as builtin from './builtin';
|
||||
|
||||
type SettingDict = Dictionary<_Setting>;
|
||||
@@ -238,9 +238,9 @@ SystemSetting(
|
||||
);
|
||||
|
||||
// eslint-disable-next-line import/no-mutable-exports
|
||||
export let langs = {};
|
||||
export const langs: Record<string, LangConfig> = {};
|
||||
|
||||
bus.on('app/started', async () => {
|
||||
export async function apply(ctx: Context) {
|
||||
logger.debug('Ensuring settings');
|
||||
const system = global.Hydro.model.system;
|
||||
for (const setting of SYSTEM_SETTINGS) {
|
||||
@@ -252,27 +252,26 @@ bus.on('app/started', async () => {
|
||||
}
|
||||
}
|
||||
try {
|
||||
langs = parseLang(system.get('hydrooj.langs'));
|
||||
global.Hydro.model.setting.langs = langs;
|
||||
Object.assign(langs, parseLang(system.get('hydrooj.langs')));
|
||||
const range = {};
|
||||
for (const key in langs) range[key] = langs[key].display;
|
||||
LangSettingNode.range = range;
|
||||
ServerLangSettingNode.range = range;
|
||||
} catch (e) { /* Ignore */ }
|
||||
});
|
||||
|
||||
bus.on('system/setting', (args) => {
|
||||
if (args.hydrooj?.langs) {
|
||||
langs = parseLang(args.hydrooj.langs);
|
||||
global.Hydro.model.setting.langs = langs;
|
||||
const range = {};
|
||||
for (const key in langs) range[key] = langs[key].display;
|
||||
LangSettingNode.range = range;
|
||||
ServerLangSettingNode.range = range;
|
||||
}
|
||||
});
|
||||
console.log('l', langs?.cc);
|
||||
ctx.on('system/setting', (args) => {
|
||||
if (args.hydrooj?.langs) {
|
||||
Object.assign(langs, parseLang(args.hydrooj.langs));
|
||||
const range = {};
|
||||
for (const key in langs) range[key] = langs[key].display;
|
||||
LangSettingNode.range = range;
|
||||
ServerLangSettingNode.range = range;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
global.Hydro.model.setting = {
|
||||
apply,
|
||||
Setting,
|
||||
PreferenceSetting,
|
||||
AccountSetting,
|
||||
|
||||
@@ -60,6 +60,7 @@ export async function buildUI() {
|
||||
if (build.errors.length) console.error(build.errors);
|
||||
if (build.warnings.length) console.warn(build.warnings);
|
||||
const pages = build.outputFiles.map((i) => i.text);
|
||||
console.log('ui', SettingModel, JSON.stringify(SettingModel.langs));
|
||||
const payload = [`window.LANGS=${JSON.stringify(SettingModel.langs)};`, ...pages];
|
||||
|
||||
const c = crypto.createHash('sha1');
|
||||
@@ -230,14 +231,13 @@ export function apply(ctx) {
|
||||
ctx.Route('media', '/media', RichMediaHandler);
|
||||
ctx.on('app/started', buildUI);
|
||||
ctx.on('app/started', updateLogo);
|
||||
ctx.on('system/setting', updateLogo);
|
||||
const debouncedBuildUI = debounce(buildUI, 1000);
|
||||
const triggerHotUpdate = (path) => {
|
||||
if (!path.includes('/ui-default/') && !path.includes('/public/')) return;
|
||||
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);
|
||||
ctx.on('app/watch/unlink', triggerHotUpdate);
|
||||
buildUI();
|
||||
updateLogo();
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/ui-default",
|
||||
"version": "4.41.1",
|
||||
"version": "4.41.2",
|
||||
"author": "undefined <i@undefined.moe>",
|
||||
"license": "AGPL-3.0",
|
||||
"main": "index.ts",
|
||||
|
||||
Reference in new issue
Block a user