fix
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user