summaryrefslogtreecommitdiff
path: root/ext/js/background/backend.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-09-03 22:33:58 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-09-11 16:05:39 -0400
commitee2466eb22754c7f4a3296d23f8002bb97c4dfb9 (patch)
tree535801cfabec21a81d2a9ee57b14ef1b8f7678ed /ext/js/background/backend.js
parent764d59df137dacfa6b4cfa8394b711fda904efd9 (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/background/backend.js')
-rw-r--r--ext/js/background/backend.js16
1 files changed, 14 insertions, 2 deletions
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js
index dea67091..8e05ee68 100644
--- a/ext/js/background/backend.js
+++ b/ext/js/background/backend.js
@@ -31,6 +31,7 @@
* PermissionsUtil
* ProfileConditionsUtil
* RequestBuilder
+ * StringUtil
* Translator
* wanakana
*/
@@ -621,7 +622,7 @@ class Backend {
}
async _onApiGetMedia({targets}) {
- return await this._dictionaryDatabase.getMedia(targets);
+ return await this._getNormalizedDictionaryDatabaseMedia(targets);
}
_onApiLog({error, level, context}) {
@@ -1847,7 +1848,7 @@ class Backend {
detailsList.push(details);
detailsMap.set(key, details);
}
- const mediaList = await this._dictionaryDatabase.getMedia(targets);
+ const mediaList = await this._getNormalizedDictionaryDatabaseMedia(targets);
for (const media of mediaList) {
const {dictionary, path} = media;
@@ -2283,4 +2284,15 @@ class Backend {
return await this._injectScript(file, tab.id, frameId);
}
+
+ async _getNormalizedDictionaryDatabaseMedia(targets) {
+ const results = await this._dictionaryDatabase.getMedia(targets);
+ for (const item of results) {
+ const {content} = item;
+ if (content instanceof ArrayBuffer) {
+ item.content = StringUtil.arrayBufferToBase64(content);
+ }
+ }
+ return results;
+ }
}