diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-09-03 22:33:58 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-03 22:33:58 -0400 |
commit | 0331374241a55415cbae37d386f47da428ede3db (patch) | |
tree | 535801cfabec21a81d2a9ee57b14ef1b8f7678ed /ext/js/language/dictionary-importer.js | |
parent | 764d59df137dacfa6b4cfa8394b711fda904efd9 (diff) |
Dictionary media import improvements (#1926)
* Add base64ToArrayBuffer to StringUtil
* Remove unnecessary media-util.js import
* Run async requirements in serial rather than parallel
* Update API.getMedia handler to convert ArrayBuffer content to base64
* Rename getImageResolution to getImageDetails
* Change parameter order of getImageDetails
* Pre-process and store media as an ArrayBuffer
* Remove MediaUtil.createBlobFromBase64Content
* Fix Anki media injection
Diffstat (limited to 'ext/js/language/dictionary-importer.js')
-rw-r--r-- | ext/js/language/dictionary-importer.js | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/ext/js/language/dictionary-importer.js b/ext/js/language/dictionary-importer.js index 98cddf76..5629e197 100644 --- a/ext/js/language/dictionary-importer.js +++ b/ext/js/language/dictionary-importer.js @@ -328,13 +328,10 @@ class DictionaryImporter { const media = new Map(); const context = {archive, media}; - const promises = []; for (const requirement of requirements) { - promises.push(this._resolveAsyncRequirement(context, requirement)); + await this._resolveAsyncRequirement(context, requirement); } - await Promise.all(promises); - return { media: [...media.values()] }; @@ -425,7 +422,7 @@ class DictionaryImporter { } // Load file content - const content = await file.async('base64'); + let content = await file.async('arraybuffer'); const mediaType = MediaUtil.getImageMediaTypeFromFileName(path); if (mediaType === null) { throw createError('Could not determine media type for image'); @@ -435,7 +432,7 @@ class DictionaryImporter { let width; let height; try { - ({width, height} = await this._mediaLoader.getImageResolution(mediaType, content)); + ({content, width, height} = await this._mediaLoader.getImageDetails(content, mediaType)); } catch (e) { throw createError('Could not load image'); } |