feat: add share pages comments and server actions

This commit is contained in:
2026-08-16 00:58:46 +07:00 Unverified
parent 5bf5d2a2c0
commit 9617d67c7c
14 changed files with 1157 additions and 108 deletions
+32
View File
@@ -0,0 +1,32 @@
import "server-only";
import { eq } from "drizzle-orm";
import { getServerSession } from "next-auth";
import { db } from "@/db";
import { users } from "@/db/schema";
import { getSessionDiscordId, type SessionWithDiscord } from "@/lib/auth/auth";
import { authOptions } from "@/lib/auth/auth-options";
import { ShareHttpError } from "@/lib/share/http-error";
export async function requireShareAuthor() {
const session = await getServerSession(authOptions);
const discordId = getSessionDiscordId(session);
const userId = (session as SessionWithDiscord | null)?.user?.id;
if (!discordId || !userId) {
throw new ShareHttpError("Unauthorized", 401);
}
const [user] = await db
.select({ id: users.id, name: users.name, image: users.image })
.from(users)
.where(eq(users.id, userId))
.limit(1);
if (!user) throw new ShareHttpError("Unauthorized", 401);
return {
userId: user.id,
discordId,
displayName: user.name || session?.user?.name || "Discord user",
avatarUrl: user.image || session?.user?.image || null,
};
}
+4
View File
@@ -0,0 +1,4 @@
export const MAX_SHARE_TEXT_BYTES = 5 * 1024 * 1024;
export const MAX_SHARE_DESCRIPTION_LENGTH = 5_000;
export const MAX_SHARE_COMMENT_LENGTH = 2_000;
export const MAX_SHARE_IMAGE_BYTES = 50 * 1024 * 1024;
+5 -4
View File
@@ -1,9 +1,10 @@
import { validateImageUploadFile } from "@/lib/cdn-images";
import { ShareHttpError } from "@/lib/share/http-error";
export const MAX_SHARE_TEXT_BYTES = 5 * 1024 * 1024;
export const MAX_SHARE_DESCRIPTION_LENGTH = 5_000;
export const MAX_SHARE_COMMENT_LENGTH = 2_000;
import {
MAX_SHARE_COMMENT_LENGTH,
MAX_SHARE_DESCRIPTION_LENGTH,
MAX_SHARE_TEXT_BYTES,
} from "@/lib/share/limits";
export type ValidatedImage = {
bytes: Buffer;