From 459771b5020471831995b234e86443a7afe28dbd Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Tue, 13 Dec 2022 23:19:05 -0500 Subject: [PATCH 1/2] Use GetContent API in search if defined --- src/modules/search/SearchModule.ts | 67 ++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 12 deletions(-) diff --git a/src/modules/search/SearchModule.ts b/src/modules/search/SearchModule.ts index a03464aa..16508b41 100644 --- a/src/modules/search/SearchModule.ts +++ b/src/modules/search/SearchModule.ts @@ -717,15 +717,13 @@ export class SearchModule implements ReaderModule { } if (tocItem) { let href = this.publication.getAbsoluteHref(tocItem.Href); - await fetch(href, this.delegate.requestConfig) - .then((r) => r.text()) - .then(async (data) => { - // ({ data, tocItem }); + if (this.delegate.api?.getContent) { + this.delegate.api?.getContent(href).then((content) => { let parser = new DOMParser(); let doc = parser.parseFromString( this.delegate.requestConfig?.encoded - ? this.decodeBase64(data) - : data, + ? this.decodeBase64(content) + : content, "application/xhtml+xml" ); if (tocItem) { @@ -739,6 +737,29 @@ export class SearchModule implements ReaderModule { ); } }); + } else { + await fetch(href, this.delegate.requestConfig) + .then((r) => r.text()) + .then(async (data) => { + let parser = new DOMParser(); + let doc = parser.parseFromString( + this.delegate.requestConfig?.encoded + ? this.decodeBase64(data) + : data, + "application/xhtml+xml" + ); + if (tocItem) { + searchDocDomSeek(term, doc, tocItem.Href, tocItem.Title).then( + (result) => { + result.forEach((searchItem) => { + localSearchResultBook.push(searchItem); + this.bookSearchResult.push(searchItem); + }); + } + ); + } + }); + } } if (index === this.publication.readingOrder.length - 1) { return localSearchResultBook; @@ -768,17 +789,16 @@ export class SearchModule implements ReaderModule { this.delegate.currentResource() ?? 0 ]; } + if (tocItem) { let href = this.publication.getAbsoluteHref(tocItem.Href); - await fetch(href, this.delegate.requestConfig) - .then((r) => r.text()) - .then(async (data) => { - // ({ data, tocItem }); + if (this.delegate.api?.getContent) { + this.delegate.api?.getContent(href).then((content) => { let parser = new DOMParser(); let doc = parser.parseFromString( this.delegate.requestConfig?.encoded - ? this.decodeBase64(data) - : data, + ? this.decodeBase64(content) + : content, "application/xhtml+xml" ); if (tocItem) { @@ -791,6 +811,29 @@ export class SearchModule implements ReaderModule { ); } }); + } else { + await fetch(href, this.delegate.requestConfig) + .then((r) => r.text()) + .then(async (data) => { + // ({ data, tocItem }); + let parser = new DOMParser(); + let doc = parser.parseFromString( + this.delegate.requestConfig?.encoded + ? this.decodeBase64(data) + : data, + "application/xhtml+xml" + ); + if (tocItem) { + searchDocDomSeek(term, doc, tocItem.Href, tocItem.Title).then( + (result) => { + result.forEach((searchItem) => { + localSearchResultBook.push(searchItem); + }); + } + ); + } + }); + } } return localSearchResultBook; From 535da93fa420403a135ea2b4665d0f8b339a2122 Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Tue, 13 Dec 2022 23:19:33 -0500 Subject: [PATCH 2/2] version bump --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 66bd7386..8db69606 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@d-i-t-a/reader", - "version": "2.1.5", + "version": "2.1.6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@d-i-t-a/reader", - "version": "2.1.5", + "version": "2.1.6", "license": "Apache-2.0", "dependencies": { "@types/sass": "^1.43.1", diff --git a/package.json b/package.json index f993d057..16ce59f8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@d-i-t-a/reader", - "version": "2.1.5", + "version": "2.1.6", "description": "A viewer application for EPUB files.", "repository": "https://github.com/d-i-t-a/R2D2BC", "license": "Apache-2.0",