Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions apps/web/src/apis/image-upload/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export interface UploadProfileImageResponse {
fileUrl: string;
}

export interface UploadChatImageResponse {
fileUrl: string;
}

export interface UploadGpaReportResponse {
fileUrl: string;
}
Expand Down Expand Up @@ -44,17 +48,32 @@ export const imageUploadApi = {
},

/**
* 채팅 이미지 업로드 (로그인 후)
* 프로필 이미지 업로드 (로그인 후)
*/
postUploadProfileImage: async (file: File): Promise<UploadProfileImageResponse> => {
const formData = new FormData();
formData.append("file", file);
const res = await axiosInstance.post<UploadProfileImageResponse>(`/file/chat/post`, formData, {
const res = await axiosInstance.post<UploadProfileImageResponse>(`/file/profile/post`, formData, {
headers: { "Content-Type": "multipart/form-data" },
});
return res.data;
},

/**
* 채팅 이미지 업로드 (로그인 후)
*/
postUploadChatImages: async (files: File[]): Promise<string[]> => {
const formData = new FormData();
files.forEach((file) => {
formData.append("files", file);
});

const res = await axiosInstance.post<UploadChatImageResponse[]>(`/file/chat`, formData, {
headers: { "Content-Type": "multipart/form-data" },
});
return res.data.map((image) => image.fileUrl);
},

/**
* 프로필 이미지 업로드 (회원가입 전, 공개 API)
*/
Expand Down
8 changes: 7 additions & 1 deletion apps/web/src/apis/image-upload/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
export type { UploadGpaReportResponse, UploadLanguageTestReportResponse, UploadProfileImageResponse } from "./api";
export type {
UploadChatImageResponse,
UploadGpaReportResponse,
UploadLanguageTestReportResponse,
UploadProfileImageResponse,
} from "./api";
export { imageUploadApi } from "./api";

export { default as useSlackNotification } from "./postSlackNotification";
export { default as useUploadChatImages } from "./postUploadChatImages";
export { default as useUploadGpaReport } from "./postUploadGpaReport";
export { default as useUploadLanguageTestReport } from "./postUploadLanguageTestReport";
export { default as useUploadProfileImage } from "./postUploadProfileImage";
Expand Down
13 changes: 13 additions & 0 deletions apps/web/src/apis/image-upload/postUploadChatImages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useMutation } from "@tanstack/react-query";
import type { AxiosError } from "axios";
import { SKIP_GLOBAL_ERROR_TOAST_META } from "@/lib/react-query/errorToastMeta";
import { imageUploadApi } from "./api";

const useUploadChatImages = () => {
return useMutation<string[], AxiosError, File[]>({
mutationFn: (files) => imageUploadApi.postUploadChatImages(files),
meta: SKIP_GLOBAL_ERROR_TOAST_META,
});
};

export default useUploadChatImages;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import clsx from "clsx";
import Link from "next/link";
import { toast } from "react-hot-toast";
import { useGetPartnerInfo } from "@/apis/chat";
import { useUploadProfileImage } from "@/apis/image-upload";
import { useUploadChatImages } from "@/apis/image-upload";
import ProfileWithBadge from "@/components/ui/ProfileWithBadge";
import useAuthStore from "@/lib/zustand/useAuthStore";
import { ConnectionStatus } from "@/types/chat";
Expand Down Expand Up @@ -49,7 +49,7 @@ const ChatContent = ({ chatId }: ChatContentProps) => {
addImageMessagePreview,
} = useChatListHandler(chatId);

const uploadProfileImageMutation = useUploadProfileImage();
const uploadChatImagesMutation = useUploadChatImages();

const { data: partnerInfo } = useGetPartnerInfo(chatId);

Expand Down Expand Up @@ -181,11 +181,7 @@ const ChatContent = ({ chatId }: ChatContentProps) => {
}}
onSendImages={async (data) => {
try {
const uploadedImages = await Promise.all(
data.images.map((image) => uploadProfileImageMutation.mutateAsync(image)),
);

const imageUrls = uploadedImages.map((image) => image.fileUrl);
const imageUrls = await uploadChatImagesMutation.mutateAsync(data.images);
const isSent = sendImageMessage(imageUrls);

if (!isSent) {
Expand Down
Loading