core: drop array-style problem content (#882)

This commit is contained in:
undefined authored and GitHub committed 2024-10-06 23:12:16 +08:00
1 parent 23dfcbeeae
commit 6ae902d3ca
9 files changed
+120 -180

No files matched your search

+3 -7
View File
@@ -1,8 +1,7 @@
import * as status from '@hydrooj/utils/lib/status';
import { findFileSync } from '@hydrooj/utils/lib/utils';
import {
avatar, buildContent, Context,
fs, PERM, PRIV, STATUS, yaml,
avatar, Context, fs, PERM, PRIV, STATUS, yaml,
} from 'hydrooj';
import jsesc from 'jsesc';
import nunjucks from 'nunjucks';
@@ -86,14 +85,13 @@ class Nunjucks extends nunjucks.Environment {
} catch {
s = content;
}
if (typeof s === 'object' && !(s instanceof Array)) {
if (typeof s === 'object') {
const langs = Object.keys(s);
const f = langs.filter((i) => i.startsWith(language));
if (s[language]) s = s[language];
else if (f.length) s = s[f[0]];
else s = s[langs[0]];
}
if (s instanceof Array) s = buildContent(s, html ? 'html' : 'markdown', (str) => str.translate(language));
return ensureTag(html ? xss.process(s) : markdown.render(s));
});
this.addFilter('contentLang', (content) => {
@@ -103,9 +101,7 @@ class Nunjucks extends nunjucks.Environment {
} catch {
s = content;
}
if (typeof s === 'object' && !(s instanceof Array)) {
return Object.keys(s);
}
if (typeof s === 'object') return Object.keys(s);
return [];
});
this.addFilter('log', (self) => {