|
|
|
@ -554,61 +554,55 @@ export function upload(file: File, folder?: any, name?: string, keepOriginal: bo
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const id = Math.random().toString();
|
|
|
|
|
|
|
|
|
|
const reader = new FileReader();
|
|
|
|
|
reader.onload = (e) => {
|
|
|
|
|
const ctx = reactive({
|
|
|
|
|
id: id,
|
|
|
|
|
name: name || file.name || 'untitled',
|
|
|
|
|
progressMax: undefined,
|
|
|
|
|
progressValue: undefined,
|
|
|
|
|
img: window.URL.createObjectURL(file)
|
|
|
|
|
});
|
|
|
|
|
const ctx = reactive({
|
|
|
|
|
id: id,
|
|
|
|
|
name: name || file.name || 'untitled',
|
|
|
|
|
progressMax: undefined,
|
|
|
|
|
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();
|
|
|
|
|
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);
|
|
|
|
|
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);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
xhr.upload.onprogress = e => {
|
|
|
|
|
if (e.lengthComputable) {
|
|
|
|
|
ctx.progressMax = e.total;
|
|
|
|
|
ctx.progressValue = e.loaded;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
alert({
|
|
|
|
|
type: 'error',
|
|
|
|
|
text: 'upload failed'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|