Update notify.ts

This commit is contained in:
Vaica committed 2026-06-24 14:25:47 +08:00
1 parent 05b22247e0
commit 34815476f2
1 file changed
+8 -1
+8 -1
View File
@@ -86,6 +86,7 @@ async function fetchLatestComments(): Promise<ArtalkComment[]> {
// 使用管理员 API 获取所有评论 // 使用管理员 API 获取所有评论
const url = `${ARTALK_SERVER}/api/v2/admin/comments?site_name=${encodeURIComponent(ARTALK_SITE)}&limit=5&sort_by=date&sort_order=desc`; const url = `${ARTALK_SERVER}/api/v2/admin/comments?site_name=${encodeURIComponent(ARTALK_SITE)}&limit=5&sort_by=date&sort_order=desc`;
console.log("[comment-notify] fetching comments with admin API..."); console.log("[comment-notify] fetching comments with admin API...");
console.log("[comment-notify] URL:", url);
const res = await fetch(url, { const res = await fetch(url, {
headers: { headers: {
@@ -94,13 +95,16 @@ async function fetchLatestComments(): Promise<ArtalkComment[]> {
}, },
}); });
console.log("[comment-notify] response status:", res.status, res.statusText);
if (!res.ok) { if (!res.ok) {
const errorText = await res.text().catch(() => "Unable to read response"); const errorText = await res.text().catch(() => "Unable to read response");
console.error("[comment-notify] fetch failed:", res.status, res.statusText); console.error("[comment-notify] fetch failed:", res.status, res.statusText);
console.error("[comment-notify] response:", errorText); console.error("[comment-notify] response body:", errorText);
// 如果是认证失败,清除 token 以便下次重试 // 如果是认证失败,清除 token 以便下次重试
if (res.status === 401 || res.status === 403) { if (res.status === 401 || res.status === 403) {
console.error("[comment-notify] authentication failed, clearing token");
authToken = null; authToken = null;
tokenExpiry = 0; tokenExpiry = 0;
} }
@@ -113,6 +117,9 @@ async function fetchLatestComments(): Promise<ArtalkComment[]> {
return data.comments || []; return data.comments || [];
} catch (e) { } catch (e) {
console.error("[comment-notify] fetch error:", e instanceof Error ? e.message : String(e)); console.error("[comment-notify] fetch error:", e instanceof Error ? e.message : String(e));
if (e instanceof Error && e.stack) {
console.error("[comment-notify] error stack:", e.stack.split('\n').slice(0, 5).join('\n'));
}
return []; return [];
} }
} }