feat : comment feature
CI / Verify (push) Successful in 2m30s
CI / Build immutable images and deploy (push) Successful in 3m9s

This commit is contained in:
2026-10-08 01:40:08 +07:00 Unverified
parent 8c8815cda5
commit 5812d99715
65 changed files with 27013 additions and 10 deletions
+26
View File
@@ -0,0 +1,26 @@
export const COMMENT_ERRORS: Record<string, string> = {
"sign-in-required": "กรุณาเข้าสู่ระบบเพื่อแสดงความคิดเห็น",
"too-many-requests": "ทำรายการบ่อยเกินไป กรุณารอสักครู่แล้วลองใหม่",
"uploads-busy": "ระบบอัปโหลดกำลังใช้งานมาก กรุณาลองใหม่อีกครั้ง",
"image-too-large": "รูปภาพแต่ละรูปต้องมีขนาดไม่เกิน 10 MiB",
"body-too-large": "แนบรูปภาพได้สูงสุด 5 รูป รูปละไม่เกิน 10 MiB",
"unsupported-image-type": "รองรับรูปภาพ JPEG, PNG และ WebP ไม่รองรับวิดีโอ",
"invalid-image": "ไม่สามารถอ่านรูปภาพได้ กรุณาเลือกไฟล์รูปภาพที่ถูกต้อง",
"empty-comment": "เขียนความคิดเห็นหรือแนบรูปภาพ",
"invalid-comment": "เขียนได้สูงสุด 4,000 ตัวอักษร และแนบรูปภาพได้ 5 รูป",
"comment-edited-reload": "ความคิดเห็นนี้ถูกแก้ไขแล้ว กรุณาโหลดใหม่ก่อนบันทึก ข้อความร่างของคุณยังอยู่",
"comment-unavailable": "ไม่สามารถทำรายการกับความคิดเห็นนี้ได้แล้ว",
"comment-not-editable": "ไม่สามารถแก้ไขความคิดเห็นนี้ได้แล้ว",
"guide-trashed": "ไกด์นี้อยู่ในถังขยะ จึงไม่สามารถแสดงความคิดเห็นได้",
};
export async function commentRequest<T>(url: string, options?: RequestInit): Promise<T> {
const response = await fetch(url, { cache: "no-store", ...options });
if (!response.ok) {
const body = await response.json().catch(() => ({}));
throw new Error(COMMENT_ERRORS[body.error] ?? "ไม่สามารถทำรายการได้ กรุณาลองใหม่");
}
return response.status === 204 ? undefined as T : await response.json() as T;
}
export function commentSignInHref() {
return `/auth/login?next=${encodeURIComponent(window.location.pathname + window.location.search + window.location.hash)}`;
}