Skip to content

Commit 6a64fab

Browse files
authored
Merge pull request #1199 from trycompai/claudio/fix-file-upload
[dev] [claudfuen] claudio/fix-file-upload
2 parents 3dc0475 + c92c2c3 commit 6a64fab

3 files changed

Lines changed: 28 additions & 5 deletions

File tree

apps/app/src/actions/files/upload-file.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
'use server';
22

3+
console.log('[uploadFile] Upload action module is being loaded...');
4+
5+
console.log('[uploadFile] Importing auth and logger...');
36
import { BUCKET_NAME, s3Client } from '@/app/s3';
47
import { auth } from '@/utils/auth';
58
import { logger } from '@/utils/logger';
6-
7-
// This log will run as soon as the module is loaded.
8-
logger.info('[uploadFile] Module loaded.');
9-
109
import { GetObjectCommand, PutObjectCommand } from '@aws-sdk/client-s3';
1110
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
1211
import { AttachmentEntityType, AttachmentType, db } from '@db';
1312
import { revalidatePath } from 'next/cache';
1413
import { headers } from 'next/headers';
1514
import { 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+
1727
function mapFileTypeToAttachmentType(fileType: string): AttachmentType {
1828
const type = fileType.split('/')[0];
1929
switch (type) {
@@ -40,7 +50,10 @@ const uploadAttachmentSchema = z.object({
4050
});
4151

4252
export 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;

apps/app/src/app/s3.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { GetObjectCommand, S3Client } from '@aws-sdk/client-s3';
22

3+
console.log('[S3] S3 module is being loaded...');
4+
35
const APP_AWS_REGION = process.env.APP_AWS_REGION;
46
const APP_AWS_ACCESS_KEY_ID = process.env.APP_AWS_ACCESS_KEY_ID;
57
const APP_AWS_SECRET_ACCESS_KEY = process.env.APP_AWS_SECRET_ACCESS_KEY;

apps/app/src/utils/auth.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ export const auth = betterAuth({
4545
database: prismaAdapter(db, {
4646
provider: 'postgresql',
4747
}),
48-
trustedOrigins: ['http://localhost:3000', 'https://app.trycomp.ai', 'https://dev.trycomp.ai'],
48+
baseURL: process.env.BETTER_AUTH_URL,
49+
trustedOrigins: [
50+
'http://localhost:3000',
51+
'https://app.trycomp.ai',
52+
'https://app.staging.trycomp.ai',
53+
],
4954
emailAndPassword: {
5055
enabled: true,
5156
},

0 commit comments

Comments
 (0)