diff --git a/www/common/common-util.js b/www/common/common-util.js index 5faa9171e..d56f7ee6f 100644 --- a/www/common/common-util.js +++ b/www/common/common-util.js @@ -13,6 +13,18 @@ return Array.prototype.slice.call(A, start, end); }; + Util.u8ToBase64 = (u8, cb) => { + const reader = new FileReader(); + reader.onload = () => { + let res = reader.result; + let trim = res.slice(res.indexOf(',') + 1); + cb(trim); + }; + reader.readAsDataURL(new Blob([u8])); + }; + + + Util.shuffleArray = function (a) { for (var i = a.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js index d16185fd1..24653b700 100644 --- a/www/common/sframe-common-file.js +++ b/www/common/sframe-common-file.js @@ -19,9 +19,7 @@ define([ '/common/media-tag.js', '/components/file-saver/FileSaver.min.js', - '/components/tweetnacl/nacl-fast.min.js', ], function ($, ApiConfig, FileCrypto, MakeBackup, Thumb, UI, UIElements, Util, Hash, h, Messages, Pages, nThen, MT) { - var Nacl = window.nacl; var module = {}; var blobToArrayBuffer = function (blob, cb) { @@ -221,10 +219,12 @@ define([ file.noStore = config.noStore; try { - file.blob = Nacl.util.encodeBase64(u8); - file.teamId = teamId; - common.uploadFile(file, function () { - console.log('Upload started...'); + Util.u8ToBase64(u8, b64 => { + file.blob = b64; + file.teamId = teamId; + common.uploadFile(file, function () { + console.log('Upload started...'); + }); }); } catch (e) { UI.alert(Messages.upload_serverError);