Files
Mayne0213 e82ea71c22 REFACTOR(repo): simplify project structure
- Move services/nextjs to nextjs/
- Move deploy/docker/Dockerfile.prod to Dockerfile
- Add GitHub Actions workflows (ci.yml, build.yml)
- Remove deploy/, services/, scripts/ folders
2026-01-05 02:29:10 +09:00

47 lines
1.2 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server';
import { GetObjectCommand } from '@aws-sdk/client-s3';
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
import { S3_CONFIG, s3Client } from '@/shared/config/s3';
// 파일 다운로드 URL 생성
const generateDownloadUrl = async (fileKey: string): Promise<string> => {
try {
const command = new GetObjectCommand({
Bucket: S3_CONFIG.BUCKET_NAME,
Key: fileKey,
});
const downloadUrl = await getSignedUrl(s3Client, command, { expiresIn: 3600 });
return downloadUrl;
} catch (error) {
throw new Error('다운로드 URL 생성에 실패했습니다.');
}
};
export async function POST(request: NextRequest) {
try {
const body = await request.json();
const { fileKey } = body;
if (!fileKey) {
return NextResponse.json(
{ error: 'fileKey가 필요합니다.' },
{ status: 400 }
);
}
const downloadUrl = await generateDownloadUrl(fileKey);
return NextResponse.json({
downloadUrl,
});
} catch (error: any) {
return NextResponse.json(
{ error: error.message || '다운로드 URL 생성에 실패했습니다.' },
{ status: 500 }
);
}
}