260806_01_ENH: 이메일 첨부파일 등록 추가
This commit is contained in:
@@ -11,6 +11,19 @@ export const GET = async (req: NextRequest, context: RouteContext) => {
|
||||
const [action] = slug;
|
||||
const notihubApi = await createNotihubApi();
|
||||
|
||||
if(slug.length === 2 && slug[1] === "attachment"){
|
||||
const fileName = searchParams.get("fileName");
|
||||
if (!fileName) {
|
||||
return NextResponse.json({ message: "fileName은 필수입니다." }, { status: 400 });
|
||||
}
|
||||
|
||||
const result = await notihubApi.get<ArrayBuffer>(
|
||||
`/template/${slug[0]}/attachment?fileName=${encodeURIComponent(fileName)}`,
|
||||
{ expectBinary: true },
|
||||
);
|
||||
return new NextResponse(result, { status: 200, headers: { "Content-Type": "application/octet-stream" } });
|
||||
}
|
||||
|
||||
if(slug.length === 1){
|
||||
const result = await notihubApi.get<Template>(
|
||||
`/template/${slug[0]}`,
|
||||
@@ -60,15 +73,15 @@ export const PUT = async (req: NextRequest, context: RouteContext) => {
|
||||
}
|
||||
|
||||
if(!action){
|
||||
const body = await req.json().catch(() => null);
|
||||
if (!body) {
|
||||
const formData = await req.formData().catch(() => null);
|
||||
if (!formData) {
|
||||
return NextResponse.json(
|
||||
{ message: "요청 바디가 없습니다." },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const result = await notihubApi.put<Template>(`/template`, body);
|
||||
const result = await notihubApi.putForm<Template>(`/template`, formData);
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
@@ -86,15 +99,15 @@ export const PATCH = async (req: NextRequest, context: RouteContext) => {
|
||||
const notihubApi = await createNotihubApi();
|
||||
|
||||
if(!action){
|
||||
const body = await req.json().catch(() => null);
|
||||
if (!body) {
|
||||
const formData = await req.formData().catch(() => null);
|
||||
if (!formData) {
|
||||
return NextResponse.json(
|
||||
{ message: "요청 바디가 없습니다." },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const result = await notihubApi.patch<Template>(`/template`, body);
|
||||
const result = await notihubApi.request<Template>(`/template`, { method: "PATCH", form: formData });
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user