From 8a8940e9c22be504e6ebc1f57272b3f339d634a6 Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Wed, 1 May 2024 10:07:32 -0400 Subject: [PATCH] EPUB: Show error when EPUB appears to be encrypted And update .error-bar appearance. --- src/common/reader.js | 7 ++++++- src/common/stylesheets/components/_other.scss | 6 ++++-- src/dom/common/dom-view.tsx | 1 + src/dom/epub/epub-view.ts | 16 ++++++++++++++++ src/dom/epub/section-view.ts | 3 +++ src/en-us.strings.js | 3 ++- 6 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/common/reader.js b/src/common/reader.js index 0dc3ce03..0bf75a7d 100644 --- a/src/common/reader.js +++ b/src/common/reader.js @@ -741,6 +741,10 @@ class Reader { this._onSetZoom(iframe, zoom); }); + let onEPUBEncrypted = () => { + this.setErrorMessage(this._getString('pdfReader.epubEncrypted')); + }; + let data; if (this._type === 'pdf') { data = this._data; @@ -812,7 +816,8 @@ class Reader { } else if (this._type === 'epub') { view = new EPUBView({ ...common, - fontFamily: this._state.fontFamily + fontFamily: this._state.fontFamily, + onEPUBEncrypted, }); } else if (this._type === 'snapshot') { view = new SnapshotView({ diff --git a/src/common/stylesheets/components/_other.scss b/src/common/stylesheets/components/_other.scss index 47649d4d..7c82dd43 100644 --- a/src/common/stylesheets/components/_other.scss +++ b/src/common/stylesheets/components/_other.scss @@ -3,11 +3,13 @@ left: 0; right: 0; bottom: 0; - height: 25px; + font-size: rem(16); + height: 2.5em; display: flex; justify-content: center; align-items: center; - background-color: #ff7474; + background-color: var(--accent-red); + color: var(--accent-white); z-index: $z-index-error-bar; } diff --git a/src/dom/common/dom-view.tsx b/src/dom/common/dom-view.tsx index f02ad3b5..3602c37b 100644 --- a/src/dom/common/dom-view.tsx +++ b/src/dom/common/dom-view.tsx @@ -1212,6 +1212,7 @@ export type DOMViewOptions = { onTabOut: (isShiftTab?: boolean) => void; onKeyUp: (event: KeyboardEvent) => void; onKeyDown: (event: KeyboardEvent) => void; + onEPUBEncrypted: () => void; data: Data & { buf?: Uint8Array, url?: string diff --git a/src/dom/epub/epub-view.ts b/src/dom/epub/epub-view.ts index 8702f8c5..8201e1e4 100644 --- a/src/dom/epub/epub-view.ts +++ b/src/dom/epub/epub-view.ts @@ -154,6 +154,12 @@ class EPUBView extends DOMView { let styleScoper = new StyleScoper(this._iframeDocument); await Promise.all(this.book.spine.spineItems.map(section => this._displaySection(section, styleScoper))); + if (this._sectionViews.some(view => view.error) && await this._isEncrypted()) { + this._options.onEPUBEncrypted(); + this._sectionsContainer.remove(); + return; + } + if (this._options.fontFamily) { this._iframeDocument.documentElement.style.setProperty('--content-font-family', this._options.fontFamily); } @@ -195,6 +201,16 @@ class EPUBView extends DOMView { this.book.archive.zip = null; } + private async _isEncrypted() { + try { + let xml = await this.book.archive.request('/META-INF/encryption.xml', 'text') as string; + return xml.includes('