From a6b6599977b33a86ae0322fdc8e7cb6e9088d3c8 Mon Sep 17 00:00:00 2001 From: wbuezas Date: Thu, 27 Mar 2025 09:37:04 +0100 Subject: [PATCH] Photos view migration --- src/pages/Admin/PhotosView.vue | 48 +++++++++------------------------- 1 file changed, 13 insertions(+), 35 deletions(-) diff --git a/src/pages/Admin/PhotosView.vue b/src/pages/Admin/PhotosView.vue index d80c61ee..a66e3fc8 100644 --- a/src/pages/Admin/PhotosView.vue +++ b/src/pages/Admin/PhotosView.vue @@ -3,9 +3,9 @@ import { useI18n } from 'vue-i18n'; import { ref, onMounted, inject, reactive, computed } from 'vue'; import VnSelect from 'src/components/common/VnSelect.vue'; -import VnForm from 'src/components/common/VnForm.vue'; import VnInput from 'src/components/common/VnInput.vue'; import useNotify from 'src/composables/useNotify.js'; +import FormModel from 'src/components/common/FormModel.vue'; const api = inject('api'); const { t } = useI18n(); @@ -51,10 +51,6 @@ const getImageCollections = async () => { } }; -const buildUploadUrl = (id, collection) => { - return `images/upload?id=${encodeURIComponent(id)}&collection=${encodeURIComponent(collection)}`; -}; - const onSubmit = async data => { if (!addedFiles.value.length) { notify(t('noFilesToUpload'), 'warning'); @@ -66,52 +62,33 @@ const onSubmit = async data => { const promises = filteredFiles.map(async (file, index) => { const fileIndex = filteredFiles[index].index; addedFiles.value[fileIndex].uploadStatus = 'uploading'; - - // const formData = new FormData(); - // formData.append('file', file.file); - - // const entityId = imageCollections.value.find( - // collection => collection.name === data.collectionFk - // ).model; - - // const url = buildUploadUrl(entityId, data.collectionFk); - // console.log('url', url); - // return api({ - // method: 'post', - // url: url, - // data: formData, - // headers: { - // 'Content-Type': 'multipart/form-data' - // } - // }); - const formData = new FormData(); - const now = Date.vnNew(); + const now = new Date(); const timestamp = now.getTime(); - console.log('file', file); - const fileName = `${file.file?.name}_${timestamp}`; - formData.append('blob', file.file, fileName); + const fileName = `${file.name}_${timestamp}`; + formData.append('image', file.file, fileName); - await axios.post('Images/upload', formData, { - params: newPhoto, + await api.post('photos/upload', formData, { + params: { + name: fileName, + collection: data.collectionFk, + updateMatching: data.updateMatching + }, headers: { 'Content-Type': 'multipart/form-data' } }); }); - const results = await Promise.allSettled(promises); results.forEach((result, index) => { const fileIndex = filteredFiles[index].index; addedFiles.value[fileIndex].uploadStatus = result.status; - if (result.status === 'rejected') { addedFiles.value[fileIndex].errorMessage = t( result.reason?.response?.data?.data?.message ); } }); - const allSuccessful = results.every( result => result.status === 'fulfilled' ); @@ -159,12 +136,13 @@ onMounted(async () => getImageCollections());