@@ -10,7 +10,9 @@ import { format } from "date-fns";
1010import { getChatMessages , createRoom } from "../services/MindsMeshAPI" ;
1111import { v4 as uuidv4 } from "uuid" ;
1212import { PaperClipIcon } from "@heroicons/react/20/solid" ;
13- import { SocketContext } from "../contexts/SocketContext" ;
13+ import { SocketContext } from "../contexts/SocketContext" ;
14+ import { uploadFile as apiUploadFile } from '../services/MindsMeshAPI' ;
15+
1416
1517
1618interface Message {
@@ -236,28 +238,17 @@ const Chat: React.FC<{ chatPartner?: User | null; onClose?: () => void }> = ({
236238 if ( ! chatPartner || ! senderId ) {
237239 return null ;
238240 }
239-
241+
240242 const formData = new FormData ( ) ;
241243 formData . append ( 'file' , file ) ;
242244 formData . append ( 'text' , newMessage ) ;
243245 formData . append ( 'messageId' , uuidv4 ( ) ) ;
244-
246+
245247 try {
246248 setIsUploading ( true ) ;
247- const response = await fetch ( `/api/chat/${ chatPartner . id } /upload` , {
248- method : 'POST' ,
249- headers : {
250- 'Authorization' : `Bearer ${ localStorage . getItem ( 'token' ) } ` ,
251- } ,
252- body : formData ,
253- } ) ;
254-
255- if ( ! response . ok ) {
256- throw new Error ( `Upload failed: ${ response . statusText } ` ) ;
257- }
258-
259- const data = await response . json ( ) ;
260- console . log ( "File upload response:" , data ) ; // Debug log
249+ const data = await apiUploadFile ( chatPartner . id , formData ) ;
250+
251+ console . log ( "File upload response:" , data ) ;
261252 return {
262253 url : data . fileUrl ,
263254 fileName : data . fileName ,
0 commit comments