Spaces:
Build error
Build error
File size: 1,838 Bytes
0bfe2e3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
import { UserData } from '../db/schemas';
import { Env } from './env';
const DEFAULT_REASON = 'Disabled by owner of the instance';
export class FeatureControl {
private static readonly _disabledHosts: Map<string, string> = (() => {
const map = new Map<string, string>();
if (Env.DISABLED_HOSTS) {
for (const disabledHost of Env.DISABLED_HOSTS.split(',')) {
const [host, reason] = disabledHost.split(':');
map.set(host, reason || DEFAULT_REASON);
}
}
return map;
})();
private static readonly _disabledAddons: Map<string, string> = (() => {
const map = new Map<string, string>();
if (Env.DISABLED_ADDONS) {
for (const disabledAddon of Env.DISABLED_ADDONS.split(',')) {
const [addon, reason] = disabledAddon.split(':');
map.set(addon, reason || DEFAULT_REASON);
}
}
return map;
})();
private static readonly _disabledServices: Map<string, string> = (() => {
const map = new Map<string, string>();
if (Env.DISABLED_SERVICES) {
for (const disabledService of Env.DISABLED_SERVICES.split(',')) {
const [service, reason] = disabledService.split(':');
map.set(service, reason || DEFAULT_REASON);
}
}
return map;
})();
public static readonly regexFilterAccess: 'none' | 'trusted' | 'all' =
Env.REGEX_FILTER_ACCESS;
public static get disabledHosts() {
return this._disabledHosts;
}
public static get disabledAddons() {
return this._disabledAddons;
}
public static get disabledServices() {
return this._disabledServices;
}
public static isRegexAllowed(userData: UserData) {
switch (this.regexFilterAccess) {
case 'trusted':
return userData.trusted ?? false;
case 'all':
return true;
default:
return false;
}
}
}
|