Skip to content

Conversation

@z1w2r3
Copy link

@z1w2r3 z1w2r3 commented Jan 29, 2026

问题描述

当上传的文件哈希与服务器上已有文件匹配时(秒传场景),file/update/hash API 会返回 finish: true,表示文件已存在无需实际上传。

但原代码忽略了这个返回值,继续尝试上传到 OSS,导致 NoSuchBucket 错误。

相关 Issues: #1, #2, #6

修复方案

在调用 _update_file_hash() 后检查返回值中的 finish 字段:

  • 如果 finishTrue,直接返回上传成功(秒传完成)
  • 否则继续正常的 OSS 上传流程

测试结果

✅ 普通上传:成功
✅ 秒传(重复文件):成功,显示 "秒传成功"

代码变更

hash_result = self._update_file_hash(task_id, md5_hash, sha1_hash)

# 检查是否秒传成功(文件已存在于服务器)
if hash_result.get('finish'):
    if progress_callback:
        progress_callback(100, "秒传成功")
    return {
        'status': 'success',
        'task_id': task_id,
        'file_name': file_name,
        'file_size': file_size,
        'md5': md5_hash,
        'sha1': sha1_hash,
        'upload_result': {'strategy': 'instant_upload', 'message': '秒传成功,文件已存在'},
        'finish_result': hash_result
    }

z1w2r3 and others added 3 commits January 29, 2026 10:46
当文件哈希与服务器上已有文件匹配时,file/update/hash API 会返回
finish: true,表示文件已存在无需上传。原代码忽略了这个返回值,
继续尝试上传到 OSS,导致 NoSuchBucket 错误。

现在检查 hash_result.finish 字段,如果为 true 则直接返回成功。

Fixes: lich0821#1, lich0821#2, lich0821#6

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
使用 file_path_obj.resolve() 将相对路径转换为绝对路径,
避免相对路径导致的异常行为

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
之前用 Path.cwd()/config,cd 后会找不到 cookie 导致要求重新登录

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant