From a1ed5429a468e51ce32c76931c3bff3e9b253f79 Mon Sep 17 00:00:00 2001 From: nquidox Date: Sun, 26 Oct 2025 21:32:35 +0300 Subject: [PATCH] upload response + get url refactor --- src/api/merchImages.js | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/api/merchImages.js b/src/api/merchImages.js index 19a8f77..61bc9f0 100644 --- a/src/api/merchImages.js +++ b/src/api/merchImages.js @@ -1,6 +1,10 @@ import { apiClient } from '@/services/apiClient.js' +import { useAuthStore } from '@/stores/authStore.js' +import { IMAGE_STORAGE_URL } from '@/main.js' export const useMerchImagesApi = () => { + const authStore = useAuthStore() + const uploadImage = async (uuid, file) => { const formData = new FormData() formData.append('file', file) @@ -13,28 +17,30 @@ export const useMerchImagesApi = () => { throw new Error(`Upload failed: ${response.status}`) } - return response.data + const { fullImage, thumbnail } = response.data + + return { + fullImage, + thumbnail, + } } catch (error) { console.error('Upload failed:', error) throw error } } - const getImageUrl = async (uuid, type) => { - try { - const response = await apiClient.get(`/merch/images/${uuid}`, { type }) - console.log(response.data.link) + const getImageUrl = (merchUuid, type = 'full') => { + const userUuid = authStore.userUuid; + if (!userUuid) throw new Error('userUuid not found in store'); - if (response.status !== 200) { - throw new Error(`Get image failed: ${response.status}`) - } - - return response.data.link - } catch (error) { - console.error('Get image failed:', error) - throw error + const allowedTypes = ['full', 'thumbnail']; + if (!allowedTypes.includes(type)) { + throw new Error(`Invalid type: ${type}. Allowed values: ${allowedTypes.join(', ')}`); } - } + + return `${IMAGE_STORAGE_URL}/merchImages/${userUuid}/${merchUuid}?type=${type}`; + }; + const deleteImage = async (uuid) => { try {