fix
This commit is contained in:
@@ -230,8 +230,21 @@ async function getAnimeInfoExtension(ext, id) {
|
||||
try {
|
||||
const match = await ext.getMetadata(id);
|
||||
if (match) {
|
||||
await (0, queries_1.cacheExtension)(extName, id, match.title, match);
|
||||
return match;
|
||||
const normalized = {
|
||||
title: match.title ?? "Unknown",
|
||||
summary: match.summary ?? "No summary available",
|
||||
episodes: Number(match.episodes) || 0,
|
||||
characters: Array.isArray(match.characters) ? match.characters : [],
|
||||
season: match.season ?? null,
|
||||
status: match.status ?? "Unknown",
|
||||
studio: match.studio ?? "Unknown",
|
||||
score: Number(match.score) || 0,
|
||||
year: match.year ?? null,
|
||||
genres: Array.isArray(match.genres) ? match.genres : [],
|
||||
image: match.image ?? ""
|
||||
};
|
||||
await (0, queries_1.cacheExtension)(extName, id, normalized.title, normalized);
|
||||
return normalized;
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
|
||||
@@ -226,15 +226,26 @@ async function getBookInfoExtension(ext, id) {
|
||||
try {
|
||||
return JSON.parse(cached.metadata);
|
||||
}
|
||||
catch {
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
if (ext.type === 'book-board' && ext.getMetadata) {
|
||||
try {
|
||||
const info = await ext.getMetadata(id);
|
||||
if (info) {
|
||||
await (0, queries_1.cacheExtension)(extName, id, info.title, info);
|
||||
return info;
|
||||
const normalized = {
|
||||
id: info.id ?? id,
|
||||
title: info.title ?? "",
|
||||
format: info.format ?? "",
|
||||
score: typeof info.score === "number" ? info.score : null,
|
||||
genres: Array.isArray(info.genres) ? info.genres : [],
|
||||
status: info.status ?? "",
|
||||
published: info.published ?? "",
|
||||
summary: info.summary ?? "",
|
||||
chapters: Number.isFinite(info.chapters) ? info.chapters : 1,
|
||||
image: typeof info.image === "string" ? info.image : ""
|
||||
};
|
||||
await (0, queries_1.cacheExtension)(extName, id, normalized.title, normalized);
|
||||
return [normalized];
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
|
||||
@@ -33,7 +33,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.search = search;
|
||||
exports.searchInExtension = searchInExtension;
|
||||
exports.getInfo = getInfo;
|
||||
exports.getFavorites = getFavorites;
|
||||
@@ -41,24 +40,6 @@ exports.getFavoriteById = getFavoriteById;
|
||||
exports.addFavorite = addFavorite;
|
||||
exports.removeFavorite = removeFavorite;
|
||||
const galleryService = __importStar(require("./gallery.service"));
|
||||
async function search(req, reply) {
|
||||
try {
|
||||
const query = req.query.q || '';
|
||||
const page = parseInt(req.query.page) || 1;
|
||||
const perPage = parseInt(req.query.perPage) || 48;
|
||||
return await galleryService.searchGallery(query, page, perPage);
|
||||
}
|
||||
catch (err) {
|
||||
const error = err;
|
||||
console.error("Gallery Search Error:", error.message);
|
||||
return {
|
||||
results: [],
|
||||
total: 0,
|
||||
page: 1,
|
||||
hasNextPage: false
|
||||
};
|
||||
}
|
||||
}
|
||||
async function searchInExtension(req, reply) {
|
||||
try {
|
||||
const provider = req.query.provider;
|
||||
|
||||
@@ -35,7 +35,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const controller = __importStar(require("./gallery.controller"));
|
||||
async function galleryRoutes(fastify) {
|
||||
fastify.get('/gallery/search', controller.search);
|
||||
fastify.get('/gallery/fetch/:id', controller.getInfo);
|
||||
fastify.get('/gallery/search/provider', controller.searchInExtension);
|
||||
fastify.get('/gallery/favorites', controller.getFavorites);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.searchGallery = searchGallery;
|
||||
exports.getGalleryInfo = getGalleryInfo;
|
||||
exports.searchInExtension = searchInExtension;
|
||||
exports.getFavorites = getFavorites;
|
||||
@@ -9,26 +8,6 @@ exports.addFavorite = addFavorite;
|
||||
exports.removeFavorite = removeFavorite;
|
||||
const extensions_1 = require("../../shared/extensions");
|
||||
const database_1 = require("../../shared/database");
|
||||
async function searchGallery(query, page = 1, perPage = 48) {
|
||||
const extensions = (0, extensions_1.getAllExtensions)();
|
||||
for (const [name, ext] of extensions) {
|
||||
if (ext.type === 'image-board' && ext.search) {
|
||||
const result = await searchInExtension(name, query, page, perPage);
|
||||
if (result.results.length > 0) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
total: 0,
|
||||
next: 0,
|
||||
previous: 0,
|
||||
pages: 0,
|
||||
page,
|
||||
hasNextPage: false,
|
||||
results: []
|
||||
};
|
||||
}
|
||||
async function getGalleryInfo(id, providerName) {
|
||||
const extensions = (0, extensions_1.getAllExtensions)();
|
||||
if (providerName) {
|
||||
@@ -38,8 +17,12 @@ async function getGalleryInfo(id, providerName) {
|
||||
console.log(`[Gallery] Getting info from ${providerName} for: ${id}`);
|
||||
const info = await ext.getInfo(id);
|
||||
return {
|
||||
...info,
|
||||
provider: providerName
|
||||
id: info.id ?? id,
|
||||
provider: providerName,
|
||||
image: info.image,
|
||||
tags: info.tags,
|
||||
title: info.title,
|
||||
headers: info.headers
|
||||
};
|
||||
}
|
||||
catch (e) {
|
||||
@@ -69,19 +52,21 @@ async function getGalleryInfo(id, providerName) {
|
||||
}
|
||||
async function searchInExtension(providerName, query, page = 1, perPage = 48) {
|
||||
const ext = (0, extensions_1.getExtension)(providerName);
|
||||
if (!ext || ext.type !== 'image-board' || !ext.search) {
|
||||
throw new Error(`La extensión "${providerName}" no existe o no soporta búsqueda.`);
|
||||
}
|
||||
try {
|
||||
console.log(`[Gallery] Searching ONLY in ${providerName} for: ${query}`);
|
||||
const results = await ext.search(query, page, perPage);
|
||||
const enrichedResults = (results?.results ?? []).map((r) => ({
|
||||
...r,
|
||||
const normalizedResults = (results?.results ?? []).map((r) => ({
|
||||
id: r.id,
|
||||
image: r.image,
|
||||
tags: r.tags,
|
||||
title: r.title,
|
||||
headers: r.headers,
|
||||
provider: providerName
|
||||
}));
|
||||
return {
|
||||
...results,
|
||||
results: enrichedResults
|
||||
page: results.page ?? page,
|
||||
hasNextPage: !!results.hasNextPage,
|
||||
results: normalizedResults
|
||||
};
|
||||
}
|
||||
catch (e) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
const cheerio = require("cheerio");
|
||||
const { queryAll, run } = require('./database');
|
||||
const { scrape } = require("./headless");
|
||||
const extensions = new Map();
|
||||
@@ -62,6 +63,7 @@ async function loadExtension(fileName) {
|
||||
}
|
||||
const name = instance.constructor.name;
|
||||
instance.scrape = scrape;
|
||||
instance.cheerio = cheerio;
|
||||
extensions.set(name, instance);
|
||||
console.log(`📦 Installed & loaded: ${name}`);
|
||||
return name;
|
||||
|
||||
@@ -23,7 +23,6 @@ async function initHeadless() {
|
||||
"--mute-audio",
|
||||
"--no-first-run",
|
||||
"--no-zygote",
|
||||
"--single-process"
|
||||
]
|
||||
});
|
||||
context = await browser.newContext({
|
||||
|
||||
Reference in New Issue
Block a user