Fixed an issue where aborting an upload would not delete the partial upload from the server. Also fixed an issue where the abortAll function wasn't resetting and reloading the frontend properly
This commit is contained in:
parent
ae0af1f996
commit
c4e8011e99
@ -200,14 +200,35 @@ function calcProgress(filePath: string) {
|
||||
fileData.lastProgressTimestamp = Date.now();
|
||||
}
|
||||
|
||||
export function abortAllUploads() {
|
||||
export async function abortAllUploads() {
|
||||
const deletePromises = [];
|
||||
|
||||
for (const filePath in CURRENT_UPLOAD_LIST) {
|
||||
if (CURRENT_UPLOAD_LIST[filePath].interval) {
|
||||
clearInterval(CURRENT_UPLOAD_LIST[filePath].interval);
|
||||
}
|
||||
if (CURRENT_UPLOAD_LIST[filePath].upload) {
|
||||
CURRENT_UPLOAD_LIST[filePath].upload.abort(true);
|
||||
//setting to false since the current tus method tries to delete against a non-existent endpoint
|
||||
CURRENT_UPLOAD_LIST[filePath].upload.abort(false); //TODO figure out how to do this properly through tus
|
||||
}
|
||||
|
||||
// Make a DELETE request to remove the file from the server
|
||||
// TODO figure out how to do this properly through tus
|
||||
const deleteUrl = `${baseURL}/api/resources/${filePath}`;
|
||||
const deletePromise = fetchURL(deleteUrl, {
|
||||
method: "DELETE"
|
||||
}).then(response => {
|
||||
if (response.status !== 200) {
|
||||
console.error(`Failed to delete file: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
}).catch(error => {
|
||||
console.error(`Error deleting file: ${error.message}`);
|
||||
});
|
||||
|
||||
deletePromises.push(deletePromise);
|
||||
delete CURRENT_UPLOAD_LIST[filePath];
|
||||
}
|
||||
|
||||
await Promise.all(deletePromises);
|
||||
}
|
||||
|
||||
|
||||
@ -74,7 +74,6 @@ export default {
|
||||
"getETA",
|
||||
]),
|
||||
...mapWritableState(useFileStore, ["reload"]),
|
||||
...mapActions(useUploadStore, ["reset"]),
|
||||
formattedETA() {
|
||||
if (!this.getETA || this.getETA === Infinity) {
|
||||
return "--:--:--";
|
||||
@ -92,6 +91,7 @@ export default {
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
...mapActions(useUploadStore, ["reset"]), // Mapping reset action from upload store
|
||||
toggle: function () {
|
||||
this.open = !this.open;
|
||||
},
|
||||
@ -100,8 +100,8 @@ export default {
|
||||
abortAllUploads();
|
||||
buttons.done("upload");
|
||||
this.open = false;
|
||||
this.reset();
|
||||
this.reload = true;
|
||||
this.reset(); // Resetting the upload store state
|
||||
this.reload = true; // Trigger reload in the file store
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user