diff --git a/desktop/src/api/extensions/extensions.controller.ts b/desktop/src/api/extensions/extensions.controller.ts index 005e0b9..e7f9b99 100644 --- a/desktop/src/api/extensions/extensions.controller.ts +++ b/desktop/src/api/extensions/extensions.controller.ts @@ -1,8 +1,6 @@ import { FastifyReply, FastifyRequest } from 'fastify'; -import { getExtension, getExtensionsList, getGalleryExtensionsMap, getBookExtensionsMap, getAnimeExtensionsMap, saveExtensionFile, deleteExtensionFile } from '../../shared/extensions'; +import { getExtension, getExtensionsList, getGalleryExtensionsMap, getBookExtensionsMap, getMangaExtensionsMap, getNovelExtensionsMap, getAnimeExtensionsMap, saveExtensionFile, deleteExtensionFile } from '../../shared/extensions'; import { ExtensionNameRequest } from '../types'; -import path from 'path'; -import fs from 'fs/promises'; const TYPE_MAP: Record = { 'anime-board': 'anime', @@ -69,6 +67,16 @@ export async function getBookExtensions(req: FastifyRequest, reply: FastifyReply return { extensions: Array.from(bookExtensions.keys()) }; } +export async function getMangaExtensions(req: FastifyRequest, reply: FastifyReply) { + const bookExtensions = getMangaExtensionsMap(); + return { extensions: Array.from(bookExtensions.keys()) }; +} + +export async function getNovelExtensions(req: FastifyRequest, reply: FastifyReply) { + const bookExtensions = getNovelExtensionsMap(); + return { extensions: Array.from(bookExtensions.keys()) }; +} + export async function getGalleryExtensions(req: FastifyRequest, reply: FastifyReply) { const galleryExtensions = getGalleryExtensionsMap(); return { extensions: Array.from(galleryExtensions.keys()) }; diff --git a/desktop/src/api/extensions/extensions.routes.ts b/desktop/src/api/extensions/extensions.routes.ts index 5720792..bb68bfa 100644 --- a/desktop/src/api/extensions/extensions.routes.ts +++ b/desktop/src/api/extensions/extensions.routes.ts @@ -6,6 +6,8 @@ async function extensionsRoutes(fastify: FastifyInstance) { fastify.get('/extensions/anime', controller.getAnimeExtensions); fastify.post('/extensions/update', controller.updateExtensions); fastify.get('/extensions/book', controller.getBookExtensions); + fastify.get('/extensions/manga', controller.getMangaExtensions); + fastify.get('/extensions/novel', controller.getNovelExtensions); fastify.get('/extensions/gallery', controller.getGalleryExtensions); fastify.get('/extensions/:name/settings', controller.getExtensionSettings); fastify.post('/extensions/install', controller.installExtension); diff --git a/desktop/src/scripts/books/book.js b/desktop/src/scripts/books/book.js index e7c6aee..4b07b18 100644 --- a/desktop/src/scripts/books/book.js +++ b/desktop/src/scripts/books/book.js @@ -499,11 +499,18 @@ async function checkLocalLibraryEntry() { async function loadAvailableExtensions() { try { - const res = await fetch('/api/extensions/book'); + if (!bookData?.entry_type) return; + console.log(bookData.entry_type) + + const type = bookData.entry_type === 'MANGA' ? 'manga' : 'novel'; + const res = await fetch(`/api/extensions/${type}`); const data = await res.json(); + availableExtensions = data.extensions || []; setupProviderFilter(); - } catch (err) { console.error(err); } + } catch (err) { + console.error(err); + } } function setupProviderFilter() { diff --git a/desktop/src/scripts/settings.js b/desktop/src/scripts/settings.js index c160c61..c55ec0e 100644 --- a/desktop/src/scripts/settings.js +++ b/desktop/src/scripts/settings.js @@ -1,4 +1,4 @@ -const API_BASE = '/api/config'; +const API_BASE2 = '/api/config'; let currentConfig = {}; let currentSchema = {}; let activeSection = ''; @@ -38,7 +38,7 @@ async function loadSettings() { `; try { - const res = await fetch(API_BASE); + const res = await fetch(API_BASE2); if (!res.ok) throw new Error(`HTTP error! status: ${res.status}`); const data = await res.json(); @@ -172,7 +172,7 @@ async function saveSettings() { }); try { - const res = await fetch(`${API_BASE}/${activeSection}`, { + const res = await fetch(`${API_BASE2}/${activeSection}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(updatedData) diff --git a/desktop/src/shared/extensions.js b/desktop/src/shared/extensions.js index 7704896..aff07cf 100644 --- a/desktop/src/shared/extensions.js +++ b/desktop/src/shared/extensions.js @@ -194,6 +194,26 @@ function getBookExtensionsMap() { return bookExts; } +function getMangaExtensionsMap() { + const mangaExts = new Map(); + for (const [name, ext] of extensions) { + if (ext.type === 'book-board' && ext.mediaType !== 'ln') { + mangaExts.set(name, ext); + } + } + return mangaExts; +} + +function getNovelExtensionsMap() { + const novelExts = new Map(); + for (const [name, ext] of extensions) { + if (ext.type === 'book-board' && ext.mediaType === 'ln') { + novelExts.set(name, ext); + } + } + return novelExts; +} + function getGalleryExtensionsMap() { const galleryExts = new Map(); for (const [name, ext] of extensions) { @@ -213,5 +233,7 @@ module.exports = { getBookExtensionsMap, getGalleryExtensionsMap, saveExtensionFile, - deleteExtensionFile + deleteExtensionFile, + getMangaExtensionsMap, + getNovelExtensionsMap }; \ No newline at end of file diff --git a/docker/src/api/extensions/extensions.controller.ts b/docker/src/api/extensions/extensions.controller.ts index 005e0b9..e7f9b99 100644 --- a/docker/src/api/extensions/extensions.controller.ts +++ b/docker/src/api/extensions/extensions.controller.ts @@ -1,8 +1,6 @@ import { FastifyReply, FastifyRequest } from 'fastify'; -import { getExtension, getExtensionsList, getGalleryExtensionsMap, getBookExtensionsMap, getAnimeExtensionsMap, saveExtensionFile, deleteExtensionFile } from '../../shared/extensions'; +import { getExtension, getExtensionsList, getGalleryExtensionsMap, getBookExtensionsMap, getMangaExtensionsMap, getNovelExtensionsMap, getAnimeExtensionsMap, saveExtensionFile, deleteExtensionFile } from '../../shared/extensions'; import { ExtensionNameRequest } from '../types'; -import path from 'path'; -import fs from 'fs/promises'; const TYPE_MAP: Record = { 'anime-board': 'anime', @@ -69,6 +67,16 @@ export async function getBookExtensions(req: FastifyRequest, reply: FastifyReply return { extensions: Array.from(bookExtensions.keys()) }; } +export async function getMangaExtensions(req: FastifyRequest, reply: FastifyReply) { + const bookExtensions = getMangaExtensionsMap(); + return { extensions: Array.from(bookExtensions.keys()) }; +} + +export async function getNovelExtensions(req: FastifyRequest, reply: FastifyReply) { + const bookExtensions = getNovelExtensionsMap(); + return { extensions: Array.from(bookExtensions.keys()) }; +} + export async function getGalleryExtensions(req: FastifyRequest, reply: FastifyReply) { const galleryExtensions = getGalleryExtensionsMap(); return { extensions: Array.from(galleryExtensions.keys()) }; diff --git a/docker/src/api/extensions/extensions.routes.ts b/docker/src/api/extensions/extensions.routes.ts index 5720792..bb68bfa 100644 --- a/docker/src/api/extensions/extensions.routes.ts +++ b/docker/src/api/extensions/extensions.routes.ts @@ -6,6 +6,8 @@ async function extensionsRoutes(fastify: FastifyInstance) { fastify.get('/extensions/anime', controller.getAnimeExtensions); fastify.post('/extensions/update', controller.updateExtensions); fastify.get('/extensions/book', controller.getBookExtensions); + fastify.get('/extensions/manga', controller.getMangaExtensions); + fastify.get('/extensions/novel', controller.getNovelExtensions); fastify.get('/extensions/gallery', controller.getGalleryExtensions); fastify.get('/extensions/:name/settings', controller.getExtensionSettings); fastify.post('/extensions/install', controller.installExtension); diff --git a/docker/src/scripts/books/book.js b/docker/src/scripts/books/book.js index e7c6aee..4b07b18 100644 --- a/docker/src/scripts/books/book.js +++ b/docker/src/scripts/books/book.js @@ -499,11 +499,18 @@ async function checkLocalLibraryEntry() { async function loadAvailableExtensions() { try { - const res = await fetch('/api/extensions/book'); + if (!bookData?.entry_type) return; + console.log(bookData.entry_type) + + const type = bookData.entry_type === 'MANGA' ? 'manga' : 'novel'; + const res = await fetch(`/api/extensions/${type}`); const data = await res.json(); + availableExtensions = data.extensions || []; setupProviderFilter(); - } catch (err) { console.error(err); } + } catch (err) { + console.error(err); + } } function setupProviderFilter() { diff --git a/docker/src/scripts/settings.js b/docker/src/scripts/settings.js index c160c61..c55ec0e 100644 --- a/docker/src/scripts/settings.js +++ b/docker/src/scripts/settings.js @@ -1,4 +1,4 @@ -const API_BASE = '/api/config'; +const API_BASE2 = '/api/config'; let currentConfig = {}; let currentSchema = {}; let activeSection = ''; @@ -38,7 +38,7 @@ async function loadSettings() { `; try { - const res = await fetch(API_BASE); + const res = await fetch(API_BASE2); if (!res.ok) throw new Error(`HTTP error! status: ${res.status}`); const data = await res.json(); @@ -172,7 +172,7 @@ async function saveSettings() { }); try { - const res = await fetch(`${API_BASE}/${activeSection}`, { + const res = await fetch(`${API_BASE2}/${activeSection}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(updatedData) diff --git a/docker/src/shared/extensions.js b/docker/src/shared/extensions.js index 7704896..aff07cf 100644 --- a/docker/src/shared/extensions.js +++ b/docker/src/shared/extensions.js @@ -194,6 +194,26 @@ function getBookExtensionsMap() { return bookExts; } +function getMangaExtensionsMap() { + const mangaExts = new Map(); + for (const [name, ext] of extensions) { + if (ext.type === 'book-board' && ext.mediaType !== 'ln') { + mangaExts.set(name, ext); + } + } + return mangaExts; +} + +function getNovelExtensionsMap() { + const novelExts = new Map(); + for (const [name, ext] of extensions) { + if (ext.type === 'book-board' && ext.mediaType === 'ln') { + novelExts.set(name, ext); + } + } + return novelExts; +} + function getGalleryExtensionsMap() { const galleryExts = new Map(); for (const [name, ext] of extensions) { @@ -213,5 +233,7 @@ module.exports = { getBookExtensionsMap, getGalleryExtensionsMap, saveExtensionFile, - deleteExtensionFile + deleteExtensionFile, + getMangaExtensionsMap, + getNovelExtensionsMap }; \ No newline at end of file