fix: comment all timemilis in api
This commit is contained in:
parent
6e0d864cb8
commit
5e3f0f67a9
|
|
@ -44,7 +44,9 @@ export const IdentityForm: React.FC<IdentityFormProps> = ({
|
|||
setLoadingPersonel(true);
|
||||
try {
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@ const baseURL = "https://mediahub.polri.go.id/api/v2/";
|
|||
const refreshToken = Cookies.get("refresh_token");
|
||||
|
||||
// Helper function to append timestamp to URL to prevent caching
|
||||
function addTimestampToUrl(url: string): string {
|
||||
const separator = url.includes('?') ? '&' : '?';
|
||||
const timestamp = Date.now();
|
||||
return `${url}${separator}timemilis=${timestamp}`;
|
||||
}
|
||||
// function addTimestampToUrl(url: string): string {
|
||||
// const separator = url.includes('?') ? '&' : '?';
|
||||
// const timestamp = Date.now();
|
||||
// return `${url}${separator}timemilis=${timestamp}`;
|
||||
// }
|
||||
|
||||
const axiosInterceptorInstance = axios.create({
|
||||
baseURL,
|
||||
|
|
@ -31,9 +31,9 @@ axiosInterceptorInstance.interceptors.request.use(
|
|||
}
|
||||
|
||||
// Add timestamp to URL to prevent caching
|
||||
if (config.url) {
|
||||
config.url = addTimestampToUrl(config.url);
|
||||
}
|
||||
// if (config.url) {
|
||||
// config.url = addTimestampToUrl(config.url);
|
||||
// }
|
||||
|
||||
return config;
|
||||
},
|
||||
|
|
|
|||
|
|
@ -10,25 +10,25 @@ let csrfTokenExpiry: number = 0;
|
|||
const CSRF_CACHE_DURATION = 5 * 60 * 1000; // 5 minutes
|
||||
|
||||
// Helper function to append timestamp to URL to prevent caching
|
||||
function addTimestampToUrl(url: string): string {
|
||||
const separator = url.includes('?') ? '&' : '?';
|
||||
const timestamp = Date.now();
|
||||
return `${url}${separator}timemilis=${timestamp}`;
|
||||
}
|
||||
// function addTimestampToUrl(url: string): string {
|
||||
// const separator = url.includes('?') ? '&' : '?';
|
||||
// const timestamp = Date.now();
|
||||
// return `${url}${separator}timemilis=${timestamp}`;
|
||||
// }
|
||||
|
||||
async function getCachedCsrfToken() {
|
||||
const now = Date.now();
|
||||
|
||||
|
||||
// Return cached token if still valid
|
||||
if (csrfTokenCache && now < csrfTokenExpiry) {
|
||||
return csrfTokenCache;
|
||||
}
|
||||
|
||||
|
||||
// Fetch new token
|
||||
try {
|
||||
const resCsrf = await getCsrfToken();
|
||||
const token = resCsrf?.data?.token;
|
||||
|
||||
|
||||
if (token) {
|
||||
csrfTokenCache = token;
|
||||
csrfTokenExpiry = now + CSRF_CACHE_DURATION;
|
||||
|
|
@ -37,11 +37,11 @@ async function getCachedCsrfToken() {
|
|||
} catch (error) {
|
||||
console.error("Failed to fetch CSRF token:", error);
|
||||
}
|
||||
|
||||
|
||||
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 csrfToken = resCsrf?.data?.token;
|
||||
|
||||
|
|
@ -54,41 +54,19 @@ export async function httpPost(pathUrl: any, data?: any, headers?: any,) {
|
|||
const mergedHeaders = {
|
||||
...defaultHeaders,
|
||||
...(csrfToken ? { "X-XSRF-TOKEN": csrfToken } : {}),
|
||||
...(authToken ? { "Authorization" : `Bearer ${authToken}`} : {}),
|
||||
...(authToken ? { Authorization: `Bearer ${authToken}` } : {}),
|
||||
...headers,
|
||||
};
|
||||
|
||||
// Add timestamp to URL to prevent caching
|
||||
const urlWithTimestamp = addTimestampToUrl(pathUrl);
|
||||
|
||||
const response = await axiosBaseInstance
|
||||
.post(urlWithTimestamp, data, { headers: mergedHeaders })
|
||||
.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 httpGet(pathUrl: any, headers: any) {
|
||||
// Add timestamp to URL to prevent caching
|
||||
const urlWithTimestamp = addTimestampToUrl(pathUrl);
|
||||
|
||||
// const urlWithTimestamp = addTimestampToUrl(pathUrl);
|
||||
|
||||
const response = await axiosBaseInstance
|
||||
.get(urlWithTimestamp, { headers })
|
||||
.post(
|
||||
// urlWithTimestamp,
|
||||
data,
|
||||
{ headers: mergedHeaders },
|
||||
)
|
||||
.catch(function (error: any) {
|
||||
console.log(error);
|
||||
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) {
|
||||
const resCsrf = await getCsrfToken();
|
||||
const csrfToken = resCsrf?.data?.token;
|
||||
|
|
@ -116,7 +143,7 @@ export async function httpPut(pathUrl: any, headers: any, data?: any) {
|
|||
const defaultHeaders = {
|
||||
"Content-Type": "application/json",
|
||||
};
|
||||
|
||||
|
||||
const mergedHeaders = {
|
||||
...defaultHeaders,
|
||||
...headers,
|
||||
|
|
@ -124,10 +151,12 @@ export async function httpPut(pathUrl: any, headers: any, data?: any) {
|
|||
};
|
||||
|
||||
// Add timestamp to URL to prevent caching
|
||||
const urlWithTimestamp = addTimestampToUrl(pathUrl);
|
||||
// const urlWithTimestamp = addTimestampToUrl(pathUrl);
|
||||
|
||||
const response = await axiosBaseInstance
|
||||
.put(urlWithTimestamp, data, { headers: mergedHeaders })
|
||||
.put(
|
||||
// urlWithTimestamp,
|
||||
data, { headers: mergedHeaders })
|
||||
.catch(function (error: any) {
|
||||
console.log(error);
|
||||
return error.response;
|
||||
|
|
|
|||
|
|
@ -30,11 +30,16 @@ export async function getUserRoles() {
|
|||
}
|
||||
|
||||
export async function getCategoryDetail(id: string) {
|
||||
const timestamp = Date.now();
|
||||
const url = `media/categories/${id}?timemilis=${timestamp}`;
|
||||
const url = `media/categories/${id}`;
|
||||
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) {
|
||||
const url = "media/categories";
|
||||
|
|
|
|||
Loading…
Reference in New Issue