feat: add multi-provider support (Komga + Stripstream Librarian)
Some checks failed
Deploy with Docker Compose / deploy (push) Has been cancelled
Some checks failed
Deploy with Docker Compose / deploy (push) Has been cancelled
- Introduce provider abstraction layer (IMediaProvider, KomgaProvider, StripstreamProvider) - Add Stripstream Librarian as second media provider with full feature parity - Migrate all pages and components from direct Komga services to provider factory - Remove dead service code (BaseApiService, HomeService, LibraryService, SearchService, TestService) - Fix library/series page-based pagination for both providers (Komga 0-indexed, Stripstream 1-indexed) - Fix unread filter and search on library page for both providers - Fix read progress display for Stripstream (reading_status mapping) - Fix series read status (books_read_count) for Stripstream - Add global search with series results for Stripstream (series_hits from Meilisearch) - Fix thumbnail proxy to return 404 gracefully instead of JSON on upstream error - Replace duration-based cache debug detection with x-nextjs-cache header Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
52
src/lib/providers/provider.factory.ts
Normal file
52
src/lib/providers/provider.factory.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { getCurrentUser } from "@/lib/auth-utils";
|
||||
import type { IMediaProvider } from "./provider.interface";
|
||||
|
||||
export async function getProvider(): Promise<IMediaProvider | null> {
|
||||
const user = await getCurrentUser();
|
||||
if (!user) return null;
|
||||
|
||||
const userId = parseInt(user.id, 10);
|
||||
|
||||
const dbUser = await prisma.user.findUnique({
|
||||
where: { id: userId },
|
||||
select: {
|
||||
activeProvider: true,
|
||||
config: { select: { url: true, authHeader: true } },
|
||||
stripstreamConfig: { select: { url: true, token: true } },
|
||||
},
|
||||
});
|
||||
|
||||
if (!dbUser) return null;
|
||||
|
||||
const activeProvider = dbUser.activeProvider ?? "komga";
|
||||
|
||||
if (activeProvider === "stripstream" && dbUser.stripstreamConfig) {
|
||||
const { StripstreamProvider } = await import("./stripstream/stripstream.provider");
|
||||
return new StripstreamProvider(
|
||||
dbUser.stripstreamConfig.url,
|
||||
dbUser.stripstreamConfig.token
|
||||
);
|
||||
}
|
||||
|
||||
if (activeProvider === "komga" || !dbUser.activeProvider) {
|
||||
if (!dbUser.config) return null;
|
||||
const { KomgaProvider } = await import("./komga/komga.provider");
|
||||
return new KomgaProvider(dbUser.config.url, dbUser.config.authHeader);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function getActiveProviderType(): Promise<string | null> {
|
||||
const user = await getCurrentUser();
|
||||
if (!user) return null;
|
||||
|
||||
const userId = parseInt(user.id, 10);
|
||||
const dbUser = await prisma.user.findUnique({
|
||||
where: { id: userId },
|
||||
select: { activeProvider: true },
|
||||
});
|
||||
|
||||
return dbUser?.activeProvider ?? "komga";
|
||||
}
|
||||
Reference in New Issue
Block a user