support for headless browser & changes on book api
This commit is contained in:
@@ -126,6 +126,7 @@ export async function getBookInfoExtension(ext: Extension | null, id: string): P
|
||||
|
||||
if (ext.type === 'book-board' && ext.getMetadata) {
|
||||
try {
|
||||
|
||||
const info = await ext.getMetadata(id);
|
||||
|
||||
if (info) {
|
||||
@@ -198,8 +199,8 @@ async function fetchBookMetadata(id: string): Promise<Book | null> {
|
||||
}
|
||||
}
|
||||
|
||||
async function searchChaptersInExtension(ext: Extension, name: string, searchTitle: string, search: boolean): Promise<ChapterWithProvider[]> {
|
||||
const cacheKey = `chapters:${name}:${searchTitle}`;
|
||||
async function searchChaptersInExtension(ext: Extension, name: string, searchTitle: string, search: boolean, origin: string): Promise<ChapterWithProvider[]> {
|
||||
const cacheKey = `chapters:${name}:${origin}:${search ? "search" : "id"}:${searchTitle}`;
|
||||
const cached = await getCache(cacheKey);
|
||||
|
||||
if (cached) {
|
||||
@@ -244,7 +245,7 @@ async function searchChaptersInExtension(ext: Extension, name: string, searchTit
|
||||
|
||||
const chaps = await ext.findChapters!(mediaId);
|
||||
|
||||
if (!chaps?.length) {
|
||||
if (!chaps?.length){
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -267,11 +268,11 @@ async function searchChaptersInExtension(ext: Extension, name: string, searchTit
|
||||
}
|
||||
}
|
||||
|
||||
export async function getChaptersForBook(id: string): Promise<{ chapters: ChapterWithProvider[] }> {
|
||||
export async function getChaptersForBook(id: string, ext: Boolean): Promise<{ chapters: ChapterWithProvider[] }> {
|
||||
let bookData: Book | null = null;
|
||||
let searchTitle: string = "";
|
||||
|
||||
if (!isNaN(Number(id))) {
|
||||
if (!ext) {
|
||||
const result = await getBookById(id);
|
||||
if (!result || "error" in result) return { chapters: [] }
|
||||
bookData = result;
|
||||
@@ -292,13 +293,15 @@ export async function getChaptersForBook(id: string): Promise<{ chapters: Chapte
|
||||
}
|
||||
|
||||
const allChapters: any[] = [];
|
||||
let exts = "anilist";
|
||||
if (ext) exts = "ext";
|
||||
|
||||
for (const [name, ext] of bookExtensions) {
|
||||
if (name == extension) {
|
||||
const chapters = await searchChaptersInExtension(ext, name, id, false);
|
||||
const chapters = await searchChaptersInExtension(ext, name, id, false, exts);
|
||||
allChapters.push(...chapters);
|
||||
} else {
|
||||
const chapters = await searchChaptersInExtension(ext, name, searchTitle, true);
|
||||
const chapters = await searchChaptersInExtension(ext, name, searchTitle, true, exts);
|
||||
allChapters.push(...chapters);
|
||||
}
|
||||
}
|
||||
@@ -308,15 +311,17 @@ export async function getChaptersForBook(id: string): Promise<{ chapters: Chapte
|
||||
};
|
||||
}
|
||||
|
||||
export async function getChapterContent(bookId: string, chapterIndex: string, providerName: string): Promise<ChapterContent> {
|
||||
export async function getChapterContent(bookId: string, chapterIndex: string, providerName: string, name: string): Promise<ChapterContent> {
|
||||
const extensions = getAllExtensions();
|
||||
const ext = extensions.get(providerName);
|
||||
|
||||
if (!ext) {
|
||||
throw new Error("Provider not found");
|
||||
}
|
||||
let exts = "anilist";
|
||||
if (name) exts = "ext";
|
||||
|
||||
const contentCacheKey = `content:${providerName}:${bookId}:${chapterIndex}`;
|
||||
const contentCacheKey = `content:${providerName}:${exts}:${bookId}:${chapterIndex}`;
|
||||
const cachedContent = await getCache(contentCacheKey);
|
||||
|
||||
if (cachedContent) {
|
||||
@@ -335,7 +340,7 @@ export async function getChapterContent(bookId: string, chapterIndex: string, pr
|
||||
}
|
||||
}
|
||||
|
||||
const chapterList = await getChaptersForBook(bookId);
|
||||
const chapterList = await getChaptersForBook(bookId, Boolean(name));
|
||||
|
||||
if (!chapterList?.chapters || chapterList.chapters.length === 0) {
|
||||
throw new Error("Chapters not found");
|
||||
|
||||
Reference in New Issue
Block a user