refacto(db): get config from mongo everywhere

This commit is contained in:
Julien Froidefond
2025-02-14 14:35:40 +01:00
parent 1f881ade26
commit 6b3866e54d
2 changed files with 24 additions and 20 deletions

View File

@@ -1,15 +1,26 @@
import { cookies } from "next/headers";
import { AuthConfig } from "@/types/auth";
import { serverCacheService } from "./server-cache.service";
import { komgaConfigService } from "./komga-config.service";
import { ConfigDBService } from "./config-db.service";
// Types de cache disponibles
export type CacheType = "DEFAULT" | "HOME" | "LIBRARIES" | "SERIES" | "BOOKS" | "IMAGES";
export abstract class BaseApiService {
protected static async getKomgaConfig(): Promise<AuthConfig> {
const cookiesStore = cookies();
return komgaConfigService.validateAndGetConfig(cookiesStore);
try {
const config = await ConfigDBService.getConfig();
return {
serverUrl: config.url,
credentials: {
username: config.username,
password: config.password,
},
};
} catch (error) {
console.error("Erreur lors de la récupération de la configuration:", error);
throw new Error("Configuration Komga non trouvée");
}
}
protected static getAuthHeaders(config: AuthConfig): Headers {