修复某些大文件无法正常上传处理问题

This commit is contained in:
Vinlic 2024-04-25 10:47:57 +08:00
parent 77d42d9484
commit a2d5ab9390

View File

@ -609,6 +609,10 @@ async function uploadFile(fileUrl: string, refreshToken: string) {
}); });
checkResult(result, refreshToken); checkResult(result, refreshToken);
let fileId, status, startTime = Date.now();
while (status != 'initialized') {
if (Date.now() - startTime > 30000)
throw new Error('文件等待处理超时');
// 获取文件上传结果 // 获取文件上传结果
result = await axios.post('https://kimi.moonshot.cn/api/file', { result = await axios.post('https://kimi.moonshot.cn/api/file', {
type: 'file', type: 'file',
@ -623,10 +627,17 @@ async function uploadFile(fileUrl: string, refreshToken: string) {
...FAKE_HEADERS ...FAKE_HEADERS
} }
}); });
const { id: fileId } = checkResult(result, refreshToken); ({ id: fileId, status } = checkResult(result, refreshToken));
}
startTime = Date.now();
let parseFinish = false;
while (!parseFinish) {
if (Date.now() - startTime > 30000)
throw new Error('文件等待处理超时');
// 处理文件转换 // 处理文件转换
result = await axios.post('https://kimi.moonshot.cn/api/file/parse_process', { parseFinish = await new Promise(resolve => {
axios.post('https://kimi.moonshot.cn/api/file/parse_process', {
ids: [fileId], ids: [fileId],
timeout: 120000 timeout: 120000
}, { }, {
@ -636,8 +647,11 @@ async function uploadFile(fileUrl: string, refreshToken: string) {
'X-Traffic-Id': userId, 'X-Traffic-Id': userId,
...FAKE_HEADERS ...FAKE_HEADERS
} }
})
.then(() => resolve(true))
.catch(() => resolve(false));
}); });
checkResult(result, refreshToken); }
return fileId; return fileId;
} }