mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: prohibit rtl characters in displayName
This commit is contained in:
4 files changed
+32
-18
No files matched your search
@@ -24,7 +24,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/fs-extra": "^11.0.4",
|
"@types/fs-extra": "^11.0.4",
|
||||||
"@types/koa": "^2.15.0",
|
"@types/koa": "^3.0.0",
|
||||||
"@types/koa-compress": "^4.0.6",
|
"@types/koa-compress": "^4.0.6",
|
||||||
"@types/koa__router": "^12.0.4",
|
"@types/koa__router": "^12.0.4",
|
||||||
"@types/saslprep": "^1.0.3",
|
"@types/saslprep": "^1.0.3",
|
||||||
|
|||||||
@@ -366,6 +366,7 @@ function set(s: Setting, key: string, value: any) {
|
|||||||
if (s.family === 'setting_storage') return undefined;
|
if (s.family === 'setting_storage') return undefined;
|
||||||
if (s.flag & setting.FLAG_DISABLED) return undefined;
|
if (s.flag & setting.FLAG_DISABLED) return undefined;
|
||||||
if ((s.flag & setting.FLAG_SECRET) && !value) return undefined;
|
if ((s.flag & setting.FLAG_SECRET) && !value) return undefined;
|
||||||
|
if (s.validation && !s.validation(value)) throw new ValidationError(key);
|
||||||
if (s.type === 'boolean') {
|
if (s.type === 'boolean') {
|
||||||
if (value === 'on') return true;
|
if (value === 'on') return true;
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ export interface Setting {
|
|||||||
name: string;
|
name: string;
|
||||||
desc: string;
|
desc: string;
|
||||||
flag: number;
|
flag: number;
|
||||||
|
validation?: (val: any) => boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Authenticator {
|
export interface Authenticator {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import fs from 'fs';
|
|||||||
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 saslPrep from 'saslprep';
|
||||||
import Schema from 'schemastery';
|
import Schema from 'schemastery';
|
||||||
import { LangConfig, parseLang } from '@hydrooj/common';
|
import { LangConfig, parseLang } from '@hydrooj/common';
|
||||||
import { findFileSync, randomstring, retry } from '@hydrooj/utils';
|
import { findFileSync, randomstring, retry } from '@hydrooj/utils';
|
||||||
@@ -47,6 +48,7 @@ export type SettingType = 'text' | 'yaml' | 'number' | 'float' | 'markdown' | 'p
|
|||||||
export const Setting = (
|
export const Setting = (
|
||||||
family: string, key: string, value: any = null,
|
family: string, key: string, value: any = null,
|
||||||
type: SettingType = 'text', name = '', desc = '', flag = 0,
|
type: SettingType = 'text', name = '', desc = '', flag = 0,
|
||||||
|
validation?: (val: any) => boolean,
|
||||||
): _Setting => {
|
): _Setting => {
|
||||||
let subType = '';
|
let subType = '';
|
||||||
if (type === 'yaml' && typeof value !== 'string') {
|
if (type === 'yaml' && typeof value !== 'string') {
|
||||||
@@ -64,6 +66,7 @@ export const Setting = (
|
|||||||
subType,
|
subType,
|
||||||
type: typeof type === 'object' ? 'select' : type,
|
type: typeof type === 'object' ? 'select' : type,
|
||||||
range: typeof type === 'object' ? type : null,
|
range: typeof type === 'object' ? type : null,
|
||||||
|
validation,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -82,13 +85,16 @@ function schemaToSettings(schema: Schema<any>) {
|
|||||||
if (s.dict) throw new Error('Dict is not supported here');
|
if (s.dict) throw new Error('Dict is not supported here');
|
||||||
let flag = (s.meta?.hidden ? FLAG_HIDDEN : 0)
|
let flag = (s.meta?.hidden ? FLAG_HIDDEN : 0)
|
||||||
| (s.meta?.disabled ? FLAG_DISABLED : 0);
|
| (s.meta?.disabled ? FLAG_DISABLED : 0);
|
||||||
const type = s.type === 'number' ? 'number'
|
const actualType = s.type === 'transform' ? s.inner.type : s.type;
|
||||||
: s.type === 'boolean' ? 'boolean'
|
const actualList = s.type === 'transform' ? s.inner.list : s.list;
|
||||||
|
const type = actualType === 'any' ? 'json'
|
||||||
|
: actualType === 'number' ? 'number'
|
||||||
|
: actualType === 'boolean' ? 'boolean'
|
||||||
: s.meta?.role === 'markdown' ? 'markdown'
|
: s.meta?.role === 'markdown' ? 'markdown'
|
||||||
: s.meta?.role === 'textarea' ? 'textarea' : 'text';
|
: s.meta?.role === 'textarea' ? 'textarea' : 'text';
|
||||||
if (s.meta?.role === 'password') flag |= FLAG_SECRET;
|
if (s.meta?.role === 'password') flag |= FLAG_SECRET;
|
||||||
const options = {};
|
const options = {};
|
||||||
for (const item of s.list || []) {
|
for (const item of actualList || []) {
|
||||||
if (item.type !== 'const') throw new Error('List item must be a constant');
|
if (item.type !== 'const') throw new Error('List item must be a constant');
|
||||||
options[item.value] = item.meta?.description || item.value;
|
options[item.value] = item.meta?.description || item.value;
|
||||||
}
|
}
|
||||||
@@ -100,8 +106,16 @@ function schemaToSettings(schema: Schema<any>) {
|
|||||||
desc: s.meta?.description,
|
desc: s.meta?.description,
|
||||||
flag,
|
flag,
|
||||||
subType: '',
|
subType: '',
|
||||||
type: s.list ? 'select' : type,
|
type: actualList ? 'select' : type,
|
||||||
range: s.list ? options : null,
|
range: actualList ? options : null,
|
||||||
|
validation: (v) => {
|
||||||
|
try {
|
||||||
|
(s as any)(v);
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
} as _Setting;
|
} as _Setting;
|
||||||
};
|
};
|
||||||
if (!schema.dict) return [];
|
if (!schema.dict) return [];
|
||||||
@@ -263,18 +277,16 @@ DomainSetting(
|
|||||||
Setting('setting_storage', 'host', '', 'text', 'Custom host', null, FLAG_HIDDEN | FLAG_DISABLED),
|
Setting('setting_storage', 'host', '', 'text', 'Custom host', null, FLAG_HIDDEN | FLAG_DISABLED),
|
||||||
);
|
);
|
||||||
|
|
||||||
DomainUserSetting(
|
DomainUserSetting(Schema.object({
|
||||||
Setting('setting_info', 'displayName', '', 'text', 'Display Name'),
|
displayName: Schema.transform(String, (input) => saslPrep(input)).default('').description('Display Name').extra('family', 'setting_info'),
|
||||||
Setting('setting_storage', 'nAccept', 0, 'number', 'nAccept', null, FLAG_HIDDEN | FLAG_DISABLED),
|
|
||||||
Setting('setting_storage', 'nSubmit', 0, 'number', 'nSubmit', null, FLAG_HIDDEN | FLAG_DISABLED),
|
rpInfo: Schema.any().extra('family', 'setting_storage').disabled().hidden(),
|
||||||
Setting('setting_storage', 'nLike', 0, 'number', 'nLike', null, FLAG_HIDDEN | FLAG_DISABLED),
|
|
||||||
Setting('setting_storage', 'rp', 0, 'number', 'RP', null, FLAG_HIDDEN | FLAG_DISABLED),
|
...Object.fromEntries(['nAccept', 'nSubmit', 'nLike', 'rp', 'rpdelta', 'rank', 'level', 'join'].map((i) => ([
|
||||||
Setting('setting_storage', 'rpInfo', {}, 'json', 'RP Detail', null, FLAG_HIDDEN | FLAG_DISABLED),
|
i, Schema.number().default(0).extra('family', 'setting_storage').disabled().hidden(),
|
||||||
Setting('setting_storage', 'rpdelta', 0, 'number', 'RP.delta', null, FLAG_HIDDEN | FLAG_DISABLED),
|
]))),
|
||||||
Setting('setting_storage', 'rank', 0, 'number', 'Rank', null, FLAG_DISABLED | FLAG_HIDDEN),
|
|
||||||
Setting('setting_storage', 'level', 0, 'number', 'level', null, FLAG_HIDDEN | FLAG_DISABLED),
|
}));
|
||||||
Setting('setting_storage', 'join', 0, 'number', 'join', null, FLAG_HIDDEN | FLAG_DISABLED),
|
|
||||||
);
|
|
||||||
|
|
||||||
const ignoreUA = [
|
const ignoreUA = [
|
||||||
'bingbot',
|
'bingbot',
|
||||||
|
|||||||
Reference in new issue
Block a user