Add AST cache for AdminLogsTest.php with extracted nodes and edges
This commit is contained in:
@@ -83,8 +83,42 @@ export const api = {
|
||||
put: <T>(path: string, body: unknown) =>
|
||||
request<T>(path, { method: 'PUT', body: JSON.stringify(body) }),
|
||||
delete: <T>(path: string) => request<T>(path, { method: 'DELETE' }),
|
||||
download: (path: string) => downloadFile(path),
|
||||
};
|
||||
|
||||
// دانلود فایل با ارسال توکن JWT در هدر و ذخیره روی دیسک کاربر
|
||||
async function downloadFile(path: string, retry = true): Promise<void> {
|
||||
const token = getToken();
|
||||
const headers: Record<string, string> = {};
|
||||
if (token) headers['Authorization'] = `Bearer ${token}`;
|
||||
|
||||
const res = await fetch(`${BASE_URL}${path}`, { headers });
|
||||
|
||||
if (!res.ok) {
|
||||
if (res.status === 401 && retry) {
|
||||
const newToken = await refreshOnce();
|
||||
if (newToken) return downloadFile(path, false);
|
||||
useAuthStore.getState().logout();
|
||||
window.location.replace('/admin/login');
|
||||
}
|
||||
throw new ApiError(res.status, 'ERR_DOWNLOAD', 'دانلود ناموفق بود');
|
||||
}
|
||||
|
||||
const blob = await res.blob();
|
||||
const disposition = res.headers.get('Content-Disposition') ?? '';
|
||||
const match = disposition.match(/filename="?([^"]+)"?/);
|
||||
const filename = match ? match[1] : 'download';
|
||||
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = filename;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
export interface ApiResponse<T> {
|
||||
success: boolean;
|
||||
data: T;
|
||||
|
||||
Reference in New Issue
Block a user