aboutsummaryrefslogtreecommitdiff
path: root/ext/js/language/dictionary-worker-media-loader.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-09-03 22:33:58 -0400
committerGitHub <noreply@github.com>2021-09-03 22:33:58 -0400
commit0331374241a55415cbae37d386f47da428ede3db (patch)
tree535801cfabec21a81d2a9ee57b14ef1b8f7678ed /ext/js/language/dictionary-worker-media-loader.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/language/dictionary-worker-media-loader.js')
-rw-r--r--ext/js/language/dictionary-worker-media-loader.js16
1 files changed, 7 insertions, 9 deletions
diff --git a/ext/js/language/dictionary-worker-media-loader.js b/ext/js/language/dictionary-worker-media-loader.js
index 90ee513f..25f8de72 100644
--- a/ext/js/language/dictionary-worker-media-loader.js
+++ b/ext/js/language/dictionary-worker-media-loader.js
@@ -45,21 +45,19 @@ class DictionaryWorkerMediaLoader {
}
/**
- * Attempts to load an image using a base64 encoded content and a media type
- * and returns its resolution.
+ * Attempts to load an image using an ArrayBuffer and a media type to return details about it.
+ * @param content The binary content for the image, encoded as an ArrayBuffer.
* @param mediaType The media type for the image content.
- * @param content The binary content for the image, encoded in base64.
- * @returns A Promise which resolves with {width, height} on success,
- * otherwise an error is thrown.
+ * @returns A Promise which resolves with {content, width, height} on success, otherwise an error is thrown.
*/
- getImageResolution(mediaType, content) {
+ getImageDetails(content, mediaType) {
return new Promise((resolve, reject) => {
const id = generateId(16);
this._requests.set(id, {resolve, reject});
self.postMessage({
- action: 'getImageResolution',
- params: {id, mediaType, content}
- });
+ action: 'getImageDetails',
+ params: {id, content, mediaType}
+ }, [content]);
});
}
}