File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
import { getSessionAccessToken, verifySession } from '@/lib/auth/dal';
import { backendFetchStream } from '@/lib/http/backend-fetch';
const QUIZ_EXCEL_PATH = '/api/v1/mngr/cntntns/quiz/excel/download';
const EXCEL_TIMEOUT_MS = 60_000;
const DOWNLOAD_FAILED_MESSAGE =
'엑셀 파일을 내려받지 못했습니다. 잠시 후 다시 시도해 주세요.';
const XLSX_CONTENT_TYPE =
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
export async function GET() {
await verifySession();
const accessToken = await getSessionAccessToken();
const result = await backendFetchStream(QUIZ_EXCEL_PATH, {
accessToken: accessToken ?? undefined,
timeoutMs: EXCEL_TIMEOUT_MS,
});
if (!result.ok) {
return new Response(DOWNLOAD_FAILED_MESSAGE, {
status: 502,
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
});
}
const upstream = result.data;
return new Response(upstream.body, {
status: 200,
headers: {
'Content-Type': upstream.headers.get('content-type') ?? XLSX_CONTENT_TYPE,
'Content-Disposition':
upstream.headers.get('content-disposition') ??
'attachment; filename="quizzes.xlsx"',
},
});
}