pnpm build
This commit is contained in:
@@ -1,24 +1,5 @@
|
|||||||
import NextAuth, { NextAuthOptions } from 'next-auth';
|
import { authOptions } from "@/lib/auth";
|
||||||
import DiscordProvider from 'next-auth/providers/discord';
|
import NextAuth from "next-auth";
|
||||||
|
|
||||||
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;
|
|
||||||
},
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handler = NextAuth(authOptions);
|
const handler = NextAuth(authOptions);
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
|
import { authOptions } from '@/lib/auth';
|
||||||
import { prisma } from '@/lib/prisma';
|
import { prisma } from '@/lib/prisma';
|
||||||
import bcrypt from 'bcryptjs';
|
import bcrypt from 'bcryptjs';
|
||||||
import { getServerSession } from 'next-auth';
|
import { getServerSession } from 'next-auth';
|
||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
import { authOptions } from '../auth/[...nextauth]/route';
|
|
||||||
|
|
||||||
import { customAlphabet } from 'nanoid';
|
import { customAlphabet } from 'nanoid';
|
||||||
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz0123456789', 7);
|
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz0123456789', 7);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
import { authOptions } from '@/lib/auth';
|
||||||
import { getDashboardStats } from '@/lib/stats';
|
import { getDashboardStats } from '@/lib/stats';
|
||||||
import { getServerSession } from 'next-auth';
|
import { getServerSession } from 'next-auth';
|
||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
import { authOptions } from '../auth/[...nextauth]/route';
|
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
const session = await getServerSession(authOptions);
|
const session = await getServerSession(authOptions);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { authOptions } from '@/app/api/auth/[...nextauth]/route';
|
import { authOptions } from '@/lib/auth';
|
||||||
import { prisma } from '@/lib/prisma';
|
import { prisma } from '@/lib/prisma';
|
||||||
import { getServerSession } from 'next-auth';
|
import { getServerSession } from 'next-auth';
|
||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { prisma } from "@/lib/prisma";
|
import { prisma } from "@/lib/prisma";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse, type NextRequest } from "next/server";
|
||||||
|
|
||||||
export async function GET(
|
export async function GET(
|
||||||
request: Request,
|
_req: NextRequest,
|
||||||
{ params }: { params: { id: string } }
|
{ params }: { params: Promise<{ id: string }> }
|
||||||
) {
|
) {
|
||||||
const { id } = params;
|
const { id } = await params;
|
||||||
|
|
||||||
if (!id) {
|
if (!id) {
|
||||||
return new NextResponse("Invalid ID", { status: 400 });
|
return new NextResponse("Invalid ID", { status: 400 });
|
||||||
@@ -22,4 +22,4 @@ export async function GET(
|
|||||||
"Cache-Control": "no-store",
|
"Cache-Control": "no-store",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+21
@@ -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;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
+25
-24
@@ -1,27 +1,28 @@
|
|||||||
import { prisma } from '@/lib/prisma';
|
import { prisma } from "@/lib/prisma";
|
||||||
|
|
||||||
export async function getDashboardStats(userId?: string) {
|
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([
|
const [totalPastes, totalViews, recentPastes, apiUsage, storageUsed, avgViews, mostViewed, avgSize] =
|
||||||
prisma.paste.count(filter),
|
await Promise.all([
|
||||||
prisma.paste.aggregate({ _sum: { views: true }, ...filter }),
|
prisma.paste.count({ where }),
|
||||||
prisma.paste.count({
|
prisma.paste.aggregate({ _sum: { views: true }, where }),
|
||||||
where: {
|
prisma.paste.count({
|
||||||
createdAt: { gte: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000) },
|
where: {
|
||||||
...(userId ? { createdBy: userId } : {}),
|
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.count({ where: { createdBy: { not: null } } }),
|
||||||
prisma.paste.aggregate({ _avg: { views: true }, ...filter }),
|
prisma.paste.aggregate({ _sum: { size: true }, where }),
|
||||||
prisma.paste.findFirst({
|
prisma.paste.aggregate({ _avg: { views: true }, where }),
|
||||||
orderBy: { views: 'desc' },
|
prisma.paste.findFirst({
|
||||||
select: { views: true },
|
orderBy: { views: "desc" },
|
||||||
...(userId ? { where: { createdBy: userId } } : {}),
|
select: { views: true },
|
||||||
}),
|
where,
|
||||||
prisma.paste.aggregate({ _avg: { size: true }, ...filter }),
|
}),
|
||||||
]);
|
prisma.paste.aggregate({ _avg: { size: true }, where }),
|
||||||
|
]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
totalPastes,
|
totalPastes,
|
||||||
@@ -36,9 +37,9 @@ export async function getDashboardStats(userId?: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getUserPastes(userId: string) {
|
export async function getUserPastes(userId: string) {
|
||||||
return await prisma.paste.findMany({
|
return prisma.paste.findMany({
|
||||||
where: { createdBy: userId },
|
where: { createdBy: userId },
|
||||||
orderBy: { createdAt: 'desc' },
|
orderBy: { createdAt: "desc" },
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
createdAt: true,
|
createdAt: true,
|
||||||
@@ -47,4 +48,4 @@ export async function getUserPastes(userId: string) {
|
|||||||
content: true,
|
content: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user