fix: comment all timemilis in api

This commit is contained in:
Sabda Yagra 2026-01-21 10:24:55 +07:00
parent 6e0d864cb8
commit 5e3f0f67a9
4 changed files with 90 additions and 54 deletions

View File

@ -44,7 +44,9 @@ export const IdentityForm: React.FC<IdentityFormProps> = ({
setLoadingPersonel(true); setLoadingPersonel(true);
try { try {
const res = await fetch( const res = await fetch(
`https://mediahub.polri.go.id/api/v2/public/users/search-personil?nrp=${nrp}&timemilis=${Date.now()}` // `https://mediahub.polri.go.id/api/v2/public/users/search-personil?nrp=${nrp}&timemilis=${Date.now()}`
`https://mediahub.polri.go.id/api/v2/public/users/search-personil?nrp=${nrp}}`
); );
if (!res.ok) { if (!res.ok) {

View File

@ -7,11 +7,11 @@ const baseURL = "https://mediahub.polri.go.id/api/v2/";
const refreshToken = Cookies.get("refresh_token"); const refreshToken = Cookies.get("refresh_token");
// Helper function to append timestamp to URL to prevent caching // Helper function to append timestamp to URL to prevent caching
function addTimestampToUrl(url: string): string { // function addTimestampToUrl(url: string): string {
const separator = url.includes('?') ? '&' : '?'; // const separator = url.includes('?') ? '&' : '?';
const timestamp = Date.now(); // const timestamp = Date.now();
return `${url}${separator}timemilis=${timestamp}`; // return `${url}${separator}timemilis=${timestamp}`;
} // }
const axiosInterceptorInstance = axios.create({ const axiosInterceptorInstance = axios.create({
baseURL, baseURL,
@ -31,9 +31,9 @@ axiosInterceptorInstance.interceptors.request.use(
} }
// Add timestamp to URL to prevent caching // Add timestamp to URL to prevent caching
if (config.url) { // if (config.url) {
config.url = addTimestampToUrl(config.url); // config.url = addTimestampToUrl(config.url);
} // }
return config; return config;
}, },

View File

@ -10,11 +10,11 @@ let csrfTokenExpiry: number = 0;
const CSRF_CACHE_DURATION = 5 * 60 * 1000; // 5 minutes const CSRF_CACHE_DURATION = 5 * 60 * 1000; // 5 minutes
// Helper function to append timestamp to URL to prevent caching // Helper function to append timestamp to URL to prevent caching
function addTimestampToUrl(url: string): string { // function addTimestampToUrl(url: string): string {
const separator = url.includes('?') ? '&' : '?'; // const separator = url.includes('?') ? '&' : '?';
const timestamp = Date.now(); // const timestamp = Date.now();
return `${url}${separator}timemilis=${timestamp}`; // return `${url}${separator}timemilis=${timestamp}`;
} // }
async function getCachedCsrfToken() { async function getCachedCsrfToken() {
const now = Date.now(); const now = Date.now();
@ -41,7 +41,7 @@ async function getCachedCsrfToken() {
return null; return null;
} }
export async function httpPost(pathUrl: any, data?: any, headers?: any,) { export async function httpPost(pathUrl: any, data?: any, headers?: any) {
const resCsrf = await getCsrfToken(); const resCsrf = await getCsrfToken();
const csrfToken = resCsrf?.data?.token; const csrfToken = resCsrf?.data?.token;
@ -54,41 +54,19 @@ export async function httpPost(pathUrl: any, data?: any, headers?: any,) {
const mergedHeaders = { const mergedHeaders = {
...defaultHeaders, ...defaultHeaders,
...(csrfToken ? { "X-XSRF-TOKEN": csrfToken } : {}), ...(csrfToken ? { "X-XSRF-TOKEN": csrfToken } : {}),
...(authToken ? { "Authorization" : `Bearer ${authToken}`} : {}), ...(authToken ? { Authorization: `Bearer ${authToken}` } : {}),
...headers, ...headers,
}; };
// Add timestamp to URL to prevent caching // Add timestamp to URL to prevent caching
const urlWithTimestamp = addTimestampToUrl(pathUrl); // const urlWithTimestamp = addTimestampToUrl(pathUrl);
const response = await axiosBaseInstance const response = await axiosBaseInstance
.post(urlWithTimestamp, data, { headers: mergedHeaders }) .post(
.catch(function (error: any) { // urlWithTimestamp,
console.log(error); data,
return error.response; { headers: mergedHeaders },
}); )
// Remove console.log for better performance
if (response?.status == 200 || response?.status == 201) {
return {
error: false,
message: "success",
data: response?.data,
};
} else {
return {
error: true,
message: response?.data?.message || response?.data || null,
data: null,
};
}
}
export async function httpGet(pathUrl: any, headers: any) {
// Add timestamp to URL to prevent caching
const urlWithTimestamp = addTimestampToUrl(pathUrl);
const response = await axiosBaseInstance
.get(urlWithTimestamp, { headers })
.catch(function (error: any) { .catch(function (error: any) {
console.log(error); console.log(error);
return error.response; return error.response;
@ -109,6 +87,55 @@ export async function httpGet(pathUrl: any, headers: any) {
} }
} }
export async function httpGet(pathUrl: any, headers: any) {
const response = await axiosBaseInstance
.get(pathUrl, { headers })
.catch(function (error: any) {
console.log(error);
return error.response;
});
if (response?.status === 200 || response?.status === 201) {
return {
error: false,
message: "success",
data: response?.data,
};
}
return {
error: true,
message: response?.data?.message || response?.data || null,
data: null,
};
}
// export async function httpGet(pathUrl: any, headers: any) {
// // Add timestamp to URL to prevent caching
// const urlWithTimestamp = addTimestampToUrl(pathUrl);
// const response = await axiosBaseInstance
// .get(urlWithTimestamp, { headers })
// .catch(function (error: any) {
// console.log(error);
// return error.response;
// });
// // Remove console.log for better performance
// if (response?.status == 200 || response?.status == 201) {
// return {
// error: false,
// message: "success",
// data: response?.data,
// };
// } else {
// return {
// error: true,
// message: response?.data?.message || response?.data || null,
// data: null,
// };
// }
// }
export async function httpPut(pathUrl: any, headers: any, data?: any) { export async function httpPut(pathUrl: any, headers: any, data?: any) {
const resCsrf = await getCsrfToken(); const resCsrf = await getCsrfToken();
const csrfToken = resCsrf?.data?.token; const csrfToken = resCsrf?.data?.token;
@ -124,10 +151,12 @@ export async function httpPut(pathUrl: any, headers: any, data?: any) {
}; };
// Add timestamp to URL to prevent caching // Add timestamp to URL to prevent caching
const urlWithTimestamp = addTimestampToUrl(pathUrl); // const urlWithTimestamp = addTimestampToUrl(pathUrl);
const response = await axiosBaseInstance const response = await axiosBaseInstance
.put(urlWithTimestamp, data, { headers: mergedHeaders }) .put(
// urlWithTimestamp,
data, { headers: mergedHeaders })
.catch(function (error: any) { .catch(function (error: any) {
console.log(error); console.log(error);
return error.response; return error.response;

View File

@ -30,11 +30,16 @@ export async function getUserRoles() {
} }
export async function getCategoryDetail(id: string) { export async function getCategoryDetail(id: string) {
const timestamp = Date.now(); const url = `media/categories/${id}`;
const url = `media/categories/${id}?timemilis=${timestamp}`;
return httpGetInterceptor(url); return httpGetInterceptor(url);
} }
// export async function getCategoryDetail(id: string) {
// const timestamp = Date.now();
// const url = `media/categories/${id}?timemilis=${timestamp}`;
// return httpGetInterceptor(url);
// }
export async function postCategory(data: any) { export async function postCategory(data: any) {
const url = "media/categories"; const url = "media/categories";