今天做了好多工作啊
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2025-12-04 21:07:54 +08:00
parent fcc20fc2e0
commit 41005a4aac
27 changed files with 733 additions and 6294 deletions

View File

@@ -1,24 +1,24 @@
"use server";
import { redirect } from "next/navigation";
import { getServerSession } from "next-auth";
import { getTranslations } from "next-intl/server";
import {
getFoldersWithTotalPairsByOwner,
getOwnerByFolderId,
getFoldersWithTotalPairsByUserId,
getUserIdByFolderId,
} from "@/lib/actions/services/folderService";
import { isNonNegativeInteger } from "@/lib/utils";
import FolderSelector from "./FolderSelector";
import Memorize from "./Memorize";
import { getTextPairsByFolderId } from "@/lib/actions/services/textPairService";
import { getPairsByFolderId } from "@/lib/actions/services/pairService";
import { auth } from "@/auth";
export default async function MemorizePage({
searchParams,
}: {
searchParams: Promise<{ folder_id?: string }>;
}) {
const session = await getServerSession();
const username = session?.user?.name;
const session = await auth();
const userId = session?.user?.id;
const t = await getTranslations("memorize.page");
const tParam = (await searchParams).folder_id;
@@ -28,23 +28,26 @@ export default async function MemorizePage({
: null
: null;
if (!username)
if (!userId) {
redirect(
`/login?redirect=/memorize${folder_id ? `?folder_id=${folder_id}` : ""}`,
);
}
const uid = Number(userId);
if (!folder_id) {
return (
<FolderSelector
folders={await getFoldersWithTotalPairsByOwner(username)}
folders={await getFoldersWithTotalPairsByUserId(uid)}
/>
);
}
const owner = await getOwnerByFolderId(folder_id);
if (owner !== username) {
const owner = await getUserIdByFolderId(folder_id);
if (owner !== uid) {
return <p>{t("unauthorized")}</p>;
}
return <Memorize textPairs={await getTextPairsByFolderId(folder_id)} />;
return <Memorize textPairs={await getPairsByFolderId(folder_id)} />;
}