refactor(db): migrate app pages and APIs from Prisma facade to Drizzle (5)
Co-authored-by: Cursor <[email protected]>
This commit is contained in:
1 parent
9aa4f331bf
commit
30b54e99e7
40 files changed
+1183
-784
No files matched your search
+14
-9
@@ -1,10 +1,11 @@
|
||||
import { and, eq, gt, or } from "drizzle-orm";
|
||||
import { headers } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { activeBanWhere } from "@/lib/bans";
|
||||
import { unixNow } from "@/lib/bans";
|
||||
import { Ban, db } from "@/lib/db";
|
||||
import { safeRedirect } from "@/lib/foundation/security";
|
||||
import { logger } from "@/lib/logger";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { isIpBlacklisted, recordRequest } from "@/lib/services/abuse-guard";
|
||||
import { siteSettings } from "@/lib/services/site-settings";
|
||||
|
||||
@@ -63,13 +64,17 @@ export async function enforceSiteAccess(): Promise<void> {
|
||||
|
||||
try {
|
||||
if (!target && session?.user?.id) {
|
||||
const ban = await prisma.ban.findFirst({
|
||||
where: {
|
||||
userId: Number(session.user.id),
|
||||
...activeBanWhere(),
|
||||
},
|
||||
select: { id: true },
|
||||
});
|
||||
const now = unixNow();
|
||||
const [ban] = await db
|
||||
.select({ id: Ban.id })
|
||||
.from(Ban)
|
||||
.where(
|
||||
and(
|
||||
eq(Ban.userId, Number(session.user.id)),
|
||||
or(eq(Ban.banExpire, 0), gt(Ban.banExpire, now)),
|
||||
),
|
||||
)
|
||||
.limit(1);
|
||||
if (ban) target = "/banned";
|
||||
}
|
||||
} catch {
|
||||
|
||||
Reference in new issue
Block a user