From c14c59688983be031cd576fa5ad157cfbf45fc55 Mon Sep 17 00:00:00 2001 From: MarSeventh <1193267292@qq.com> Date: Mon, 2 Mar 2026 22:13:18 +0800 Subject: [PATCH] =?UTF-8?q?Bug:=E4=BF=AE=E5=A4=8D=E5=81=B6=E5=8F=91?= =?UTF-8?q?=E7=9A=84HF=E6=B8=A0=E9=81=93=E7=A7=BB=E5=8A=A8=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=AF=BC=E8=87=B4=E6=96=87=E4=BB=B6=E4=B8=A2=E5=A4=B1?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions/upload/huggingface/getUploadUrl.js | 8 ++++++-- functions/upload/index.js | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/functions/upload/huggingface/getUploadUrl.js b/functions/upload/huggingface/getUploadUrl.js index 7003e451..47a974ad 100644 --- a/functions/upload/huggingface/getUploadUrl.js +++ b/functions/upload/huggingface/getUploadUrl.js @@ -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); diff --git a/functions/upload/index.js b/functions/upload/index.js index f97968c1..2a20b834 100644 --- a/functions/upload/index.js +++ b/functions/upload/index.js @@ -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);