[IMP] web_editor: introduce a tool method to compute size of data URL
This commit extracts the calculation of the number of bytes within a base64 data URL to a method named `getDataURLBinarySize`. task-2835144 Part-of: odoo/odoo#103398
This commit is contained in:
@@ -496,6 +496,15 @@ function createDataURL(blob) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {String} dataURL
|
||||
* @returns {Number} number of bytes represented with base64
|
||||
*/
|
||||
function getDataURLBinarySize(dataURL) {
|
||||
// Every 4 bytes of base64 represent 3 bytes.
|
||||
return dataURL.split(',')[1].length / 4 * 3;
|
||||
}
|
||||
|
||||
export default {
|
||||
applyModifications,
|
||||
cropperDataFields,
|
||||
@@ -507,4 +516,5 @@ export default {
|
||||
isImageSupportedForStyle,
|
||||
createDataURL,
|
||||
isGif,
|
||||
getDataURLBinarySize,
|
||||
};
|
||||
|
||||
@@ -31,6 +31,7 @@ import {
|
||||
isImageSupportedForStyle,
|
||||
createDataURL,
|
||||
isGif,
|
||||
getDataURLBinarySize,
|
||||
} from "web_editor.image_processing";
|
||||
import * as OdooEditorLib from "@web_editor/js/editor/odoo-editor/src/OdooEditor";
|
||||
import {SIZES, MEDIAS_BREAKPOINTS} from "@web/core/ui/ui_service";
|
||||
@@ -5874,7 +5875,7 @@ const ImageHandlerOption = SnippetOptionWidget.extend({
|
||||
return;
|
||||
}
|
||||
const dataURL = await applyModifications(img, {mimetype: this._getImageMimetype(img)});
|
||||
this._filesize = dataURL.split(',')[1].length / 4 * 3 / 1024;
|
||||
this._filesize = getDataURLBinarySize(dataURL) / 1024;
|
||||
|
||||
if (update) {
|
||||
img.classList.add('o_modified_image_to_save');
|
||||
|
||||
Reference in New Issue
Block a user