added reader

This commit is contained in:
2025-11-27 02:11:17 +01:00
parent 76aa21ef14
commit a6c753085e
5 changed files with 1350 additions and 14 deletions

View File

@@ -31,8 +31,8 @@ async function loadExtensions() {
try {
delete require.cache[require.resolve(filePath)];
const ExtensionClass = require(filePath);
const instance = typeof ExtensionClass === 'function'
? new ExtensionClass()
const instance = typeof ExtensionClass === 'function'
? new ExtensionClass()
: (ExtensionClass.default ? new ExtensionClass.default() : null);
if (instance && (instance.type === "anime-board" || instance.type === "book-board")) {
@@ -351,7 +351,7 @@ fastify.get('/api/book/:id/chapters', async (req, reply) => {
.map(async ([name, ext]) => {
try {
console.log(`[${name}] Searching chapters for: ${searchTitle}`);
// Pass strict search options
const matches = await ext.search({
query: searchTitle,
@@ -366,7 +366,7 @@ fastify.get('/api/book/:id/chapters', async (req, reply) => {
// Use the first match to find chapters
const best = matches[0];
const chaps = await ext.findChapters(best.id);
if (chaps && chaps.length > 0) {
console.log(`[${name}] Found ${chaps.length} chapters.`);
chaps.forEach(ch => {
@@ -398,6 +398,73 @@ fastify.get('/api/book/:id/chapters', async (req, reply) => {
return { chapters: sortedChapters };
});
fastify.get('/api/book/:bookId/:chapter/:provider', async (req, reply) => {
const { bookId, chapter, provider } = req.params;
const ext = extensions.get(provider);
if (!ext)
return reply.code(404).send({ error: "Provider not found" });
let chapterId = decodeURIComponent(chapter);
let chapterTitle = null;
let chapterNumber = null;
const index = parseInt(chapter);
const chapterList = await fetch(
`http://localhost:3000/api/book/${bookId}/chapters`
).then(r => r.json());
if (!chapterList?.chapters)
return reply.code(404).send({ error: "Chapters not found" });
const providerChapters = chapterList.chapters.filter(
c => c.provider === provider
);
if (!providerChapters[index])
return reply.code(404).send({ error: "Chapter index out of range" });
const selected = providerChapters[index];
chapterId = selected.id;
chapterTitle = selected.title || null;
chapterNumber = selected.number || index;
try {
if (ext.mediaType === "manga") {
const pages = await ext.findChapterPages(chapterId);
return reply.send({
type: "manga",
chapterId,
title: chapterTitle,
number: chapterNumber,
provider,
pages
});
}
if (ext.mediaType === "ln") {
const content = await ext.findChapterPages(chapterId);
return reply.send({
type: "ln",
chapterId,
title: chapterTitle,
number: chapterNumber,
provider,
content
});
}
return reply.code(400).send({ error: "Unknown mediaType" });
} catch (err) {
console.error(err);
return reply.code(500).send({ error: "Error loading chapter" });
}
});
fastify.get('/api/book/:id', async (req, reply) => {
const id = req.params.id;
@@ -493,6 +560,11 @@ fastify.get('/api/top-airing', (req, reply) => {
return new Promise((resolve) => db.all("SELECT full_data FROM top_airing ORDER BY rank ASC LIMIT 10", [], (err, rows) => resolve({ results: rows ? rows.map(r => JSON.parse(r.full_data)) : [] })));
});
fastify.get('/read/:id/:chapter/:provider', (req, reply) => {
const stream = fs.createReadStream(path.join(__dirname, 'views', 'reader.html'));
reply.type('text/html').send(stream);
});
const start = async () => {
try {
await fastify.listen({ port: 3000, host: '0.0.0.0' });