Compare commits

...

2 Commits

Author SHA1 Message Date
Derek db3940f354 Bump 2022-05-21 16:05:55 -04:00
Derek d4cd641f74 Do not read the ENTIRE file before
uploading 

No idea if this code is supposed to serve a purpose, but it breaks on 
files larger than 4GB in firefox and chrome, and the read file-as-buffer 
is never used
2022-05-21 16:05:33 -04:00
2 changed files with 42 additions and 48 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "misskey", "name": "misskey",
"version": "12.110.1+birb3", "version": "12.110.1+birb3-1",
"codename": "indigo", "codename": "indigo",
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -554,61 +554,55 @@ export function upload(file: File, folder?: any, name?: string, keepOriginal: bo
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const id = Math.random().toString(); const id = Math.random().toString();
const reader = new FileReader(); const ctx = reactive({
reader.onload = (e) => { id: id,
const ctx = reactive({ name: name || file.name || 'untitled',
id: id, progressMax: undefined,
name: name || file.name || 'untitled', progressValue: undefined,
progressMax: undefined, img: window.URL.createObjectURL(file)
progressValue: undefined, });
img: window.URL.createObjectURL(file)
});
uploads.value.push(ctx); uploads.value.push(ctx);
console.log(keepOriginal); const data = new FormData();
data.append('i', $i.token);
data.append('force', 'true');
data.append('file', file);
const data = new FormData(); if (folder) data.append('folderId', folder);
data.append('i', $i.token); if (name) data.append('name', name);
data.append('force', 'true');
data.append('file', file);
if (folder) data.append('folderId', folder);
if (name) data.append('name', name);
const xhr = new XMLHttpRequest();
xhr.open('POST', apiUrl + '/drive/files/create', true);
xhr.onload = (ev) => {
if (xhr.status !== 200 || ev.target == null || ev.target.response == null) {
// TODO: 消すのではなくて再送できるようにしたい
uploads.value = uploads.value.filter(x => x.id != id);
alert({
type: 'error',
text: 'upload failed'
});
reject();
return;
}
const driveFile = JSON.parse(ev.target.response);
resolve(driveFile);
const xhr = new XMLHttpRequest();
xhr.open('POST', apiUrl + '/drive/files/create', true);
xhr.onload = (ev) => {
if (xhr.status !== 200 || ev.target == null || ev.target.response == null) {
// TODO: 消すのではなくて再送できるようにしたい
uploads.value = uploads.value.filter(x => x.id != id); uploads.value = uploads.value.filter(x => x.id != id);
};
xhr.upload.onprogress = e => { alert({
if (e.lengthComputable) { type: 'error',
ctx.progressMax = e.total; text: 'upload failed'
ctx.progressValue = e.loaded; });
}
};
xhr.send(data); reject();
return;
}
const driveFile = JSON.parse(ev.target.response);
resolve(driveFile);
uploads.value = uploads.value.filter(x => x.id != id);
}; };
reader.readAsArrayBuffer(file);
xhr.upload.onprogress = e => {
if (e.lengthComputable) {
ctx.progressMax = e.total;
ctx.progressValue = e.loaded;
}
};
xhr.send(data);
}); });
} }