Fixed Large ID Precision Loss จาก Django DRF/JWT, CockroachDB Large IDs

This commit is contained in:
Flook 2025-11-10 04:46:21 +07:00
parent 8c6c240a60
commit c52928fb1e
2 changed files with 22 additions and 10 deletions

View File

@ -16,13 +16,6 @@ const getStatusBadge = (status) => {
}
};
/**
* Component สำหรบแสดงตาราง Model Registry
* @param {Array} models - อม Models กรองแล (จาก useModelList)
* @param {function} handleOpenEdit - Handler สำหรบเป Modal แกไข
* @param {function} handleDelete - Handler สำหรบลบ Model
* @param {boolean} deleteLoading - สถานะ Loading ของ Delete Mutation
*/
function ModelTable({ models, handleOpenEdit, handleDelete, deleteLoading }) {
// 1. Hook (Test Connection)
// Hook Logic Action
@ -84,7 +77,7 @@ function ModelTable({ models, handleOpenEdit, handleDelete, deleteLoading }) {
<button
className="btn btn-outline btn-info btn-xs tooltip"
data-tip="Test Connection"
onClick={() => handleTest(model.id)}
onClick={() => handleTest(String(model.id))}
disabled={testConnectionMutation.isPending}
>
{testConnectionMutation.isPending ?
@ -97,7 +90,7 @@ function ModelTable({ models, handleOpenEdit, handleDelete, deleteLoading }) {
<button
className="btn btn-outline btn-error btn-xs tooltip"
data-tip="Delete Model"
onClick={() => handleDelete(model.id)}
onClick={() => handleDelete(String(model.id))}
disabled={deleteLoading || testConnectionMutation.isPending}
>
<FaTrash className="w-3 h-3" />

View File

@ -2,12 +2,31 @@ import axios from 'axios';
import { getStore } from '../app/store';
import { logout } from '../features/auth/authSlice';
// 1. สร้าง Axios Instance โดยใช้ Base URL จาก .env
// REGEX ตรวจจับตัวเลขที่ใหญ่เกิน 15 หลัก (ซึ่งเกินขีดจำกัดความปลอดภัยของ JS)
const bigIntRegex = /"id":(\d{15,})/g;
// 1. สร้าง Axios Instance โดยใช้ Base URL จาก .env
const axiosClient = axios.create({
baseURL: import.meta.env.VITE_API_BASE_URL,
// กำหนด Timeout เพื่อป้องกันการค้าง
timeout: 15000,
transformResponse: [
function (data) {
if (typeof data === 'string') {
// 1. ใช้ Regex เพื่อค้นหาฟิลด์ "id" ที่มีตัวเลขเกิน 15 หลัก
data = data.replace(bigIntRegex, (match, p1) => {
// 2. แปลงตัวเลขนั้นให้เป็น String ที่มีเครื่องหมายคำพูดล้อมรอบ
return `"id":"${p1}"`;
});
}
// 3. เรียก JSON.parse หลังจากแปลงแล้ว
try {
return JSON.parse(data);
} catch {
return data; // คืนค่าเดิมถ้าไม่สามารถ Parse JSON ได้ (เช่น 404 text)
}
},
].concat(axios.defaults.transformResponse || []),
});