From 090c6ae918d68b60ed85a09e71ada0c46e9c4e3e Mon Sep 17 00:00:00 2001 From: myeongheonhong Date: Wed, 23 Aug 2023 17:46:18 +0900 Subject: [PATCH] =?UTF-8?q?[=20fix=20]=20=EC=84=9C=EB=B2=84=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=20api=20=EC=A4=84=EC=9D=B4=EA=B8=B0=20=EC=9C=84?= =?UTF-8?q?=ED=95=B4=20=ED=86=B5=ED=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/wishes/getPresignedURL.ts | 17 ----------------- api/wishes/uploadPresignedURL.ts | 13 ------------- api/wishes/wishesAPI.ts | 28 ++++++++++++++++++++++++++++ hooks/wishes/useUploadItemInfo.ts | 3 +-- hooks/wishes/useUploadItemInfo.tsx | 21 --------------------- 5 files changed, 29 insertions(+), 53 deletions(-) delete mode 100644 api/wishes/getPresignedURL.ts delete mode 100644 api/wishes/uploadPresignedURL.ts delete mode 100644 hooks/wishes/useUploadItemInfo.tsx diff --git a/api/wishes/getPresignedURL.ts b/api/wishes/getPresignedURL.ts deleted file mode 100644 index d4d85252..00000000 --- a/api/wishes/getPresignedURL.ts +++ /dev/null @@ -1,17 +0,0 @@ -import PATH from '@/constant/path'; -import { client } from '../common/axios'; - -export const getPresignedURL = async (fileName: string | undefined) => { - const accessToken = localStorage.getItem('accessToken'); - const data = await client.get( - `${PATH.API}/${PATH.V1}/${PATH.FILE}?${PATH.FILE_NAME}=${fileName}`, - { - headers: { - 'Content-Type': 'application/json', - Authorization: `Bearer ${accessToken}`, - }, - }, - ); - - return data; -}; diff --git a/api/wishes/uploadPresignedURL.ts b/api/wishes/uploadPresignedURL.ts deleted file mode 100644 index 7af5fff1..00000000 --- a/api/wishes/uploadPresignedURL.ts +++ /dev/null @@ -1,13 +0,0 @@ -import axios from 'axios'; - -export const uploadPresignedURL = async (signedURL: string, file: File | Blob | null) => { - console.log(decodeURIComponent(signedURL)); - const data = await axios.put(signedURL, file, { - headers: { - 'Content-Type': file?.type, - }, - }); - - console.log(data); - return data; -}; diff --git a/api/wishes/wishesAPI.ts b/api/wishes/wishesAPI.ts index 9787db6c..c188a133 100644 --- a/api/wishes/wishesAPI.ts +++ b/api/wishes/wishesAPI.ts @@ -3,6 +3,7 @@ import PATH from '../../constant/path'; import { client } from '../common/axios'; import { WishesDataType } from '@/types/wishes/wishesDataType'; import { PARSING_TAG_KEY } from '@/constant/parsingTagKey'; +import axios from 'axios'; export const createWishesLink = async (wishesData: WishesDataType) => { const accessToken = localStorage.getItem('accessToken'); @@ -89,3 +90,30 @@ export const getUserAccount = async () => { }); return data?.data; }; + +export const getPresignedURL = async (fileName: string | undefined) => { + const accessToken = localStorage.getItem('accessToken'); + const data = await client.get( + `${PATH.API}/${PATH.V1}/${PATH.FILE}?${PATH.FILE_NAME}=${fileName}`, + { + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${accessToken}`, + }, + }, + ); + + return data; +}; + +export const uploadPresignedURL = async (signedURL: string, file: File | Blob | null) => { + console.log(decodeURIComponent(signedURL)); + const data = await axios.put(signedURL, file, { + headers: { + 'Content-Type': file?.type, + }, + }); + + console.log(data); + return data; +}; diff --git a/hooks/wishes/useUploadItemInfo.ts b/hooks/wishes/useUploadItemInfo.ts index 68724eb1..eb27cb06 100644 --- a/hooks/wishes/useUploadItemInfo.ts +++ b/hooks/wishes/useUploadItemInfo.ts @@ -1,5 +1,4 @@ -import { getPresignedURL } from '@/api/wishes/getPresignedURL'; -import { uploadPresignedURL } from '@/api/wishes/uploadPresignedURL'; +import { getPresignedURL, uploadPresignedURL } from '@/api/wishes/wishesAPI'; import { QUERY_KEY } from '@/constant/queryKey'; import { useEffect, useState } from 'react'; import { useMutation, useQuery } from 'react-query'; diff --git a/hooks/wishes/useUploadItemInfo.tsx b/hooks/wishes/useUploadItemInfo.tsx deleted file mode 100644 index 6f602cec..00000000 --- a/hooks/wishes/useUploadItemInfo.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import { useState } from 'react'; - -export default function useUploadItemInfo() { - const [imageFile, setImageFile] = useState(null); - const [previewImage, setPreviewImage] = useState(''); - - function uploadImageFile(e: React.ChangeEvent) { - const imageFile = e.target.files && e.target.files[0]; - - if (imageFile) { - setImageFile(imageFile); - const reader = new FileReader(); - imageFile && reader.readAsDataURL(imageFile); - reader.onloadend = () => { - setPreviewImage(reader.result as string); - }; - } - } - - return { imageFile, previewImage, setPreviewImage, uploadImageFile }; -}