diff --git a/app/share/all/page.tsx b/app/share/all/page.tsx deleted file mode 100644 index 23615db..0000000 --- a/app/share/all/page.tsx +++ /dev/null @@ -1,182 +0,0 @@ -import Link from "next/link"; -import { desc, sql } from "drizzle-orm"; -import { ArrowUpRight, Plus } from "lucide-react"; -import { Badge } from "@/components/ui/badge"; -import { Button } from "@/components/ui/button"; -import { - Card, - CardContent, - CardDescription, - CardHeader, - CardTitle, -} from "@/components/ui/card"; -import { - Table, - TableBody, - TableCell, - TableHead, - TableHeader, - TableRow, -} from "@/components/ui/table"; -import { db } from "@/db"; -import { shareTexts } from "@/db/schema"; - -export const dynamic = "force-dynamic"; - -function formatBangkok(date: Date) { - return new Intl.DateTimeFormat("en-GB", { - dateStyle: "medium", - timeStyle: "short", - timeZone: "Asia/Bangkok", - }).format(date); -} - -export default async function AllSharesPage() { - const shares = await db - .select({ - id: shareTexts.id, - authorName: shareTexts.authorName, - source: shareTexts.source, - description: shareTexts.description, - contentPreview: sql`left(${shareTexts.content}, 160)`, - createdAt: shareTexts.createdAt, - }) - .from(shareTexts) - .orderBy(desc(shareTexts.createdAt)); - - return ( -
-
-
-

Share

-

- {shares.length.toLocaleString("th-TH")} ลิงก์สาธารณะ -

-
- -
- - - - ข้อความที่แชร์ทั้งหมด - - เลือกข้อความเพื่อเปิดหน้าสาธารณะ - - - -
- - - - Share - Preview - Author - Source - Created - Open - - - - {shares.length === 0 ? ( - - - ยังไม่มีข้อความที่แชร์ - - - ) : ( - shares.map((share) => ( - - - - {share.id} - - - -

- {share.description || share.contentPreview} -

-
- {share.authorName} - - - {share.source === "bot" ? "Bot" : "Web"} - - - {formatBangkok(share.createdAt)} - - - -
- )) - )} -
-
-
- -
- {shares.length === 0 ? ( -

- ยังไม่มีข้อความที่แชร์ -

- ) : ( - shares.map((share) => ( - - - - {share.id} - - - {share.authorName} · {formatBangkok(share.createdAt)} - - - -

- {share.description || share.contentPreview} -

-
- - {share.source === "bot" ? "Bot" : "Web"} - - -
-
-
- )) - )} -
-
-
-
- ); -} diff --git a/lib/leaderboard/database.ts b/lib/leaderboard/database.ts index 76dad9f..27010dd 100644 --- a/lib/leaderboard/database.ts +++ b/lib/leaderboard/database.ts @@ -69,6 +69,29 @@ export async function getXpLeaderboardPage( return buildXpLeaderboard(rows, requestedPage, searchQuery); } +export async function getMemberXpStats(userId: string) { + const database = getLeaderboardDatabase(); + const [sourceRows, leaderboard] = await Promise.all([ + database + .select({ + level: userLevels.level, + totalXp: userLevels.xp, + }) + .from(userLevels) + .where(eq(userLevels.userId, userId)) + .limit(1), + getXpLeaderboardPage(1, userId), + ]); + const rankedRow = leaderboard.rows.find((row) => row.userId === userId); + const sourceRow = sourceRows[0]; + + return { + level: sourceRow?.level ?? 0, + totalXp: sourceRow?.totalXp ?? "0", + rank: rankedRow?.rank ?? null, + }; +} + export async function getVoiceLeaderboardPage( currentChannelIds: string[], requestedPage: number, @@ -108,3 +131,21 @@ export async function getVoiceLeaderboardPage( searchQuery, ); } + +export async function getMemberVoiceStats( + userId: string, + currentChannelIds: string[], +) { + const leaderboard = await getVoiceLeaderboardPage( + currentChannelIds, + 1, + undefined, + userId, + ); + const rankedRow = leaderboard.rows.find((row) => row.userId === userId); + + return { + totalSeconds: rankedRow?.totalSeconds ?? "0", + rank: rankedRow?.rank ?? null, + }; +} diff --git a/next.config.ts b/next.config.ts index 752cb84..7e02640 100644 --- a/next.config.ts +++ b/next.config.ts @@ -11,7 +11,7 @@ const nextConfig: NextConfig = { root: __dirname, }, serverExternalPackages: ["bun"], - allowedDevOrigins: ['test.gunshiz.top'], + allowedDevOrigins: ['test.gunshiz.top', 'astral.neko-piranha.ts.net'], images: { remotePatterns: [ { @@ -21,19 +21,7 @@ const nextConfig: NextConfig = { { protocol: 'https', hostname: 'cdn.discordapp.com', - }, - { - protocol: 'https', - hostname: 'p16-sign-sg.tiktokcdn.com', - }, - { - protocol: 'https', - hostname: 'p16-sign.tiktokcdn-us.com', - }, - { - protocol: 'https', - hostname: '*.tiktokcdn.com', - }, + } ], }, };