fix(api): normalize empty list responses

This commit is contained in:
zetaloop
2026-04-26 01:53:05 +08:00
parent 904148bd55
commit 30c336345e
11 changed files with 28 additions and 23 deletions
+3 -3
View File
@@ -4,7 +4,7 @@ import type { Post } from "@/lib/types"
import { httpJson } from "./http"
type Paginated<T> = {
items: T[]
items: T[] | null
meta: {
total: number
offset: number
@@ -40,7 +40,7 @@ export async function listPosts(options?: ListOptions): Promise<Post[]> {
const res = await httpJson<Paginated<Post>>(withOffsetLimit("/api/v1/posts", options), {
cache: "no-store",
})
return res.items
return res.items ?? []
}
export async function getPostById(postId: string): Promise<Post | undefined> {
@@ -80,7 +80,7 @@ export async function listPostsByAuthor(userId: string, options?: ListOptions):
cache: "no-store",
},
)
return res.items
return res.items ?? []
}
export async function togglePostLike(postId: string, currentlyLiked: boolean): Promise<void> {