MCPcopy Create free account
hub / github.com/hydro-dev/Hydro / apply

Function apply

packages/hydrooj/src/model/setting.ts:381–411  ·  view source on GitHub ↗
(ctx: Context)

Source from the content-addressed store, hash-verified

379
380export const inject = ['db'];
381export async function apply(ctx: Context) {
382 logger.info('Ensuring settings');
383 for (const lang in global.Hydro.locales) {
384 if (!global.Hydro.locales[lang].__interface) continue;
385 langRange[lang] = global.Hydro.locales[lang].__langname;
386 }
387 const system = global.Hydro.model.system;
388 for (const setting of SYSTEM_SETTINGS) {
389 if (!setting.value) continue;
390 const current = await ctx.db.collection('system').findOne({ _id: setting.key });
391 if (!current || current.value == null || current.value === '') {
392 await system.set(setting.key, setting.value);
393 }
394 }
395 try {
396 Object.assign(langs, parseLang(system.get('hydrooj.langs')));
397 const range = {};
398 for (const key in langs) range[key] = langs[key].display;
399 LangSettingNode.range = range;
400 ServerLangSettingNode.range = range;
401 } catch (e) { /* Ignore */ }
402 ctx.on('system/setting', (args) => {
403 if (!args.hydrooj?.langs) return;
404 Object.assign(langs, parseLang(args.hydrooj.langs));
405 const range = {};
406 for (const key in langs) range[key] = langs[key].display;
407 LangSettingNode.range = range;
408 ServerLangSettingNode.range = range;
409 });
410 ctx.emit('system/setting-loaded');
411}
412
413global.Hydro.model.setting = {
414 apply,

Callers

nothing calls this directly

Calls 6

parseLangFunction · 0.90
collectionMethod · 0.80
infoMethod · 0.45
setMethod · 0.45
getMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected