Fix multiple file upload issues #2112 #2111 #1783

This commit is contained in:
yflory 2026-02-09 15:18:55 +01:00
parent 98d84125f0
commit 608f7d58c4
4 changed files with 16 additions and 22 deletions

View File

@ -10,8 +10,16 @@ const factory = (NaclUtil) => {
window.atob = window.atob || function (str) { return Buffer.from(str, 'base64').toString('binary'); };
window.btoa = window.btoa || function (str) { return Buffer.from(str, 'binary').toString('base64'); };
Util.encodeBase64 = NaclUtil.encodeBase64;
Util.encodeBase64 = u8 => {
if (typeof(u8?.toBase64) === "function") {
return u8.toBase64();
}
return NaclUtil.encodeBase64(u8);
}
Util.decodeBase64 = str => {
if (typeof(Uint8Array?.fromBase64) === "function") {
return Uint8Array.fromBase64(str);
}
let i = str.length % 4;
if (i) { str += '='.repeat(4-i); }
return NaclUtil.decodeBase64(str);
@ -23,18 +31,6 @@ const factory = (NaclUtil) => {
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));

View File

@ -33,7 +33,7 @@ define([
module.uploadFile = function (common, data, cb) {
var sframeChan = common.getSframeChannel();
sframeChan.query('Q_UPLOAD_FILE', data, cb);
sframeChan.query('Q_UPLOAD_FILE', data, cb, {raw: true});
};
module.create = function (common, config) {
@ -220,14 +220,13 @@ define([
file.noStore = config.noStore;
try {
Util.u8ToBase64(u8, b64 => {
file.blob = b64;
file.teamId = teamId;
common.uploadFile(file, function () {
console.log('Upload started...');
});
file.blob = u8;
file.teamId = teamId;
common.uploadFile(file, function () {
console.log('Upload started...');
});
} catch (e) {
console.error(e);
UI.alert(Messages.upload_serverError);
}
};

View File

@ -1700,7 +1700,6 @@ define([
}
});
};
data.blob = Utils.Util.decodeBase64(data.blob);
Files.upload(data, data.noStore, Cryptpad, updateProgress, onComplete, onError, onPending);
cb();
});

File diff suppressed because one or more lines are too long