Portofolio

Fix:
- api/mobile/portofolio/[id]/route.ts: tambah put dan delete

File:
Add:
- src/app/api/mobile/file/: upload & delete

### No Issue
This commit is contained in:
2025-09-01 17:14:36 +08:00
parent 2b7694cad1
commit 41bf7ce45c
3 changed files with 237 additions and 11 deletions

View File

@@ -0,0 +1,41 @@
import { NextResponse } from "next/server";
export { DELETE };
async function DELETE(
request: Request,
{ params }: { params: { id: string } }
) {
try {
const { id } = params;
const deleteFile = await fetch(
`https://wibu-storage.wibudev.com/api/files/${id}/delete`,
{
method: "DELETE",
headers: {
Authorization: `Bearer ${process.env.WS_APIKEY}`,
},
}
);
if (deleteFile.ok) {
return NextResponse.json(
{
success: true,
message: "File berhasil dihapus",
},
{ status: 200 }
);
}
} catch (error) {
return NextResponse.json(
{
success: false,
message: "Gagal menghapus file, coba lagi nanti (error: 500)",
reason: (error as Error).message,
},
{ status: 500 }
);
}
}

View File

@@ -0,0 +1,51 @@
import { funGetDirectoryNameByValue } from "@/app_modules/_global/fun/get";
import { NextResponse } from "next/server";
export async function POST(request: Request) {
const formData = await request.formData();
const dirId = formData.get("dirId");
const keyOfDirectory = await funGetDirectoryNameByValue({
value: dirId as string,
});
try {
const res = await fetch("https://wibu-storage.wibudev.com/api/upload", {
method: "POST",
body: formData,
headers: {
Authorization: `Bearer ${process.env.WS_APIKEY}`,
},
});
const dataRes = await res.json();
if (res.ok) {
return NextResponse.json(
{
success: true,
data: dataRes.data,
message: "Success upload file " + keyOfDirectory,
},
{ status: 200 }
);
} else {
const errorText = await res.text();
console.log(`Failed upload ${keyOfDirectory}: ${errorText}`);
return NextResponse.json(
{ success: false, message: errorText },
{ status: 400 }
);
}
} catch (error) {
console.log("Error upload >>", (error as Error).message || error);
return NextResponse.json(
{
success: false,
message: "Failed upload file",
reason: (error as Error).message || error,
},
{ status: 500 }
);
}
}