Skip to content

Commit 2ccc2ee

Browse files
wxh06immccn123
authored andcommitted
改用新的讨论列表接口
1 parent f8c5e74 commit 2ccc2ee

File tree

2 files changed

+43
-42
lines changed

2 files changed

+43
-42
lines changed

packages/archive/src/lib/list.ts

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
11
import type { BaseLogger } from "pino";
22
import type { PrismaClient } from "@prisma/client";
3+
import type { UserSummary } from "./user";
4+
import type { ForumData, ReplyContent } from "./post";
35
import { getResponse } from "./parser";
46

5-
interface LegacyDiscussList {
6-
status: 200;
7-
data: {
8-
count: number;
9-
result: {
10-
PostID: number;
11-
Title: string;
12-
Author: { _instance: "Luogu\\Model\\User\\User" };
13-
Forum: {
14-
Forum: {
15-
ForumID: number;
16-
Name: string;
17-
InternalName: string;
18-
_instance: "Luogu\\Model\\Discuss\\Forum";
19-
};
20-
};
21-
Top: number;
22-
SubmitTime: number;
23-
isValid: boolean;
24-
LatestReply: {
25-
Author: { _instance: "Luogu\\Model\\User\\User" };
26-
ReplyTime: number;
27-
Content: string;
28-
_instance: "Luogu\\Model\\Discuss\\PostReply";
29-
} | null;
30-
RepliesCount: number;
31-
_instance: "Luogu\\Model\\Discuss\\Post";
32-
}[];
7+
interface PostData {
8+
id: number;
9+
title: string;
10+
author: UserSummary;
11+
time: number;
12+
forum: ForumData;
13+
topped: boolean;
14+
valid: boolean;
15+
locked: false;
16+
replyCount: number;
17+
recentReply: ReplyContent | false;
18+
}
19+
20+
interface PostListResponse {
21+
code: 200;
22+
currentTemplate: "DiscussList";
23+
currentData: {
24+
forum: ForumData | null;
25+
publicForums: ForumData[];
26+
posts: {
27+
perPage: number;
28+
count: number;
29+
result: PostData[];
30+
};
31+
canPost: boolean;
3332
};
3433
}
3534

@@ -41,12 +40,14 @@ export default async function getPostList(
4140
) {
4241
const response = await getResponse(
4342
logger,
44-
`https://www.luogu.com/api/discuss?page=${page}`,
43+
`https://www.luogu.com/discuss?_contentOnly&page=${page}`,
4544
false,
4645
);
4746
const {
48-
data: { result },
49-
} = (await response.json()) as LegacyDiscussList;
47+
currentData: {
48+
posts: { result },
49+
},
50+
} = (await response.json()) as PostListResponse;
5051
const saved = Object.fromEntries(
5152
(
5253
await prisma.post.findMany({
@@ -57,8 +58,8 @@ export default async function getPostList(
5758
where: {
5859
id: {
5960
in: result
60-
.filter((post) => post.SubmitTime < after)
61-
.map((post) => post.PostID),
61+
.filter((post) => post.time < after)
62+
.map((post) => post.id),
6263
},
6364
},
6465
})
@@ -67,12 +68,12 @@ export default async function getPostList(
6768
return result
6869
.filter(
6970
(post) =>
70-
post.SubmitTime >= after ||
71-
!(post.PostID in saved) ||
72-
(post.LatestReply &&
73-
(!saved[post.PostID] ||
74-
Math.floor(saved[post.PostID].getTime() / 60000) !==
75-
Math.floor(post.LatestReply.ReplyTime / 60))),
71+
post.time >= after ||
72+
!(post.id in saved) ||
73+
(post.recentReply &&
74+
(!saved[post.id] ||
75+
Math.floor(saved[post.id].getTime() / 60000) !==
76+
Math.floor(post.recentReply.time / 60))),
7677
)
77-
.map((post) => post.PostID);
78+
.map((post) => post.id);
7879
}

packages/archive/src/lib/post.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { UserSummary, upsertUserSnapshotHook } from "./user";
99
const PAGES_PER_SAVE = parseInt(process.env.PAGES_PER_SAVE ?? "64", 10);
1010
export const emitters: Record<number, EventEmitter> = {};
1111

12-
interface ForumData {
12+
export interface ForumData {
1313
name: string;
1414
type: number;
1515
slug: string;
@@ -24,7 +24,7 @@ interface PostData {
2424
content: string;
2525
}
2626

27-
interface ReplyContent {
27+
export interface ReplyContent {
2828
id: number;
2929
author: UserSummary;
3030
time: number;

0 commit comments

Comments
 (0)