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);
|
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) {
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -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,15 +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(
|
||||||
|
// urlWithTimestamp,
|
||||||
|
data,
|
||||||
|
{ headers: mergedHeaders },
|
||||||
|
)
|
||||||
.catch(function (error: any) {
|
.catch(function (error: any) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
return error.response;
|
return error.response;
|
||||||
|
|
@ -84,31 +88,54 @@ export async function httpPost(pathUrl: any, data?: any, headers?: any,) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function httpGet(pathUrl: any, headers: any) {
|
export async function httpGet(pathUrl: any, headers: any) {
|
||||||
// Add timestamp to URL to prevent caching
|
|
||||||
const urlWithTimestamp = addTimestampToUrl(pathUrl);
|
|
||||||
|
|
||||||
const response = await axiosBaseInstance
|
const response = await axiosBaseInstance
|
||||||
.get(urlWithTimestamp, { headers })
|
.get(pathUrl, { headers })
|
||||||
.catch(function (error: any) {
|
.catch(function (error: any) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
return error.response;
|
return error.response;
|
||||||
});
|
});
|
||||||
// Remove console.log for better performance
|
|
||||||
if (response?.status == 200 || response?.status == 201) {
|
if (response?.status === 200 || response?.status === 201) {
|
||||||
return {
|
return {
|
||||||
error: false,
|
error: false,
|
||||||
message: "success",
|
message: "success",
|
||||||
data: response?.data,
|
data: response?.data,
|
||||||
};
|
};
|
||||||
} else {
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
error: true,
|
error: true,
|
||||||
message: response?.data?.message || response?.data || null,
|
message: response?.data?.message || response?.data || null,
|
||||||
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;
|
||||||
|
|
|
||||||
|
|
@ -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";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue