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