filemanager: fix upload cancellation

This commit is contained in:
Johannes Zellner
2024-08-19 17:09:04 +02:00
parent a218761e99
commit 69ecbe5ad7
2 changed files with 9 additions and 7 deletions
+7 -5
View File
@@ -67,13 +67,12 @@ export function createDirectoryModel(origin, accessToken, api) {
return result.body.entries;
},
async upload(targetDir, file, progressHandler) {
upload(targetDir, file, progressHandler) {
// file may contain a file name or a file path + file name
const relativefilePath = (file.webkitRelativePath ? file.webkitRelativePath : file.name);
const xhr = new XMLHttpRequest();
const req = new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.addEventListener('load', () => {
if (xhr.status >= 200 && xhr.status < 300) {
resolve(xhr.response);
@@ -101,10 +100,13 @@ export function createDirectoryModel(origin, accessToken, api) {
xhr.send(file);
});
const res = await req;
// attach for upstream xhr.abort()
req.xhr = xhr;
return req;
},
async newFile(filePath) {
await this.save(filePath, '')
await this.save(filePath, '');
},
async newFolder(folderPath) {
await superagent.post(`${origin}/api/v1/${api}/files/${folderPath}?access_token=${accessToken}&directory=true`);