This commit is contained in:
superdinmc
2025-11-14 17:23:58 +07:00 Unverified
parent 6c0fda2b86
commit 27b8336295
8 changed files with 301 additions and 21 deletions
+11 -4
View File
@@ -5,6 +5,7 @@ import type { PgDatabase } from "drizzle-orm/pg-core";
import { revalidatePath } from "next/cache";
import { redirect } from "next/navigation";
import { after } from "next/server";
import type { TypedFormData } from "@/app/(ui)/endgame/type";
import { apiAuthCheck } from "./auth";
import { uidRegex } from "./const";
import { db } from "./db";
@@ -36,11 +37,17 @@ export async function getArtifactConfig() {
}
export async function submitArtifact(formData: FormData) {
const form = formData as unknown as TypedFormData<{
name: string;
uid: string;
character: string;
comment: string;
}>;
const config = await getArtifactConfig();
const name = formData.get("name")?.toString();
const uid = formData.get("uid")?.toString();
const character = formData.get("character")?.toString();
const comment = formData.get("comment")?.toString() || "";
const name = form.get("name")?.toString();
const uid = form.get("uid")?.toString();
const character = form.get("character")?.toString();
const comment = form.get("comment")?.toString() || "";
if (!name || !uid || !character) return "กรุณากรอกข้อมูลให้ครบถ้วน";
if (name.length > 32) return "ชื่อยาวเกินไป ต้องไม่เกิน 32 ตัวอักษร";
if (!uidRegex.test(uid)) return "UID ไม่ถูกต้อง ต้องเป็นเลข 9 หลัก";
+1 -1
View File
@@ -38,5 +38,5 @@ export async function apiAuthCheck() {
// console.log(session);
return session?.user;
return session?.user.role === "admin" ? session.user : null;
}
+6 -7
View File
@@ -109,13 +109,7 @@ export const endgameSubmissions = endgame.table("submissions", {
id: text().primaryKey().$defaultFn(uuidv7),
name: text().notNull(),
user: text().notNull(),
slip: bytea().notNull(),
char: text()
.notNull()
.references(() => characters.name, {
onDelete: "cascade",
onUpdate: "cascade",
}),
expires: timestamp().$defaultFn(() => new Date(Date.now() + 15 * 60 * 1000)), // 15 minutes to pay
queue: serial(),
checked: boolean().notNull().default(false),
});
@@ -244,6 +238,10 @@ export const user = pgTable("user", {
.defaultNow()
.$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(),
role: text("role"),
banned: boolean("banned").default(false),
banReason: text("ban_reason"),
banExpires: timestamp("ban_expires"),
});
export const session = pgTable("session", {
@@ -259,6 +257,7 @@ export const session = pgTable("session", {
userId: text("user_id")
.notNull()
.references(() => user.id, { onDelete: "cascade" }),
impersonatedBy: text("impersonated_by"),
});
export const account = pgTable("account", {