little improvement on book api
This commit is contained in:
@@ -145,8 +145,11 @@ export async function searchBooksInExtension(ext: Extension | null, name: string
|
|||||||
if (!ext) return [];
|
if (!ext) return [];
|
||||||
|
|
||||||
if ((ext.type === 'book-board') && ext.search) {
|
if ((ext.type === 'book-board') && ext.search) {
|
||||||
|
const start = performance.now();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log(`[${name}] Searching for book: ${query}`);
|
console.log(`[${name}] Searching for book: ${query}`);
|
||||||
|
|
||||||
const matches = await ext.search({
|
const matches = await ext.search({
|
||||||
query: query,
|
query: query,
|
||||||
media: {
|
media: {
|
||||||
@@ -156,7 +159,16 @@ export async function searchBooksInExtension(ext: Extension | null, name: string
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (matches && matches.length > 0) {
|
const end = performance.now();
|
||||||
|
console.log(`[${name}] Search time: ${(end - start).toFixed(2)} ms`);
|
||||||
|
console.log(`[${name}] Search time: ${(end - start).toFixed(2)} ms`);
|
||||||
|
console.log(`[${name}] Search time: ${(end - start).toFixed(2)} ms`);
|
||||||
|
console.log(`[${name}] Search time: ${(end - start).toFixed(2)} ms`);
|
||||||
|
console.log(`[${name}] Search time: ${(end - start).toFixed(2)} ms`);
|
||||||
|
console.log(`[${name}] Search time: ${(end - start).toFixed(2)} ms`);
|
||||||
|
console.log(`[${name}] Search time: ${(end - start).toFixed(2)} ms`);
|
||||||
|
|
||||||
|
if (matches?.length) {
|
||||||
return matches.map(m => ({
|
return matches.map(m => ({
|
||||||
id: m.id,
|
id: m.id,
|
||||||
extensionName: name,
|
extensionName: name,
|
||||||
@@ -168,6 +180,7 @@ export async function searchBooksInExtension(ext: Extension | null, name: string
|
|||||||
isExtensionResult: true
|
isExtensionResult: true
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`Extension search failed for ${name}:`, e);
|
console.error(`Extension search failed for ${name}:`, e);
|
||||||
}
|
}
|
||||||
@@ -269,7 +282,7 @@ async function searchChaptersInExtension(ext: Extension, name: string, searchTit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getChaptersForBook(id: string, ext: Boolean): Promise<{ chapters: ChapterWithProvider[] }> {
|
export async function getChaptersForBook(id: string, ext: Boolean, onlyProvider?: string): Promise<{ chapters: ChapterWithProvider[] }> {
|
||||||
let bookData: Book | null = null;
|
let bookData: Book | null = null;
|
||||||
let searchTitle: string = "";
|
let searchTitle: string = "";
|
||||||
|
|
||||||
@@ -298,6 +311,7 @@ export async function getChaptersForBook(id: string, ext: Boolean): Promise<{ ch
|
|||||||
if (ext) exts = "ext";
|
if (ext) exts = "ext";
|
||||||
|
|
||||||
for (const [name, ext] of bookExtensions) {
|
for (const [name, ext] of bookExtensions) {
|
||||||
|
if (onlyProvider && name !== onlyProvider) continue;
|
||||||
if (name == extension) {
|
if (name == extension) {
|
||||||
const chapters = await searchChaptersInExtension(ext, name, id, false, exts);
|
const chapters = await searchChaptersInExtension(ext, name, id, false, exts);
|
||||||
allChapters.push(...chapters);
|
allChapters.push(...chapters);
|
||||||
@@ -340,7 +354,7 @@ export async function getChapterContent(bookId: string, chapterIndex: string, pr
|
|||||||
}
|
}
|
||||||
|
|
||||||
const isExternal = source !== 'anilist';
|
const isExternal = source !== 'anilist';
|
||||||
const chapterList = await getChaptersForBook(bookId, isExternal);
|
const chapterList = await getChaptersForBook(bookId, isExternal, providerName);
|
||||||
|
|
||||||
if (!chapterList?.chapters || chapterList.chapters.length === 0) {
|
if (!chapterList?.chapters || chapterList.chapters.length === 0) {
|
||||||
throw new Error("Chapters not found");
|
throw new Error("Chapters not found");
|
||||||
|
|||||||
Reference in New Issue
Block a user