-
Notifications
You must be signed in to change notification settings - Fork 11
/
kmq_configuration.ts
94 lines (75 loc) · 2.69 KB
/
kmq_configuration.ts
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { DataFiles } from "./constants";
import { IPCLogger } from "./logger";
import { parseJsonFileSync, pathExistsSync } from "./helpers/utils";
const logger = new IPCLogger("kmq_feature_switch");
export default class KmqConfiguration {
private static instance: KmqConfiguration | undefined;
private config: { [featureSwitch: string]: boolean };
private constructor() {
this.config = {};
}
public static get Instance(): KmqConfiguration {
if (!this.instance) {
this.instance = new this();
KmqConfiguration.reload();
}
return this.instance;
}
static reload(): void {
logger.info("Reloading feature switches...");
if (!this.instance) this.instance = new this();
if (!pathExistsSync(DataFiles.FEATURE_SWITCH_CONFIG)) {
logger.warn("Feature switch file doesn't exist, ignoring...");
return;
}
let featureSwitches: any;
try {
featureSwitches = parseJsonFileSync(
DataFiles.FEATURE_SWITCH_CONFIG,
);
} catch (e) {
logger.error(`Error reading feature switch file. err = ${e}`);
return;
}
for (const [featureSwitchName, value] of Object.entries(
featureSwitches,
)) {
if (typeof value !== "boolean") {
logger.warn(
`Attempted to read feature switch ${featureSwitchName}, invalid value ${value}`,
);
}
this.instance.config[featureSwitchName] = value as boolean;
}
}
maintenanceModeEnabled(): boolean {
return this.config["maintenanceModeEnabled"] ?? false;
}
disallowMigrations(): boolean {
return this.config["disallowMigrations"] ?? false;
}
persistMatchedPlaylistSongs(): boolean {
return this.config["persistMatchedSpotifySongs"] ?? false;
}
newsSubscriptionsEnabled(): boolean {
return this.config["newsSubscriptionEnabled"] ?? false;
}
partialChannelFetchingEnabled(): boolean {
return this.config["partialChannelFetchingEnabled"] ?? false;
}
newsGenerationEnabled(): boolean {
return this.config["newsGenerationEnabled"] ?? false;
}
ytdlpUpdatesEnabled(): boolean {
return this.config["ytdlpUpdatesEnabled"] ?? true;
}
ytdlpDownloadWithPoToken(): boolean {
return this.config["ytdlpDownloadWithPoToken"] ?? false;
}
ytdlpDownloadWithProxy(): boolean {
return this.config["ytdlpDownloadWithProxy"] ?? false;
}
downloadWithOnesieRequest(): boolean {
return this.config["downloadWithOnesieRequest"] ?? true;
}
}