mirror of
https://github.com/aljazceru/ditto.git
synced 2025-12-18 05:54:23 +01:00
Add PleromaConfigDB module
This commit is contained in:
29
src/utils/PleromaConfigDB.ts
Normal file
29
src/utils/PleromaConfigDB.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import type { PleromaConfig } from '@/schemas/pleroma-api.ts';
|
||||
|
||||
export class PleromaConfigDB {
|
||||
constructor(private configs: PleromaConfig[]) {
|
||||
}
|
||||
|
||||
get(group: string, key: string): PleromaConfig | undefined {
|
||||
return this.configs.find((c) => c.group === group && c.key === key);
|
||||
}
|
||||
|
||||
set(group: string, key: string, value: PleromaConfig): void {
|
||||
const index = this.configs.findIndex((c) => c.group === group && c.key === key);
|
||||
if (index === -1) {
|
||||
this.configs.push(value);
|
||||
} else {
|
||||
this.configs[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
merge(configs: PleromaConfig[]): void {
|
||||
for (const { group, key, value } of configs) {
|
||||
this.set(group, key, { group, key, value });
|
||||
}
|
||||
}
|
||||
|
||||
toJSON(): PleromaConfig[] {
|
||||
return this.configs;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user