11'use server' ;
22
3+ console . log ( '[uploadFile] Upload action module is being loaded...' ) ;
4+
5+ console . log ( '[uploadFile] Importing auth and logger...' ) ;
36import { BUCKET_NAME , s3Client } from '@/app/s3' ;
47import { auth } from '@/utils/auth' ;
58import { logger } from '@/utils/logger' ;
6-
7- // This log will run as soon as the module is loaded.
8- logger . info ( '[uploadFile] Module loaded.' ) ;
9-
109import { GetObjectCommand , PutObjectCommand } from '@aws-sdk/client-s3' ;
1110import { getSignedUrl } from '@aws-sdk/s3-request-presigner' ;
1211import { AttachmentEntityType , AttachmentType , db } from '@db' ;
1312import { revalidatePath } from 'next/cache' ;
1413import { headers } from 'next/headers' ;
1514import { z } from 'zod' ;
1615
16+ console . log ( '[uploadFile] Importing S3 client...' ) ;
17+
18+ console . log ( '[uploadFile] Importing AWS SDK...' ) ;
19+
20+ console . log ( '[uploadFile] Importing database...' ) ;
21+
22+ console . log ( '[uploadFile] All imports successful' ) ;
23+
24+ // This log will run as soon as the module is loaded.
25+ logger . info ( '[uploadFile] Module loaded.' ) ;
26+
1727function mapFileTypeToAttachmentType ( fileType : string ) : AttachmentType {
1828 const type = fileType . split ( '/' ) [ 0 ] ;
1929 switch ( type ) {
@@ -40,7 +50,10 @@ const uploadAttachmentSchema = z.object({
4050} ) ;
4151
4252export const uploadFile = async ( input : z . infer < typeof uploadAttachmentSchema > ) => {
53+ console . log ( '[uploadFile] Function called - starting execution' ) ;
4354 logger . info ( `[uploadFile] Starting upload for ${ input . fileName } ` ) ;
55+
56+ console . log ( '[uploadFile] Checking S3 client availability' ) ;
4457 try {
4558 // Check if S3 client is available
4659 if ( ! s3Client ) {
@@ -59,9 +72,11 @@ export const uploadFile = async (input: z.infer<typeof uploadAttachmentSchema>)
5972 } as const ;
6073 }
6174
75+ console . log ( '[uploadFile] Parsing input schema' ) ;
6276 const { fileName, fileType, fileData, entityId, entityType, pathToRevalidate } =
6377 uploadAttachmentSchema . parse ( input ) ;
6478
79+ console . log ( '[uploadFile] Getting user session' ) ;
6580 const session = await auth . api . getSession ( { headers : await headers ( ) } ) ;
6681 const organizationId = session ?. session . activeOrganizationId ;
6782
@@ -75,6 +90,7 @@ export const uploadFile = async (input: z.infer<typeof uploadAttachmentSchema>)
7590
7691 logger . info ( `[uploadFile] Starting upload for ${ fileName } in org ${ organizationId } ` ) ;
7792
93+ console . log ( '[uploadFile] Converting file data to buffer' ) ;
7894 const fileBuffer = Buffer . from ( fileData , 'base64' ) ;
7995
8096 const MAX_FILE_SIZE_MB = 10 ;
0 commit comments