给所有请求都加上jwt,隐藏生成jwt的secret(放到.env中),隐藏app-secret(放在pm2运行配置文件中,后续直接读取环境配置即可)
This commit is contained in:
+10
-7
@@ -386,15 +386,18 @@ export async function del<T>(endpoint: string, params?: QueryParams): Promise<Ap
|
||||
|
||||
// 下载文件的方法
|
||||
export async function downloadFile(path: string): Promise<Blob> {
|
||||
const downloadUrl = `${DOCUMENT_URL}${path}`;
|
||||
|
||||
// 使用 PDF 代理路由获取文件,自动添加 JWT 认证
|
||||
const downloadUrl = `/api/pdf-proxy?path=${encodeURIComponent(path)}`;
|
||||
|
||||
try {
|
||||
// console.log(`📦 axios-client.ts->下载文件: ${downloadUrl}`);
|
||||
const response = await axios.get(downloadUrl, {
|
||||
responseType: 'blob'
|
||||
});
|
||||
|
||||
return response.data;
|
||||
const response = await fetch(downloadUrl);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`下载失败: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
|
||||
return await response.blob();
|
||||
} catch (error) {
|
||||
console.error('下载文件失败:', error);
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user