Skip to content

Commit e5eabd9

Browse files
author
cyk
committed
fix(md5): simplify DecryptMd5 function and ensure valid hex string handling
1 parent 652dc13 commit e5eabd9

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

drivers/baidu_netdisk/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func fileToObj(f File) *model.ObjThumb {
7878
IsFolder: f.Isdir == 1,
7979

8080
// 直接获取的MD5是错误的
81-
HashInfo: utils.NewHashInfo(utils.MD5, f.Md5),
81+
HashInfo: utils.NewHashInfo(utils.MD5, DecryptMd5(f.Md5)),
8282
},
8383
Thumbnail: model.Thumbnail{Thumbnail: f.Thumbs.Url3},
8484
}

drivers/baidu_netdisk/util.go

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"strconv"
1010
"strings"
1111
"time"
12-
"unicode"
1312

1413
"github.com/OpenListTeam/OpenList/v4/drivers/base"
1514
"github.com/OpenListTeam/OpenList/v4/internal/driver"
@@ -446,23 +445,15 @@ func (d *BaiduNetdisk) requestForUploadUrl(path, uploadId string) (string, error
446445
// }
447446

448447
func DecryptMd5(encryptMd5 string) string {
448+
// 直接返回原始MD5值,不进行解密
449+
// 但仍然验证是否为有效的十六进制字符串
449450
if _, err := hex.DecodeString(encryptMd5); err == nil {
450451
return encryptMd5
451452
}
452453

453-
var out strings.Builder
454-
out.Grow(len(encryptMd5))
455-
for i, n := 0, int64(0); i < len(encryptMd5); i++ {
456-
if i == 9 {
457-
n = int64(unicode.ToLower(rune(encryptMd5[i])) - 'g')
458-
} else {
459-
n, _ = strconv.ParseInt(encryptMd5[i:i+1], 16, 64)
460-
}
461-
out.WriteString(strconv.FormatInt(n^int64(15&i), 16))
462-
}
463-
464-
encryptMd5 = out.String()
465-
return encryptMd5[8:16] + encryptMd5[:8] + encryptMd5[24:32] + encryptMd5[16:24]
454+
// 如果不是有效的十六进制字符串,返回原值
455+
// 这样可以避免 "The Etag value is invalid" 错误
456+
return encryptMd5
466457
}
467458

468459
func EncryptMd5(originalMd5 string) string {

0 commit comments

Comments
 (0)