Bug:修复偶发的HF渠道移动文件导致文件丢失的问题

This commit is contained in:
MarSeventh
2026-03-02 22:13:18 +08:00
parent 14b7a8f976
commit c14c596889
2 changed files with 12 additions and 4 deletions
+6 -2
View File
@@ -88,8 +88,12 @@ export async function onRequestPost(context) {
// 使用统一的文件命名函数生成文件ID
const fullId = await buildUniqueFileId(context, fileName, fileType || 'application/octet-stream');
// 构建 HuggingFace 文件路径:直接使用 fullId(与其他渠道保持一致)
const filePath = fullId;
// 生成唯一标识符前缀(UUID格式),加在文件名前面
const uniquePrefix = crypto.randomUUID();
const lastSlashIndex = fullId.lastIndexOf('/');
const filePath = lastSlashIndex === -1
? `${uniquePrefix}_${fullId}`
: `${fullId.substring(0, lastSlashIndex + 1)}${uniquePrefix}_${fullId.substring(lastSlashIndex + 1)}`;
// 获取 LFS 上传信息
const huggingfaceAPI = new HuggingFaceAPI(hfChannel.token, hfChannel.repo, hfChannel.isPrivate || false);
+6 -2
View File
@@ -752,8 +752,12 @@ async function uploadFileToHuggingFace(context, fullId, metadata, returnLink) {
const precomputedSha256 = formdata.get('sha256') || null;
console.log('File to upload:', fileName, 'size:', file?.size, 'precomputed SHA256:', precomputedSha256 ? 'yes' : 'no');
// 构建文件路径:直接使用 fullId(与其他渠道保持一致)
const hfFilePath = fullId;
// 生成唯一标识符前缀(UUID格式),加在文件名前面
const uniquePrefix = crypto.randomUUID();
const lastSlashIndex = fullId.lastIndexOf('/');
const hfFilePath = lastSlashIndex === -1
? `${uniquePrefix}_${fullId}`
: `${fullId.substring(0, lastSlashIndex + 1)}${uniquePrefix}_${fullId.substring(lastSlashIndex + 1)}`;
console.log('HuggingFace file path:', hfFilePath);
const huggingfaceAPI = new HuggingFaceAPI(hfChannel.token, hfChannel.repo, hfChannel.isPrivate || false);