feat: 完善后台导入日志权限与备份恢复
This commit is contained in:
@@ -13,5 +13,16 @@ export function saveBlob(blob: Blob, filename: string): void {
|
||||
|
||||
export async function downloadFile(url: string, filename: string, params?: object): Promise<void> {
|
||||
const res = await download(url, params);
|
||||
saveBlob(res.data, filename);
|
||||
saveBlob(res.data, pickFilename(res.headers, filename));
|
||||
}
|
||||
|
||||
function pickFilename(headers: Record<string, string>, fallback: string): string {
|
||||
const disposition = headers['content-disposition'] || headers['Content-Disposition'];
|
||||
const match = disposition?.match(/filename\*?=(?:UTF-8''|")?([^";]+)/i);
|
||||
if (!match?.[1]) return fallback;
|
||||
try {
|
||||
return decodeURIComponent(match[1].replace(/"/g, ''));
|
||||
} catch {
|
||||
return match[1].replace(/"/g, '');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user