fix: align rules list and review detail flows
This commit is contained in:
@@ -110,6 +110,39 @@ export class WopiService {
|
||||
return fileId.replace(/\.\./g, '').replace(/^\//, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* 某些后端文件代理不支持 HEAD,这里先尝试 HEAD,遇到 405 再回退到 GET。
|
||||
*/
|
||||
private async probeFileMetadata(fileUrl: string, frontendJWT: string) {
|
||||
const headers = {
|
||||
'Authorization': `Bearer ${frontendJWT}`,
|
||||
};
|
||||
|
||||
const headResponse = await fetch(fileUrl, {
|
||||
method: 'HEAD',
|
||||
headers,
|
||||
});
|
||||
|
||||
if (headResponse.ok) {
|
||||
return headResponse;
|
||||
}
|
||||
|
||||
if (headResponse.status !== 405) {
|
||||
throw new Error(`文件探测失败: ${headResponse.status}`);
|
||||
}
|
||||
|
||||
const getResponse = await fetch(fileUrl, {
|
||||
method: 'GET',
|
||||
headers,
|
||||
});
|
||||
|
||||
if (!getResponse.ok) {
|
||||
throw new Error(`文件探测失败: ${getResponse.status}`);
|
||||
}
|
||||
|
||||
return getResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* CheckFileInfo - 返回文件元数据
|
||||
* @param fileId - 文件路径(例如:contracts/test.docx)
|
||||
@@ -123,20 +156,12 @@ export class WopiService {
|
||||
// 清理文件路径
|
||||
const sanitizedFileId = this.sanitizeFileId(fileId);
|
||||
|
||||
// 通过 FastAPI 代理获取文件元数据(使用 HEAD 请求)
|
||||
// 通过 FastAPI 代理获取文件元数据。
|
||||
// 注意:当前后端文件路由对 HEAD 返回 405,不能再直接据此判定“文件不存在”。
|
||||
const fileUrl = `${DOCUMENT_URL}${sanitizedFileId}`;
|
||||
|
||||
try {
|
||||
const response = await fetch(fileUrl, {
|
||||
method: 'HEAD',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${tokenData.frontendJWT}`,
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`文件不存在: ${sanitizedFileId}`);
|
||||
}
|
||||
const response = await this.probeFileMetadata(fileUrl, tokenData.frontendJWT);
|
||||
|
||||
const contentLength = response.headers.get('Content-Length');
|
||||
const lastModified = response.headers.get('Last-Modified');
|
||||
|
||||
Reference in New Issue
Block a user