aboutsummaryrefslogtreecommitdiff
path: root/ext/js/media/media-loader.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-03-14 18:41:15 -0400
committerGitHub <noreply@github.com>2021-03-14 18:41:15 -0400
commit07df1e011794f5a77f7fb7da5cd9ea353a8747e2 (patch)
tree98a679d4ef07629b8f0121e244038c557c972bd8 /ext/js/media/media-loader.js
parent52a4d874eada5be121e15d73d1d10e9a8d84bdb8 (diff)
Fix dictionary image support (#1526)
* Fix content security policy for images * Add createBlobFromBase64Content to MediaUtil * Update MediaLoader to use MediaUtil * Use blob URLs when importing dictionaries * Update VM's URL to support createObjectURL and revokeObjectURL * Fix test
Diffstat (limited to 'ext/js/media/media-loader.js')
-rw-r--r--ext/js/media/media-loader.js17
1 files changed, 5 insertions, 12 deletions
diff --git a/ext/js/media/media-loader.js b/ext/js/media/media-loader.js
index d9d40a36..4ac733c5 100644
--- a/ext/js/media/media-loader.js
+++ b/ext/js/media/media-loader.js
@@ -15,6 +15,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+/* global
+ * MediaUtil
+ */
+
class MediaLoader {
constructor() {
this._token = {};
@@ -82,22 +86,11 @@ class MediaLoader {
const token = this._token;
const data = (await yomichan.api.getMedia([{path, dictionaryName}]))[0];
if (token === this._token && data !== null) {
- const contentArrayBuffer = this._base64ToArrayBuffer(data.content);
- const blob = new Blob([contentArrayBuffer], {type: data.mediaType});
+ const blob = MediaUtil.createBlobFromBase64Content(data.content, data.mediaType);
const url = URL.createObjectURL(blob);
cachedData.data = data;
cachedData.url = url;
}
return cachedData;
}
-
- _base64ToArrayBuffer(content) {
- const binaryContent = window.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;
- }
}