Add AST cache for AdminLogsTest.php with extracted nodes and edges

This commit is contained in:
hamed
2026-07-10 09:48:45 +03:30
parent 9d2023a72f
commit 11efed4100
13 changed files with 1133 additions and 791 deletions
+34
View File
@@ -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;