fix: show file upload errors
parent
af9b42549f
commit
06e8713fa5
|
@ -55,12 +55,22 @@ export async function upload(
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
onError: function (error) {
|
onError: function (error: Error | tus.DetailedError) {
|
||||||
if (CURRENT_UPLOAD_LIST[filePath].interval) {
|
if (CURRENT_UPLOAD_LIST[filePath].interval) {
|
||||||
clearInterval(CURRENT_UPLOAD_LIST[filePath].interval);
|
clearInterval(CURRENT_UPLOAD_LIST[filePath].interval);
|
||||||
}
|
}
|
||||||
delete CURRENT_UPLOAD_LIST[filePath];
|
delete CURRENT_UPLOAD_LIST[filePath];
|
||||||
reject(new Error(`Upload failed: ${error.message}`));
|
|
||||||
|
const message =
|
||||||
|
error instanceof tus.DetailedError
|
||||||
|
? error.originalResponse === null
|
||||||
|
? "000 No connection"
|
||||||
|
: error.originalResponse.getBody()
|
||||||
|
: "Upload failed";
|
||||||
|
|
||||||
|
console.error(error);
|
||||||
|
|
||||||
|
reject(new Error(message));
|
||||||
},
|
},
|
||||||
onProgress: function (bytesUploaded) {
|
onProgress: function (bytesUploaded) {
|
||||||
const fileData = CURRENT_UPLOAD_LIST[filePath];
|
const fileData = CURRENT_UPLOAD_LIST[filePath];
|
||||||
|
|
|
@ -132,7 +132,6 @@ import {
|
||||||
import { files as api } from "@/api";
|
import { files as api } from "@/api";
|
||||||
import ProgressBar from "@/components/ProgressBar.vue";
|
import ProgressBar from "@/components/ProgressBar.vue";
|
||||||
import prettyBytes from "pretty-bytes";
|
import prettyBytes from "pretty-bytes";
|
||||||
import { StatusError } from "@/api/utils.js";
|
|
||||||
|
|
||||||
const USAGE_DEFAULT = { used: "0 B", total: "0 B", usedPercentage: 0 };
|
const USAGE_DEFAULT = { used: "0 B", total: "0 B", usedPercentage: 0 };
|
||||||
|
|
||||||
|
@ -181,13 +180,9 @@ export default {
|
||||||
total: prettyBytes(usage.total, { binary: true }),
|
total: prettyBytes(usage.total, { binary: true }),
|
||||||
usedPercentage: Math.round((usage.used / usage.total) * 100),
|
usedPercentage: Math.round((usage.used / usage.total) * 100),
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} finally {
|
||||||
if (error instanceof StatusError && error.is_canceled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.$showError(error);
|
|
||||||
}
|
|
||||||
return Object.assign(this.usage, usageStats);
|
return Object.assign(this.usage, usageStats);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
toRoot() {
|
toRoot() {
|
||||||
this.$router.push({ path: "/files" });
|
this.$router.push({ path: "/files" });
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
import {
|
import {
|
||||||
computed,
|
computed,
|
||||||
defineAsyncComponent,
|
defineAsyncComponent,
|
||||||
|
inject,
|
||||||
onBeforeUnmount,
|
onBeforeUnmount,
|
||||||
onMounted,
|
onMounted,
|
||||||
onUnmounted,
|
onUnmounted,
|
||||||
|
@ -50,6 +51,8 @@ import { name } from "../utils/constants";
|
||||||
const Editor = defineAsyncComponent(() => import("@/views/files/Editor.vue"));
|
const Editor = defineAsyncComponent(() => import("@/views/files/Editor.vue"));
|
||||||
const Preview = defineAsyncComponent(() => import("@/views/files/Preview.vue"));
|
const Preview = defineAsyncComponent(() => import("@/views/files/Preview.vue"));
|
||||||
|
|
||||||
|
const $showError = inject<IToastError>("$showError")!;
|
||||||
|
|
||||||
const layoutStore = useLayoutStore();
|
const layoutStore = useLayoutStore();
|
||||||
const fileStore = useFileStore();
|
const fileStore = useFileStore();
|
||||||
const uploadStore = useUploadStore();
|
const uploadStore = useUploadStore();
|
||||||
|
@ -109,7 +112,7 @@ watch(reload, (newValue) => {
|
||||||
newValue && fetchData();
|
newValue && fetchData();
|
||||||
});
|
});
|
||||||
watch(uploadError, (newValue) => {
|
watch(uploadError, (newValue) => {
|
||||||
newValue && layoutStore.showError();
|
newValue && $showError(newValue);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Define functions
|
// Define functions
|
||||||
|
|
Loading…
Reference in New Issue