Skip to content

Commit

Permalink
Use x-luogu-type header instead of _contentOnly in query params
Browse files Browse the repository at this point in the history
  • Loading branch information
wxh06 authored and immccn123 committed Nov 18, 2024
1 parent 5cdd854 commit 7e9b385
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 16 deletions.
8 changes: 3 additions & 5 deletions packages/archive/src/lib/judgement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ export default async function saveJudgements(
logger: BaseLogger,
prisma: PrismaClient,
) {
const res = await getResponse(
logger,
lgUrl(`/judgement?_contentOnly`, false),
false,
).then((response): Promise<JudgementResponse> => response.json());
const res = await getResponse(logger, lgUrl(`/judgement`, false), false).then(
(response): Promise<JudgementResponse> => response.json(),
);

const operations: PrismaPromise<unknown>[] = [];
const judgements = res.currentData.logs;
Expand Down
2 changes: 1 addition & 1 deletion packages/archive/src/lib/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default async function getPostList(
) {
const response = await getResponse(
logger,
lgUrl(`/discuss?_contentOnly&page=${page}`),
lgUrl(`/discuss?page=${page}`),
false,
);
const {
Expand Down
5 changes: 4 additions & 1 deletion packages/archive/src/lib/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ export async function getResponse(
retries = 1,
) {
const response = await fetch(url, {
headers: cookie ? { cookie: process.env.COOKIE! } : undefined,
headers: {
"x-luogu-type": "content-only",
...(cookie ? { cookie: process.env.COOKIE! } : {}),
},
cache: "no-cache",
});
logger.info(
Expand Down
5 changes: 1 addition & 4 deletions packages/archive/src/lib/paste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ export default async function savePaste(
prisma: PrismaClient,
id: string,
) {
const response = await getResponse(
logger,
lgUrl(`/paste/${id}?_contentOnly`, false),
);
const response = await getResponse(logger, lgUrl(`/paste/${id}`, false));
const json = (await response.json()) as
| { code: 403 | 404; currentData: LuoguError }
| { code: 200; currentData: { paste: Paste } };
Expand Down
8 changes: 3 additions & 5 deletions packages/archive/src/lib/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,9 @@ export async function savePost(
let allReplies: ReplyContent[] = [];

const fetchPage = (page: number) =>
getResponse(
logger,
lgUrl(`/discuss/${id}?_contentOnly&page=${page}`),
false,
).then((response): Promise<ResponseBody> => response.json());
getResponse(logger, lgUrl(`/discuss/${id}?page=${page}`), false).then(
(response): Promise<ResponseBody> => response.json(),
);

const saveReplies = async (replies: ReplyContent[]) => {
// eslint-disable-next-line no-restricted-syntax
Expand Down

0 comments on commit 7e9b385

Please sign in to comment.