diff --git a/app/api/drive/files/route.ts b/app/api/drive/files/route.ts index 1645d58..c41c7b0 100644 --- a/app/api/drive/files/route.ts +++ b/app/api/drive/files/route.ts @@ -7,8 +7,6 @@ import File from '@/models/File'; import { authOptions } from '../../auth/[...nextauth]/authOptions'; import { UserDataTypes } from '../../auth/[...nextauth]/next-auth.interfaces'; -const Bucket = process.env.AWS_BUCKET_NAME as string; - const s3Client = new S3Client({ region: process.env.AWS_REGION as string, credentials: { @@ -71,12 +69,14 @@ export async function PUT(req: NextRequest) { let link = null; if (fl?.link) { const input = { - Bucket, - CopySource: `${Bucket}/${fl.link}`, + Bucket: 'dream-by-vishal', + CopySource: `dream-by-vishal/${fl.link}`, Key: encodeURI(`${body?.parent}/${fl?.name}`), }; await s3Client.send(new CopyObjectCommand(input)); - await s3Client.send(new DeleteObjectCommand({ Bucket, Key: encodeURI(fl.link) })); + await s3Client.send( + new DeleteObjectCommand({ Bucket: 'dream-by-vishal', Key: encodeURI(fl.link) }) + ); link = encodeURI(`${body?.parent}/${fl?.name}`); } const input = { @@ -96,7 +96,10 @@ export async function PUT(req: NextRequest) { const deleteAllChilds = async (fl: any) => { if (fl?.link) { await s3Client.send( - new DeleteObjectCommand({ Bucket, Key: encodeURI(`${fl?.parent}/${fl?.name}`) }) + new DeleteObjectCommand({ + Bucket: 'dream-by-vishal', + Key: encodeURI(`${fl?.parent}/${fl?.name}`), + }) ); } await fl?.deleteOne(); diff --git a/app/api/drive/files/upload/route.ts b/app/api/drive/files/upload/route.ts index ccef6ff..c851693 100644 --- a/app/api/drive/files/upload/route.ts +++ b/app/api/drive/files/upload/route.ts @@ -10,8 +10,6 @@ import File from '@/models/File'; export const maxDuration = 60; export const dynamic = 'force-dynamic'; -const Bucket = process.env.AWS_BUCKET_NAME as string; - const s3Client = new S3Client({ region: process.env.AWS_REGION as string, credentials: { @@ -36,7 +34,7 @@ export async function POST(req: Request) { files.map(async (file) => { const Body = (await file.arrayBuffer()) as Buffer; const Key = encodeURI(parent ? `${parent}/${file.name}` : file.name); - await s3Client.send(new PutObjectCommand({ Bucket, Key, Body })); + await s3Client.send(new PutObjectCommand({ Bucket: 'dream-by-vishal', Key, Body })); await File.create({ user: session?.user._id, parent, @@ -61,7 +59,7 @@ export async function GET(req: NextRequest) { } await startDb(); const Key = req.nextUrl.searchParams.get('Key') || ''; - const command = new GetObjectCommand({ Bucket, Key }); + const command = new GetObjectCommand({ Bucket: 'dream-by-vishal', Key }); const src = await getSignedUrl(s3Client, command, { expiresIn: 3600 }); return NextResponse.json(src, { status: 200 }); } catch (error: any) { diff --git a/app/api/upload/route.ts b/app/api/upload/route.ts index bcfc855..f5f178e 100644 --- a/app/api/upload/route.ts +++ b/app/api/upload/route.ts @@ -24,7 +24,7 @@ async function uploadImageToS3(file: Buffer, name: string) { Key: name, Body: fileBuffer, ACL: ObjectCannedACL.public_read, - Bucket: process.env.AWS_BUCKET_NAME, + Bucket: 'dream-by-vishal', ContentType: 'image/*', }; const command = new PutObjectCommand(params);