x
This commit is contained in:
1 parent
7cb65bf5e7
commit
512a988d17
21 files changed
+516
-159
No files matched your search
@@ -0,0 +1,42 @@
|
||||
import { Elysia } from "elysia";
|
||||
import prisma from "../lib/prisma";
|
||||
|
||||
export const mediaRoute = new Elysia({ prefix: "/media" })
|
||||
.get("/", async () => {
|
||||
const media = await prisma.media.findMany({
|
||||
orderBy: { createdAt: "desc" }
|
||||
});
|
||||
|
||||
const BACKEND_PUBLIC_URL = process.env.BACKEND_PUBLIC_URL || "http://localhost:3051";
|
||||
|
||||
return media.map(m => ({
|
||||
...m,
|
||||
url: `${BACKEND_PUBLIC_URL}${m.path}`
|
||||
}));
|
||||
})
|
||||
.delete("/:id", async ({ params, set }) => {
|
||||
try {
|
||||
const mediaId = parseInt(params.id);
|
||||
|
||||
const media = await prisma.media.findUnique({
|
||||
where: { id: mediaId }
|
||||
});
|
||||
|
||||
if (!media) {
|
||||
set.status = 404;
|
||||
return { error: "Media not found" };
|
||||
}
|
||||
|
||||
await prisma.media.delete({
|
||||
where: { id: mediaId }
|
||||
});
|
||||
|
||||
// We are not removing the physical file right now, but could be added later if needed.
|
||||
|
||||
return { success: true, message: "Media deleted successfully" };
|
||||
} catch (err) {
|
||||
console.error("[Media] Delete Error:", err);
|
||||
set.status = 500;
|
||||
return { error: "Failed to delete media" };
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user