feat : big update
CI / Verify (push) Successful in 3m14s
CI / Build immutable images and deploy (push) Successful in 4m0s

This commit is contained in:
2026-10-01 18:37:15 +07:00 Unverified
parent c5037154cb
commit 0022625edb
76 changed files with 18671 additions and 29 deletions
@@ -0,0 +1,32 @@
import { and, eq } from "drizzle-orm";
import * as z from "zod";
import { getDb } from "@/db";
import { commissionMessages, commissionTickets } from "@/db/schema";
import { notifyCommission } from "@/lib/commission/server";
import { authorizeTicket } from "@/lib/commission/tickets";
import { getMediaStorage } from "@/lib/media/storage";
import { errorResponse, HttpError, requireSameOrigin } from "@/lib/security/http";
import { limitRequest } from "@/lib/security/rate-limit";
export async function DELETE(request: Request,
context: RouteContext<"/api/commission/tickets/[id]/messages/[messageId]">) {
try {
requireSameOrigin(request);
const { id, messageId } = await context.params;
if (!z.uuid().safeParse(messageId).success) throw new HttpError(404, "message-not-found");
const { ticket, user } = await authorizeTicket(id);
await limitRequest("commission-message-delete", user.id, 30);
const imageObjectKey = await getDb().transaction(async (tx) => {
const [message] = await tx.delete(commissionMessages)
.where(and(eq(commissionMessages.id, messageId), eq(commissionMessages.ticketId, id),
eq(commissionMessages.authorId, user.id)))
.returning({ imageObjectKey: commissionMessages.imageObjectKey });
if (!message) throw new HttpError(404, "message-not-found");
await tx.update(commissionTickets).set({ updatedAt: new Date() }).where(eq(commissionTickets.id, id));
return message.imageObjectKey;
});
if (imageObjectKey) await (await getMediaStorage()).delete(imageObjectKey).catch(() => undefined);
await notifyCommission(id, ticket.userId);
return new Response(null, { status: 204 });
} catch (cause) { return errorResponse(cause); }
}