Skip to content

Commit

Permalink
删帖
Browse files Browse the repository at this point in the history
  • Loading branch information
wxh06 committed Jul 16, 2023
1 parent e0a4142 commit 31299b1
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 30 deletions.
7 changes: 7 additions & 0 deletions packages/viewer/src/app/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ export default function Footer() {
联系我们
</ExternalLink>{" "}
&middot;{" "}
<Link
href="/removal"
className="link-secondary text-decoration-none"
>
删帖政策
</Link>{" "}
&middot;{" "}
<ExternalLink href="https://github.com/piterator-org/luogu-discussion-archive">
<svg
xmlns="http://www.w3.org/2000/svg"
Expand Down
20 changes: 18 additions & 2 deletions packages/viewer/src/app/[id]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ export async function generateMetadata({
const id = parseInt(params.id, 10);
if (Number.isNaN(id)) notFound();
const snapshot = await prisma.snapshot.findFirst({
select: { title: true },
select: { title: true, discussion: { select: { takedown: true } } },
orderBy: { time: "desc" },
where: { discussionId: id },
});
return {
title: `${snapshot ? `「${snapshot.title}」` : "404"} - 洛谷帖子保存站`,
title: `${
snapshot && !snapshot.discussion.takedown
? `「${snapshot.title}」`
: "404"
} - 洛谷帖子保存站`,
};
}

Expand All @@ -37,6 +41,7 @@ export default async function Page({
time,
snapshots: [{ title, forum, author, content, until: updatedAt }],
_count: { replies },
takedown,
} = (await prisma.discussion.findUnique({
where: { id },
select: {
Expand All @@ -53,10 +58,21 @@ export default async function Page({
orderBy: { time: "desc" },
take: 1,
},
takedown: { select: { reason: true, submitter: true } },
_count: { select: { replies: true } },
},
})) ?? notFound();

if (takedown)
return (
<>
<p>{takedown.reason}</p>
<p>
<UserInfo user={takedown.submitter} /> 申请删除。
</p>
</>
);

return (
<div className="row px-2 px-md-0">
<div className="col-lg-4 col-md-5 col-12 order-md-last mb-4s">
Expand Down
24 changes: 24 additions & 0 deletions packages/viewer/src/app/removal/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export default function Page() {
return (
<>
<h2 className="text-center">删除政策</h2>
<p>
如果您认为我们保存的帖子侵犯了您的权益或违反公序良俗,请发邮件至{" "}
<a href="mailto:lda@piterator.com">lda@piterator.com</a>{" "}
申请删除。您的邮件应该包含:
</p>
<ol>
<li>要删除的帖子编号(一个或多个);</li>
<li>
我们应该删除这个/这些帖子的理由(不会被公开,但这是我们判断是否删帖的依据);
</li>
<li>*申请者的洛谷用户编号;</li>
<li>
*需要展示给访问者的文本内容(例如,可以包含公开的删除原因、用户应该查阅的辟谣帖等),每个帖子须对应一段文字。
</li>
</ol>
<p>上述标注星号(*)的内容会在被删除的帖子页面上展示。</p>
<p>我们一般将会在一天内回复您。</p>
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export async function GET(
select: selectDiscussionWithContent,
where: {
snapshots: { some: { authorId: uid } },
takedown: { is: null },
id: { lt: cursor ? parseInt(cursor, 10) : undefined },
},
orderBy: { id: "desc" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export async function GET(
{ replies: { some: { authorId: uid } } },
{ snapshots: { some: { authorId: uid } } },
],
takedown: { is: null },
id: { lt: cursor ? parseInt(cursor, 10) : undefined },
},
orderBy: { id: "desc" },
Expand Down
1 change: 1 addition & 0 deletions packages/viewer/src/app/user/[uid]/replies/data/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export async function GET(
},
where: {
authorId: uid,
discussion: { takedown: { is: null } },
id: { lt: cursor ? parseInt(cursor, 10) : undefined },
},
orderBy: { id: "desc" },
Expand Down
6 changes: 2 additions & 4 deletions packages/viewer/src/components/UserInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ export default function UserInfo({
{href === undefined ? (
<Link
href={getUserUrl(user.id)}
className={`lg-fg-${user.color}`}
style={{ textDecorationLine: "none" }}
className={`text-decoration-none lg-fg-${user.color}`}
>
{user.username}
</Link>
) : (
<a
href={href}
className={`lg-fg-${user.color}`}
style={{ textDecorationLine: "none" }}
className={`text-decoration-none lg-fg-${user.color}`}
target="_blank"
rel="noopener noreferrer"
>
Expand Down
14 changes: 14 additions & 0 deletions prisma/migrations/20230716173707_discussion_takedown/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- CreateTable
CREATE TABLE "DiscussionTakedown" (
"discussionId" INTEGER NOT NULL,
"reason" TEXT NOT NULL,
"submitterId" INTEGER NOT NULL,

CONSTRAINT "DiscussionTakedown_pkey" PRIMARY KEY ("discussionId")
);

-- AddForeignKey
ALTER TABLE "DiscussionTakedown" ADD CONSTRAINT "DiscussionTakedown_discussionId_fkey" FOREIGN KEY ("discussionId") REFERENCES "Discussion"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "DiscussionTakedown" ADD CONSTRAINT "DiscussionTakedown_submitterId_fkey" FOREIGN KEY ("submitterId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
58 changes: 34 additions & 24 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
provider = "prisma-client-js"
binaryTargets = ["native", "debian-openssl-3.0.x"]
}

Expand All @@ -12,23 +12,25 @@ datasource db {
}

model User {
id Int @id
username String @db.VarChar
color String @db.VarChar
checkmark String? @db.Char(7)
badge String? @db.VarChar
snapshots Snapshot[]
replies Reply[]
pastes Paste[]
judgements Judgement[]
id Int @id
username String @db.VarChar
color String @db.VarChar
checkmark String? @db.Char(7)
badge String? @db.VarChar
snapshots Snapshot[]
replies Reply[]
pastes Paste[]
judgements Judgement[]
discussionTakedowns DiscussionTakedown[]
}

model Discussion {
id Int @id
time DateTime @db.Timestamp(0)
id Int @id
time DateTime @db.Timestamp(0)
snapshots Snapshot[]
replyCount Int
replies Reply[]
takedown DiscussionTakedown?
}

model Snapshot {
Expand All @@ -46,6 +48,26 @@ model Snapshot {
@@index([discussionId])
}

model Reply {
id Int @id
discussion Discussion @relation(fields: [discussionId], references: [id])
discussionId Int
time DateTime @db.Timestamp(0)
author User @relation(fields: [authorId], references: [id])
authorId Int
content String @db.Text
@@index([discussionId])
}

model DiscussionTakedown {
discussion Discussion @relation(fields: [discussionId], references: [id])
discussionId Int @id
reason String
submitter User @relation(fields: [submitterId], references: [id])
submitterId Int
}

model Paste {
id String @id @db.Char(8)
time DateTime @db.Timestamp(0)
Expand All @@ -65,18 +87,6 @@ model PasteSnapshot {
@@id([pasteId, time])
}

model Reply {
id Int @id
discussion Discussion @relation(fields: [discussionId], references: [id])
discussionId Int
time DateTime @db.Timestamp(0)
author User @relation(fields: [authorId], references: [id])
authorId Int
content String @db.Text
@@index([discussionId])
}

model Judgement {
time DateTime @db.Timestamp(0)
user User @relation(fields: [userId], references: [id])
Expand Down

0 comments on commit 31299b1

Please sign in to comment.