fix: 1. 系统设置入口进来只会跳转到拥有权限访问的页面。

2. 优化登录样式
This commit is contained in:
2025-11-26 18:05:15 +08:00
parent efbf78246f
commit 1b0108e518
6 changed files with 179 additions and 28 deletions
+44 -8
View File
@@ -11,9 +11,16 @@ export async function loader({ request }: LoaderFunctionArgs) {
// 获取 JWT token
const { frontendJWT } = await getUserSession(request);
// 从查询参数获取文件路径
// 从查询参数获取文件路径和预览标志
const url = new URL(request.url);
const filePath = url.searchParams.get("path");
const isPreview = url.searchParams.get("preview") === "true";
console.log("📄 [PDF Proxy] 请求参数:", {
path: filePath,
preview: url.searchParams.get("preview"),
isPreview: isPreview
});
if (!filePath) {
return new Response("缺少文件路径参数", { status: 400 });
@@ -38,13 +45,42 @@ export async function loader({ request }: LoaderFunctionArgs) {
// 获取文件内容
const blob = await response.blob();
// 返回文件,保持原始的 Content-Type
return new Response(blob, {
headers: {
'Content-Type': response.headers.get('Content-Type') || 'application/pdf',
'Cache-Control': 'public, max-age=3600', // 缓存1小时
},
});
// 从路径中提取文件名
const fileName = filePath.split('/').pop() || 'document.pdf';
// 判断文件类型
const fileExtension = fileName.split('.').pop()?.toLowerCase();
let contentType = response.headers.get('Content-Type') || 'application/octet-stream';
// 🔑 根据文件扩展名强制设置正确的 Content-Type
if (fileExtension === 'pdf') {
contentType = 'application/pdf';
} else if (fileExtension === 'doc' || fileExtension === 'docx') {
contentType = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
}
// 设置响应头
const headers: HeadersInit = {
'Content-Type': contentType,
'Cache-Control': 'public, max-age=3600', // 缓存1小时
};
// 根据 preview 参数决定是预览还是下载
// 默认行为:强制下载(保持向后兼容性)
if (isPreview) {
// 在浏览器中预览
headers['Content-Disposition'] = `inline; filename="${encodeURIComponent(fileName)}"`;
console.log("📄 [PDF Proxy] 设置为预览模式 (inline)");
} else {
// 强制下载(默认行为)
headers['Content-Disposition'] = `attachment; filename="${encodeURIComponent(fileName)}"`;
console.log("📄 [PDF Proxy] 设置为下载模式 (attachment)");
}
console.log("📄 [PDF Proxy] 响应头:", headers);
// 返回文件
return new Response(blob, { headers });
} catch (error) {
console.error('PDF 代理错误:', error);