mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 13:40:27 +02:00
feat: Add dynamic loading of JSZip library with error handling for EPUB fetching
This commit is contained in:
@@ -178,6 +178,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script type="application/json" id="reader-data">{{ {'chapters': chapters, 'title': job.original_filename}|tojson }}</script>
|
<script type="application/json" id="reader-data">{{ {'chapters': chapters, 'title': job.original_filename}|tojson }}</script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/jszip@3.10.1/dist/jszip.min.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/epubjs@0.3.93/dist/epub.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/epubjs@0.3.93/dist/epub.min.js"></script>
|
||||||
<script type="module">
|
<script type="module">
|
||||||
const statusEl = document.querySelector('[data-role="reader-status"]');
|
const statusEl = document.querySelector('[data-role="reader-status"]');
|
||||||
@@ -306,6 +307,30 @@
|
|||||||
return buffer;
|
return buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let ensureJsZipPromise = null;
|
||||||
|
const ensureJsZip = async () => {
|
||||||
|
if (typeof window !== 'undefined' && window.JSZip) {
|
||||||
|
return window.JSZip;
|
||||||
|
}
|
||||||
|
if (ensureJsZipPromise) {
|
||||||
|
return ensureJsZipPromise;
|
||||||
|
}
|
||||||
|
ensureJsZipPromise = (async () => {
|
||||||
|
try {
|
||||||
|
const module = await import('https://cdn.jsdelivr.net/npm/jszip@3.10.1/+esm');
|
||||||
|
const lib = module?.default || module?.JSZip || module;
|
||||||
|
if (lib && typeof window !== 'undefined') {
|
||||||
|
window.JSZip = lib;
|
||||||
|
}
|
||||||
|
return lib || null;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to dynamically import JSZip', error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
return ensureJsZipPromise;
|
||||||
|
};
|
||||||
|
|
||||||
const buildAssetUrl = (path) => {
|
const buildAssetUrl = (path) => {
|
||||||
if (!path) {
|
if (!path) {
|
||||||
return '';
|
return '';
|
||||||
@@ -830,6 +855,12 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const jszipLib = await ensureJsZip();
|
||||||
|
if (!jszipLib) {
|
||||||
|
setStatus('JSZip could not be loaded. Please check your network connection.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setStatus('Fetching EPUB…');
|
setStatus('Fetching EPUB…');
|
||||||
let epubPayload = null;
|
let epubPayload = null;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user