From ee2466eb22754c7f4a3296d23f8002bb97c4dfb9 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Fri, 3 Sep 2021 22:33:58 -0400 Subject: 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 --- ext/js/data/sandbox/string-util.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'ext/js/data') diff --git a/ext/js/data/sandbox/string-util.js b/ext/js/data/sandbox/string-util.js index 37e021c9..b523c39d 100644 --- a/ext/js/data/sandbox/string-util.js +++ b/ext/js/data/sandbox/string-util.js @@ -58,4 +58,19 @@ class StringUtil { return binary; } } + + /** + * Converts a base64 string to an ArrayBuffer. + * @param content The binary content string encoded in base64. + * @returns A new `ArrayBuffer` object corresponding to the specified content. + */ + static base64ToArrayBuffer(content) { + const binaryContent = atob(content); + const length = binaryContent.length; + const array = new Uint8Array(length); + for (let i = 0; i < length; ++i) { + array[i] = binaryContent.charCodeAt(i); + } + return array.buffer; + } } -- cgit v1.2.3