fix: double upload attachment

This commit is contained in:
Methapon Metanipat 2024-10-24 13:25:42 +07:00
parent b58ed78929
commit c9f582359c

View file

@ -1,11 +1,13 @@
import { Dialog, QSelect, Notify, QNotifyCreateOptions } from 'quasar';
import GlobalDialog from 'components/GlobalDialog.vue';
import DialogDuplicateData from 'components/DialogDuplicateData.vue';
import { Ref, ref } from 'vue';
import axios, { AxiosInstance, AxiosProgressEvent } from 'axios';
import { ComposerTranslation } from 'vue-i18n';
import { defineStore } from 'pinia';
import { Ref, ref } from 'vue';
import { getRole } from 'src/services/keycloak';
import { AxiosInstance, AxiosProgressEvent } from 'axios';
import GlobalDialog from 'components/GlobalDialog.vue';
import DialogDuplicateData from 'components/DialogDuplicateData.vue';
export const baseUrl = import.meta.env.VITE_API_BASE_URL;
@ -291,21 +293,26 @@ export function manageAttachment(
onUploadProgress?: (e: AxiosProgressEvent) => void;
abortController?: AbortController;
}) => {
const res = await api.put(
const urlRes = await api.put(
`/${base}/${opts.parentId}/attachment/${opts.name}`,
opts.file,
{
headers: { 'Content-Type': opts.file.type },
onUploadProgress: opts.onUploadProgress
? opts.onUploadProgress
: option?.onUploadProgress
? option.onUploadProgress
: (e) => console.log(e),
signal: opts.abortController?.signal,
},
);
if (res.status < 400) return true;
return false;
if (urlRes.status >= 400) return false;
// NOTE: Must use axios instance or else CORS error.
const uploadRes = await axios.put(urlRes.data, opts.file, {
headers: { 'Content-Type': opts.file.type },
onUploadProgress: opts.onUploadProgress
? opts.onUploadProgress
: option?.onUploadProgress
? option.onUploadProgress
: (e) => console.log(e),
signal: opts.abortController?.signal,
});
if (uploadRes.status >= 400) return false;
return true;
},
delAttachment: async (opts: { parentId: string; name: string }) => {
const res = await api.delete(