TierList visuals complete

Co-authored-by: Gunshin <[email protected]>
Co-authored-by: S4mSh1ne <[email protected]>
This commit is contained in:
Dreamgineer
2025-10-02 18:10:39 -04:00
co-authored by Gunshin S4mSh1ne
Unverified
parent ca652d273d
commit b66212acf8
27 changed files with 817 additions and 183 deletions
+45 -2
View File
@@ -1,6 +1,7 @@
"use server";
import { eq, inArray, not, sql } from "drizzle-orm";
import type { PgColumn, PgTable } from "drizzle-orm/pg-core";
import { revalidatePath } from "next/cache";
import { redirect } from "next/navigation";
import { apiAuthCheck } from "./auth";
@@ -77,6 +78,7 @@ export async function toggleCheck(submissionId: string) {
})
.where(eq(submissions.id, submissionId));
revalidatePath("/artifact/admin");
revalidatePath("/artifact");
}
export async function toggleLock() {
@@ -93,7 +95,7 @@ export async function toggleLock() {
)
await db.insert(artifactSettings).values({ locked: true });
revalidatePath("/artifact/admin");
revalidatePath("/");
revalidatePath("/artifact");
}
export async function setLimit(limit: number) {
@@ -111,7 +113,7 @@ export async function setLimit(limit: number) {
)
await db.insert(artifactSettings).values({ limit });
revalidatePath("/artifact/admin");
revalidatePath("/");
revalidatePath("/artifact");
}
export async function wipe() {
@@ -121,6 +123,7 @@ export async function wipe() {
sql`ALTER SEQUENCE artifact.submissions_queue_seq RESTART WITH 1`,
);
revalidatePath("/artifact/admin");
revalidatePath("/artifact");
redirect("/artifact/admin");
}
@@ -135,3 +138,43 @@ export async function random() {
if (sub) redirect(`/artifact/admin/${sub.id}`);
else throw "ไม่พบผู้ลงทะเบียนที่ยังไม่ตรวจสอบ";
}
export async function reorder(
table: PgTable & { id: PgColumn; order: PgColumn },
id: string,
position: number,
) {
await db
.update(table)
.set({
order: sql`
(
SELECT (prev_order + next_order) / 2
FROM (
SELECT "order",
lag("order") OVER (ORDER BY "order") AS prev_order,
lead("order") OVER (ORDER BY "order") AS next_order,
row_number() OVER (ORDER BY "order") AS rn
FROM ${table}
) sub
WHERE rn = ${position}
)
`,
})
.where(eq(table.id, id));
}
export async function untangle(
table: PgTable & { id: PgColumn; order: PgColumn },
) {
await db.execute(sql`
WITH ordered AS (
SELECT id, row_number() OVER (ORDER BY "order") * 10 AS new_order
FROM ${table}
)
UPDATE ${table} t
SET "order" = o.new_order
FROM ordered o
WHERE t.id = o.id;
`);
}
+8 -3
View File
@@ -7,9 +7,14 @@ import * as schema from "$/db/schema";
export const auth = betterAuth({
emailAndPassword: {
enabled: true,
// disableSignUp: true,
disableSignUp: true,
},
trustedOrigins: ["http://nyx:3000"],
trustedOrigins: [
"http://nyx:3000",
"http://astral:3000",
"http://localhost:3000",
"https://dev3000.dgnr.us",
],
database: drizzleAdapter(db, {
provider: "pg", // or "mysql", "sqlite"
schema,
@@ -23,7 +28,7 @@ export async function apiAuthCheck() {
headers: await headers(),
});
console.log(session);
// console.log(session);
return session?.user;
}
+23 -14
View File
@@ -1,14 +1,15 @@
import {
type AnyPgColumn,
boolean,
date,
integer,
pgEnum,
pgSchema,
pgTable,
serial,
text,
timestamp,
type AnyPgColumn,
boolean,
date,
integer,
numeric,
pgEnum,
pgSchema,
pgTable,
serial,
text,
timestamp,
} from "drizzle-orm/pg-core";
import { uuidv7 } from "uuidv7";
import { bytea } from "./custom";
@@ -27,6 +28,7 @@ export const element = pgEnum("character_element", [
export const cdn = pgTable("cdn", {
id: text().primaryKey().$defaultFn(uuidv7),
data: bytea().notNull(),
name: text(),
type: text().notNull(),
size: text().notNull(),
});
@@ -50,6 +52,7 @@ export const characters = pgTable("characters", {
.references(() => cdn.id),
weapon: text().notNull(),
amber: text().notNull(), // Amber character ID
order: numeric().notNull(),
});
export const versions = pgTable("versions", {
@@ -95,27 +98,30 @@ export const tierlist = pgSchema("tierlist");
export const tierlistTypes = tierlist.table("types", {
id: text().primaryKey().$defaultFn(uuidv7),
name: text().notNull(),
image: text()
.notNull()
.references(() => cdn.id),
image: text().references(() => cdn.id),
order: numeric().notNull(),
});
export const tierlistTiers = tierlist.table("tiers", {
id: text().primaryKey().$defaultFn(uuidv7),
name: text().notNull(),
badges: text().references(()=>tierlistBadges.id).array(),
image: text().references(() => cdn.id),
order: numeric().notNull(),
});
export const tierlistColumns = tierlist.table("columns", {
id: text().primaryKey().$defaultFn(uuidv7),
name: text().notNull(),
image: text().references(() => cdn.id),
order: numeric().notNull(),
});
export const tierlistBadges = tierlist.table("badges", {
id: text().primaryKey().$defaultFn(uuidv7),
name: text().notNull(),
image: text().references(() => cdn.id),
order: numeric().notNull(),
});
export const tierlistVersions = tierlist.table("versions", {
@@ -126,6 +132,8 @@ export const tierlistVersions = tierlist.table("versions", {
.notNull()
.references(() => tierlistTypes.id),
image: text().references(() => cdn.id),
from: text().notNull().references(()=>versions.id),
order: numeric().notNull(),
});
export const tierlistStates = tierlist.table("states", {
@@ -138,7 +146,7 @@ export const tierlistStates = tierlist.table("states", {
.references(() => tierlistVersions.id),
tier: text()
.notNull()
.references(() => tierlistVersions.id),
.references(() => tierlistTiers.id),
column: text()
.notNull()
.references(() => tierlistColumns.id),
@@ -147,6 +155,7 @@ export const tierlistStates = tierlist.table("states", {
.references(() => tierlistBadges.id)
.array(4)
.default([]),
order: numeric().notNull(),
});
//#endregion
+1 -1
View File
@@ -92,4 +92,4 @@ export class EventSourceManager {
}
}
export const sse = new EventSourceManager();
export const sse = new EventSourceManager();