diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-09-03 22:33:58 -0400 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-09-11 16:05:39 -0400 |
commit | ee2466eb22754c7f4a3296d23f8002bb97c4dfb9 (patch) | |
tree | 535801cfabec21a81d2a9ee57b14ef1b8f7678ed /ext/js/media | |
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/media')
-rw-r--r-- | ext/js/media/media-loader.js | 5 | ||||
-rw-r--r-- | ext/js/media/media-util.js | 16 |
2 files changed, 3 insertions, 18 deletions
diff --git a/ext/js/media/media-loader.js b/ext/js/media/media-loader.js index 7dafc2a3..8c7e356c 100644 --- a/ext/js/media/media-loader.js +++ b/ext/js/media/media-loader.js @@ -16,7 +16,7 @@ */ /* global - * MediaUtil + * StringUtil */ class MediaLoader { @@ -86,7 +86,8 @@ class MediaLoader { const token = this._token; const data = (await yomichan.api.getMedia([{path, dictionary}]))[0]; if (token === this._token && data !== null) { - const blob = MediaUtil.createBlobFromBase64Content(data.content, data.mediaType); + const buffer = StringUtil.base64ToArrayBuffer(data.content); + const blob = new Blob([buffer], {type: data.mediaType}); const url = URL.createObjectURL(blob); cachedData.data = data; cachedData.url = url; diff --git a/ext/js/media/media-util.js b/ext/js/media/media-util.js index f783038a..11172c5c 100644 --- a/ext/js/media/media-util.js +++ b/ext/js/media/media-util.js @@ -129,20 +129,4 @@ class MediaUtil { return null; } } - - /** - * Creates a new `Blob` object from a base64 string of content. - * @param content The binary content string encoded in base64. - * @param mediaType The type of the media. - * @returns A new `Blob` object corresponding to the specified content. - */ - static createBlobFromBase64Content(content, mediaType) { - 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 new Blob([array.buffer], {type: mediaType}); - } } |