mirror of
https://github.com/ZSCGR/CloudFlare-ImgBed.git
synced 2026-08-18 22:53:43 +08:00
Bug:修复偶发的HF渠道移动文件导致文件丢失的问题
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user