Update comment pagination and ignore data files

This commit is contained in:
LeonspaceX
2026-01-27 12:13:19 +08:00
parent 463c793e89
commit 72204c74b0
7 changed files with 78 additions and 22 deletions

View File

@@ -175,7 +175,7 @@ export interface Article {
export const fetchArticles = async (page: number, signal?: AbortSignal): Promise<Article[]> => {
try {
const response = await fetch(`/api/10_info?page=${page}`, { signal });
const response = await fetch(`/api/posts_info?page=${page}`, { signal });
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
@@ -219,15 +219,23 @@ export interface Comment {
parent_comment_id: number;
}
export const getComments = async (id: string | number): Promise<Comment[]> => {
export interface CommentPage {
comments: Comment[];
total_pages: number;
}
export const getComments = async (id: string | number, page: number = 1): Promise<CommentPage> => {
try {
const response = await fetch(`/api/get/comment?id=${id}`);
const response = await fetch(`/api/get/comment?id=${id}&page=${page}`);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const json = await response.json();
if (json.code === 1000 && Array.isArray(json.data)) {
return json.data as Comment[];
if (json.code === 1000 && json.data && Array.isArray(json.data.comments)) {
return {
comments: json.data.comments as Comment[],
total_pages: Number(json.data.total_pages) || 0,
};
}
throw new Error('Invalid response code or missing data');
} catch (error) {