From c7fc842fbe0535d508d0689100fbb273850cd290 Mon Sep 17 00:00:00 2001 From: syui Date: Sun, 18 Jan 2026 19:06:34 +0900 Subject: [PATCH] fix locale file none --- src/web/lib/api.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/web/lib/api.ts b/src/web/lib/api.ts index 4839eb6..d15c9ba 100644 --- a/src/web/lib/api.ts +++ b/src/web/lib/api.ts @@ -63,11 +63,17 @@ export async function getPds(did: string): Promise { return null } +// Check if response is JSON +function isJsonResponse(res: Response): boolean { + const contentType = res.headers.get('content-type') + return contentType?.includes('application/json') ?? false +} + // Load local profile async function getLocalProfile(did: string): Promise { try { const res = await fetch(`/content/${did}/app.bsky.actor.profile/self.json`) - if (res.ok) return res.json() + if (res.ok && isJsonResponse(res)) return res.json() } catch { // Not found } @@ -109,12 +115,12 @@ export async function getAvatarUrl(did: string, profile: Profile): Promise { try { const indexRes = await fetch(`/content/${did}/${collection}/index.json`) - if (indexRes.ok) { + if (indexRes.ok && isJsonResponse(indexRes)) { const rkeys: string[] = await indexRes.json() const posts: Post[] = [] for (const rkey of rkeys) { const res = await fetch(`/content/${did}/${collection}/${rkey}.json`) - if (res.ok) posts.push(await res.json()) + if (res.ok && isJsonResponse(res)) posts.push(await res.json()) } return posts.sort((a, b) => new Date(b.value.createdAt).getTime() - new Date(a.value.createdAt).getTime() @@ -157,7 +163,7 @@ export async function getPost(did: string, collection: string, rkey: string, loc if (localFirst) { try { const res = await fetch(`/content/${did}/${collection}/${rkey}.json`) - if (res.ok) return res.json() + if (res.ok && isJsonResponse(res)) return res.json() } catch { // Not found } @@ -182,7 +188,7 @@ export async function describeRepo(did: string): Promise { // Try local first try { const res = await fetch(`/content/${did}/describe.json`) - if (res.ok) { + if (res.ok && isJsonResponse(res)) { const data = await res.json() return data.collections || [] }