mirror of
https://github.com/aljazceru/ditto.git
synced 2025-12-17 05:24:22 +01:00
30 lines
771 B
TypeScript
30 lines
771 B
TypeScript
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;
|
|
}
|
|
}
|