Use 'content' instead of 'source' to contain media file data

This commit is contained in:
toasted-nutbread 2020-04-19 10:16:59 -04:00
parent 07e5e5c15b
commit 7faaf4e457
3 changed files with 8 additions and 8 deletions

View File

@ -323,7 +323,7 @@ class DictionaryImporter {
throw new Error(`Could not find image at path ${JSON.stringify(path)} for ${errorSource}`); throw new Error(`Could not find image at path ${JSON.stringify(path)} for ${errorSource}`);
} }
const source = await file.async('base64'); const content = await file.async('base64');
const mediaType = mediaUtility.getImageMediaTypeFromFileName(path); const mediaType = mediaUtility.getImageMediaTypeFromFileName(path);
if (mediaType === null) { if (mediaType === null) {
throw new Error(`Could not determine media type for image at path ${JSON.stringify(path)} for ${errorSource}`); throw new Error(`Could not determine media type for image at path ${JSON.stringify(path)} for ${errorSource}`);
@ -331,7 +331,7 @@ class DictionaryImporter {
let image; let image;
try { try {
image = await mediaUtility.loadImage(mediaType, source); image = await mediaUtility.loadImage(mediaType, content);
} catch (e) { } catch (e) {
throw new Error(`Could not load image at path ${JSON.stringify(path)} for ${errorSource}`); throw new Error(`Could not load image at path ${JSON.stringify(path)} for ${errorSource}`);
} }
@ -346,7 +346,7 @@ class DictionaryImporter {
mediaType, mediaType,
width, width,
height, height,
source content
}; };
context.media.set(path, mediaData); context.media.set(path, mediaData);

View File

@ -52,7 +52,7 @@ const mediaUtility = (() => {
} }
} }
function loadImage(mediaType, base64Source) { function loadImage(mediaType, content) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const image = new Image(); const image = new Image();
const eventListeners = new EventListenerCollection(); const eventListeners = new EventListenerCollection();
@ -64,7 +64,7 @@ const mediaUtility = (() => {
eventListeners.removeAllEventListeners(); eventListeners.removeAllEventListeners();
reject(new Error('Image failed to load')); reject(new Error('Image failed to load'));
}, false); }, false);
image.src = `data:${mediaType};base64,${base64Source}`; image.src = `data:${mediaType};base64,${content}`;
}); });
} }

View File

@ -86,7 +86,7 @@ class MediaLoader {
const token = this._token; const token = this._token;
const data = (await apiGetMedia([{path, dictionaryName}]))[0]; const data = (await apiGetMedia([{path, dictionaryName}]))[0];
if (token === this._token && data !== null) { if (token === this._token && data !== null) {
const sourceArrayBuffer = this._base64ToArrayBuffer(data.source); const sourceArrayBuffer = this._base64ToArrayBuffer(data.content);
const blob = new Blob([sourceArrayBuffer], {type: data.mediaType}); const blob = new Blob([sourceArrayBuffer], {type: data.mediaType});
const url = URL.createObjectURL(blob); const url = URL.createObjectURL(blob);
cachedData.data = data; cachedData.data = data;
@ -95,8 +95,8 @@ class MediaLoader {
return cachedData; return cachedData;
} }
_base64ToArrayBuffer(source) { _base64ToArrayBuffer(content) {
const binarySource = window.atob(source); const binarySource = window.atob(content);
const length = binarySource.length; const length = binarySource.length;
const array = new Uint8Array(length); const array = new Uint8Array(length);
for (let i = 0; i < length; ++i) { for (let i = 0; i < length; ++i) {