Compare commits

..

No commits in common. "db3940f3545c40c8c9b8954a839d71b7eb4162aa" and "b63cdc2c5cfff921cc6ba51b5fd7f9b343018f39" have entirely different histories.

2 changed files with 48 additions and 42 deletions

View File

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

View File

@ -554,55 +554,61 @@ 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 ctx = reactive({ const reader = new FileReader();
id: id, reader.onload = (e) => {
name: name || file.name || 'untitled', const ctx = reactive({
progressMax: undefined, id: id,
progressValue: undefined, name: name || file.name || 'untitled',
img: window.URL.createObjectURL(file) progressMax: undefined,
}); progressValue: undefined,
img: window.URL.createObjectURL(file)
});
uploads.value.push(ctx); uploads.value.push(ctx);
const data = new FormData(); console.log(keepOriginal);
data.append('i', $i.token);
data.append('force', 'true');
data.append('file', file);
if (folder) data.append('folderId', folder); const data = new FormData();
if (name) data.append('name', name); data.append('i', $i.token);
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);
};
alert({ xhr.upload.onprogress = e => {
type: 'error', if (e.lengthComputable) {
text: 'upload failed' ctx.progressMax = e.total;
}); ctx.progressValue = e.loaded;
}
};
reject(); xhr.send(data);
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);
}); });
} }