From 673119679e4be9aa59456ef09960a74a81005bac Mon Sep 17 00:00:00 2001 From: UltraLionFr Date: Wed, 20 Aug 2025 17:14:23 +0200 Subject: [PATCH] pnpm build --- app/api/auth/[...nextauth]/route.ts | 23 ++----------- app/api/paste/route.ts | 2 +- app/api/stats/route.ts | 2 +- app/api/user-pastes/route.ts | 2 +- app/raw/[id]/route.ts | 10 +++--- lib/auth.ts | 21 ++++++++++++ lib/stats.ts | 49 ++++++++++++++-------------- prisma/altbin.db | Bin 73728 -> 77824 bytes 8 files changed, 56 insertions(+), 53 deletions(-) create mode 100644 lib/auth.ts diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts index 9f3894a..ca0b5b4 100644 --- a/app/api/auth/[...nextauth]/route.ts +++ b/app/api/auth/[...nextauth]/route.ts @@ -1,24 +1,5 @@ -import NextAuth, { NextAuthOptions } from 'next-auth'; -import DiscordProvider from 'next-auth/providers/discord'; - -export const authOptions: NextAuthOptions = { - providers: [ - DiscordProvider({ - clientId: process.env.DISCORD_CLIENT_ID!, - clientSecret: process.env.DISCORD_CLIENT_SECRET!, - }), - ], - callbacks: { - async session({ session, token }) { - if (session.user && token.sub) { - session.user.id = token.sub; - } else { - session.user.id = ''; - } - return session; - }, -} -}; +import { authOptions } from "@/lib/auth"; +import NextAuth from "next-auth"; const handler = NextAuth(authOptions); diff --git a/app/api/paste/route.ts b/app/api/paste/route.ts index a830ff7..1772853 100644 --- a/app/api/paste/route.ts +++ b/app/api/paste/route.ts @@ -1,8 +1,8 @@ +import { authOptions } from '@/lib/auth'; import { prisma } from '@/lib/prisma'; import bcrypt from 'bcryptjs'; import { getServerSession } from 'next-auth'; import { NextResponse } from 'next/server'; -import { authOptions } from '../auth/[...nextauth]/route'; import { customAlphabet } from 'nanoid'; const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz0123456789', 7); diff --git a/app/api/stats/route.ts b/app/api/stats/route.ts index 2ed2489..05bf4e8 100644 --- a/app/api/stats/route.ts +++ b/app/api/stats/route.ts @@ -1,7 +1,7 @@ +import { authOptions } from '@/lib/auth'; import { getDashboardStats } from '@/lib/stats'; import { getServerSession } from 'next-auth'; import { NextResponse } from 'next/server'; -import { authOptions } from '../auth/[...nextauth]/route'; export async function GET() { const session = await getServerSession(authOptions); diff --git a/app/api/user-pastes/route.ts b/app/api/user-pastes/route.ts index d2490f0..7b6b84a 100644 --- a/app/api/user-pastes/route.ts +++ b/app/api/user-pastes/route.ts @@ -1,4 +1,4 @@ -import { authOptions } from '@/app/api/auth/[...nextauth]/route'; +import { authOptions } from '@/lib/auth'; import { prisma } from '@/lib/prisma'; import { getServerSession } from 'next-auth'; import { NextResponse } from 'next/server'; diff --git a/app/raw/[id]/route.ts b/app/raw/[id]/route.ts index 07e696a..f97643f 100644 --- a/app/raw/[id]/route.ts +++ b/app/raw/[id]/route.ts @@ -1,11 +1,11 @@ import { prisma } from "@/lib/prisma"; -import { NextResponse } from "next/server"; +import { NextResponse, type NextRequest } from "next/server"; export async function GET( - request: Request, - { params }: { params: { id: string } } + _req: NextRequest, + { params }: { params: Promise<{ id: string }> } ) { - const { id } = params; + const { id } = await params; if (!id) { return new NextResponse("Invalid ID", { status: 400 }); @@ -22,4 +22,4 @@ export async function GET( "Cache-Control": "no-store", }, }); -} \ No newline at end of file +} diff --git a/lib/auth.ts b/lib/auth.ts new file mode 100644 index 0000000..01b16a3 --- /dev/null +++ b/lib/auth.ts @@ -0,0 +1,21 @@ +import { NextAuthOptions } from "next-auth"; +import DiscordProvider from "next-auth/providers/discord"; + +export const authOptions: NextAuthOptions = { + providers: [ + DiscordProvider({ + clientId: process.env.DISCORD_CLIENT_ID!, + clientSecret: process.env.DISCORD_CLIENT_SECRET!, + }), + ], + callbacks: { + async session({ session, token }) { + if (session.user && token.sub) { + (session.user as { id?: string }).id = token.sub; + } else { + (session.user as { id?: string }).id = ""; + } + return session; + }, + }, +}; diff --git a/lib/stats.ts b/lib/stats.ts index 9f076a4..6af6fd1 100644 --- a/lib/stats.ts +++ b/lib/stats.ts @@ -1,27 +1,28 @@ -import { prisma } from '@/lib/prisma'; +import { prisma } from "@/lib/prisma"; export async function getDashboardStats(userId?: string) { - const filter = userId ? { where: { createdBy: userId } } : {}; + const where = userId ? { createdBy: userId } : undefined; - const [totalPastes, totalViews, recentPastes, apiUsage, storageUsed, avgViews, mostViewed, avgSize] = await Promise.all([ - prisma.paste.count(filter), - prisma.paste.aggregate({ _sum: { views: true }, ...filter }), - prisma.paste.count({ - where: { - createdAt: { gte: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000) }, - ...(userId ? { createdBy: userId } : {}), - }, - }), - prisma.paste.count({ where: { createdBy: { not: null } } }), - prisma.paste.aggregate({ _sum: { size: true }, ...filter }), - prisma.paste.aggregate({ _avg: { views: true }, ...filter }), - prisma.paste.findFirst({ - orderBy: { views: 'desc' }, - select: { views: true }, - ...(userId ? { where: { createdBy: userId } } : {}), - }), - prisma.paste.aggregate({ _avg: { size: true }, ...filter }), - ]); + const [totalPastes, totalViews, recentPastes, apiUsage, storageUsed, avgViews, mostViewed, avgSize] = + await Promise.all([ + prisma.paste.count({ where }), + prisma.paste.aggregate({ _sum: { views: true }, where }), + prisma.paste.count({ + where: { + createdAt: { gte: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000) }, + ...(userId ? { createdBy: userId } : {}), + }, + }), + prisma.paste.count({ where: { createdBy: { not: null } } }), + prisma.paste.aggregate({ _sum: { size: true }, where }), + prisma.paste.aggregate({ _avg: { views: true }, where }), + prisma.paste.findFirst({ + orderBy: { views: "desc" }, + select: { views: true }, + where, + }), + prisma.paste.aggregate({ _avg: { size: true }, where }), + ]); return { totalPastes, @@ -36,9 +37,9 @@ export async function getDashboardStats(userId?: string) { } export async function getUserPastes(userId: string) { - return await prisma.paste.findMany({ + return prisma.paste.findMany({ where: { createdBy: userId }, - orderBy: { createdAt: 'desc' }, + orderBy: { createdAt: "desc" }, select: { id: true, createdAt: true, @@ -47,4 +48,4 @@ export async function getUserPastes(userId: string) { content: true, }, }); -} \ No newline at end of file +} diff --git a/prisma/altbin.db b/prisma/altbin.db index 7094ddf5f503516a5ce23a2c4257cc0d8cf4615e..d3e55a483befbff7fcbd580a712f93fae3cdbf2b 100644 GIT binary patch delta 2074 zcmcgsO>Ep$5Z;CS6bE=h6%ryyOaZBh(As`p@7l?MRB0&^Z9yWZs;c0v{WfdXezyFR zl1i{i1P4S8rP&Y;Jp`!&E|o}fLpdN2h$F{diqKvV5=z8{16&w;cjKg0LQb`I{bbL4 z^UZuSo`vrQ7JeJJF*>+hC=^b93RA`9jdyM<&zvB4@kQYz`Ir1n{vv;p-${quBX>6z zzb|h6O8Y$T8w5r zx9K&=*5x<9`sL>O;Nb9PVR&<6@$2E%jSFOCw6K1mPAmf%$} z=Y+oSxQL@kkhz$XQo~uCo7fSvzy$a~?0C*~-m)PGeLJyYUetBE=!jlW8>|MmnkmB^)?hpFJot5p=K~%gJ@kXRE=M}_ z3fOFmgUw==n_uIChut)z7*8wpLi`w26{?Ou5F^tSP&7<1k8<7-n8EcP3GbJS@vzD? z73nQMi8+i7upk&;dupio^coBmhqBwL859QKyc0$-T=ba@ug_$lPJ0*$|HW}1cwSQPV| z8Z|i{BrkIux&9ZE4n>sH$j5*r5f4jQdR-v$97>a^XtStM^I5pBRWH&BneJC!tL*hE z!-VWwo>kVX(}&WuA=MobdF>gZb(jDz-#3g=gN686*5+}Wxcv@gC+&_9?gkt@tC5Ii zq!`tTu9m8dRaH~9OpThBX&LF#NG}~HHysCrv~tXZQRAvst(59zMs;(dUe(LCZW}a% zRrE}Z6q7@)@mj#FW{K8y!&D8`;(FaKGu9`fYLBMf20w1_5PD^F(}c0O<;ToTr(o~W z$|g)pl9WmeV>8)8NF9QZhg{frvw=m>+Z2{BV%&KWstaT1<^}T{3%#-Zb2tHe09*k! f_n5FxJYW3$XX$oBGbyEIy&@TAxm-0gL#_S?&5G~} delta 103 zcmV-t0GR)P-~@oc1dtmAiU0rr5|JQ30gAC;q%Rf+58VI&000XQ`w#XH@ek||=MUl! z-LZkh0khsQ`V9pyWNCIjlifcj7!D6v01w>{#Sd8zp$~lztq+M0=?`TOm9ri|FAtGW J4zpQLr_dObBlZ9Q