Skip to content

Commit 6950b33

Browse files
committed
v3.9.2
1 parent 512438b commit 6950b33

File tree

10 files changed

+91
-41
lines changed

10 files changed

+91
-41
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ iikira/BaiduPCS-Go was largely inspired by [GangZhuo/BaiduPCS](https://github.co
100100
[离线下载](#离线下载), 支持http/https/ftp/电驴/磁力链协议.
101101

102102
# 版本更新
103+
**2023.06.03** v3.9.2
104+
- 修复秒传链接无法转存, 因官方接口变动秒传已不再支持短链接格式
105+
- 修复上传文件无法使用秒传
106+
- fix #254 支持-f参数输出带密码分享链接
107+
- fix #251 根据mengzonefire同志提供函数增加md5解密
108+
103109
**2023.03.19** v3.9.1
104110
- 修复秒传转存返回错误码9019
105111

baidupcs/file_directory.go

+1
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ func (f *FileDirectory) String() string {
311311
func (fl FileDirectoryList) fixMD5() {
312312
for _, v := range fl {
313313
v.fixMD5()
314+
v.MD5 = DecryptMD5(v.MD5)
314315
}
315316
}
316317

baidupcs/pcserror/panerrorinfo.go

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ type (
1111
ErrType ErrType
1212
Err error
1313
ErrNo int `json:"errno"`
14-
// ErrMsg string `json:"err_msg"`
1514
}
1615
)
1716

baidupcs/prepare.go

+33-29
Original file line numberDiff line numberDiff line change
@@ -301,40 +301,23 @@ func (pcs *BaiduPCS) PrepareMove(cpmvJSON ...*CpMvJSON) (dataReadCloser io.ReadC
301301

302302
// prepareRapidUpload 秒传文件, 不进行文件夹检查
303303
func (pcs *BaiduPCS) prepareRapidUpload(targetPath, contentMD5, sliceMD5, crc32 string, length int64) (dataReadCloser io.ReadCloser, pcsError pcserror.Error) {
304-
pcs.lazyInit()
305-
pcsURL := pcs.generatePCSURL("file", "rapidupload", map[string]string{
306-
"path": targetPath, // 上传文件的全路径名
307-
"content-length": strconv.FormatInt(length, 10), // 待秒传的文件长度
308-
"content-md5": contentMD5, // 待秒传的文件的MD5
309-
"slice-md5": sliceMD5, // 待秒传的文件前256kb的MD5
310-
"content-crc32": crc32, // 待秒传文件CRC32
311-
"ondup": "overwrite", // overwrite: 表示覆盖同名文件; newcopy: 表示生成文件副本并进行重命名,命名规则为“文件名_日期.后缀”; skip: 表示跳过同名文件; fail: 表示直接报错
312-
})
304+
pcsURL := pcs.generatePanURL("rapidupload", nil)
313305
baiduPCSVerbose.Infof("%s URL: %s\n", OperationRapidUpload, pcsURL)
314-
315-
dataReadCloser, pcsError = pcs.sendReqReturnReadCloser(reqTypePCS, OperationRapidUpload, http.MethodGet, pcsURL.String(), nil, nil)
316-
return
317-
}
318-
319-
// PrepareRapidUpload 秒传文件, 只返回服务器响应数据和错误信息
320-
func (pcs *BaiduPCS) PrepareRapidUpload(targetPath, contentMD5, sliceMD5, crc32 string, length int64) (dataReadCloser io.ReadCloser, pcsError pcserror.Error) {
321-
pcs.lazyInit()
322-
pcsError = pcs.CheckIsdir(OperationRapidUpload, targetPath, "", length)
323-
if pcsError != nil {
324-
return nil, pcsError
306+
post := map[string]string{
307+
"rtype": "0",
308+
"path": targetPath,
309+
"content-md5": contentMD5,
310+
"slice-md5": sliceMD5,
311+
"content-length": strconv.FormatInt(length, 10),
325312
}
313+
baiduPCSVerbose.Infof("%s URL: %s, Post: %v\n", OperationRapidUpload, pcsURL, post)
326314

327-
return pcs.prepareRapidUpload(targetPath, contentMD5, sliceMD5, crc32, length)
315+
dataReadCloser, pcsError = pcs.sendReqReturnReadCloser(reqTypePan, OperationRapidUpload, http.MethodPost, pcsURL.String(), post, nil)
316+
return
328317
}
329318

330-
// PrepareRapidUploadV2 秒传文件, 新接口
331-
func (pcs *BaiduPCS) PrepareRapidUploadV2(targetPath, contentMD5, sliceMD5 string, length int64) (dataReadCloser io.ReadCloser, pcsError pcserror.Error) {
332-
pcs.lazyInit()
333-
pcsError = pcs.CheckIsdir(OperationRapidUpload, targetPath, "", length)
334-
if pcsError != nil {
335-
return nil, pcsError
336-
}
337-
319+
// prepareRapidUploadV2 秒传文件接口2, 不进行文件夹检查
320+
func (pcs *BaiduPCS) prepareRapidUploadV2(targetPath, contentMD5, sliceMD5, crc32 string, length int64) (dataReadCloser io.ReadCloser, pcsError pcserror.Error) {
338321
pcsURL := pcs.generatePanURL("precreate", nil)
339322
post := map[string]string{
340323
"path": targetPath,
@@ -358,6 +341,27 @@ func (pcs *BaiduPCS) PrepareRapidUploadV2(targetPath, contentMD5, sliceMD5 strin
358341
return
359342
}
360343

344+
// PrepareRapidUpload 秒传文件旧接口, 只返回服务器响应数据和错误信息
345+
func (pcs *BaiduPCS) PrepareRapidUpload(targetPath, contentMD5, sliceMD5, crc32 string, length int64) (dataReadCloser io.ReadCloser, pcsError pcserror.Error) {
346+
pcs.lazyInit()
347+
pcsError = pcs.CheckIsdir(OperationRapidUpload, targetPath, "", length)
348+
if pcsError != nil {
349+
return nil, pcsError
350+
}
351+
352+
return pcs.prepareRapidUpload(targetPath, contentMD5, sliceMD5, crc32, length)
353+
}
354+
355+
// PrepareRapidUploadV2 秒传文件新接口, 只返回服务器响应数据和错误信息
356+
func (pcs *BaiduPCS) PrepareRapidUploadV2(targetPath, contentMD5, sliceMD5 string, length int64) (dataReadCloser io.ReadCloser, pcsError pcserror.Error) {
357+
pcs.lazyInit()
358+
pcsError = pcs.CheckIsdir(OperationRapidUpload, targetPath, "", length)
359+
if pcsError != nil {
360+
return nil, pcsError
361+
}
362+
return pcs.prepareRapidUploadV2(targetPath, contentMD5, sliceMD5, "", length)
363+
}
364+
361365
// PrepareLocateDownload 获取下载链接, 只返回服务器响应数据和错误信息
362366
func (pcs *BaiduPCS) PrepareLocateDownload(pcspath string) (dataReadCloser io.ReadCloser, pcsError pcserror.Error) {
363367
pcs.lazyInit()

baidupcs/share.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type (
1212
ShareOption struct {
1313
Password string // 密码
1414
Period int // 有效期
15+
IsCombined bool // 是否将密码输出到分享链接
1516
}
1617

1718
// Shared 分享信息
@@ -70,7 +71,7 @@ var (
7071
// ShareSet 分享文件
7172
func (pcs *BaiduPCS) ShareSet(paths []string, option *ShareOption) (s *Shared, pcsError pcserror.Error) {
7273
if option.Password == "" || len(option.Password) != 4 {
73-
option = &ShareOption{CreatePasswd(), option.Period}
74+
option = &ShareOption{CreatePasswd(), option.Period, option.IsCombined}
7475
}
7576

7677
dataReadCloser, pcsError := pcs.PrepareSharePSet(paths, option.Password, option.Period)

baidupcs/upload.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,11 @@ func (pcs *BaiduPCS) RapidUpload(targetPath, contentMD5, sliceMD5, crc32 string,
116116
pcs.deleteCache([]string{path.Dir(targetPath)})
117117
}
118118
}()
119-
120-
return pcs.rapidUploadV2(targetPath, strings.ToLower(contentMD5), strings.ToLower(sliceMD5), length)
119+
pcsError = pcs.rapidUploadV2(targetPath, strings.ToLower(contentMD5), strings.ToLower(sliceMD5), length)
120+
if pcsError != nil {
121+
pcsError = pcs.rapidUpload(targetPath, strings.ToLower(contentMD5), strings.ToLower(sliceMD5), "", length)
122+
}
123+
return
121124
}
122125

123126
func (pcs *BaiduPCS) rapidUpload(targetPath, contentMD5, sliceMD5, crc32 string, length int64) (pcsError pcserror.Error) {
@@ -126,7 +129,7 @@ func (pcs *BaiduPCS) rapidUpload(targetPath, contentMD5, sliceMD5, crc32 string,
126129
return
127130
}
128131
defer dataReadCloser.Close()
129-
return pcserror.DecodePCSJSONError(OperationRapidUpload, dataReadCloser)
132+
return pcserror.DecodePanJSONError(OperationRapidUpload, dataReadCloser)
130133
}
131134

132135
func (pcs *BaiduPCS) rapidUploadV2(targetPath, contentMD5, sliceMD5 string, length int64) (pcsError pcserror.Error) {

baidupcs/util.go

+28
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"github.com/qjfoidnh/BaiduPCS-Go/pcsutil/converter"
1010
"io"
1111
"path"
12+
"regexp"
13+
"strconv"
1214
"strings"
1315
"time"
1416
)
@@ -108,3 +110,29 @@ func GetHTTPScheme(https bool) (scheme string) {
108110
}
109111
return "http"
110112
}
113+
114+
func DecryptMD5(rawMD5 string) string {
115+
if len(rawMD5) != 32 {
116+
return rawMD5
117+
}
118+
var keychar string = rawMD5[9:10]
119+
match, _ := regexp.MatchString("[a-f0-9]", keychar)
120+
if match {
121+
return rawMD5
122+
}
123+
sliceFirst := fmt.Sprintf("%x", []rune(rawMD5)[9] -'g')
124+
sliceSecond := rawMD5[0:9] + sliceFirst + rawMD5[10:]
125+
sliceThird := ""
126+
for i := 0; i < len(sliceSecond); i++ {
127+
if sliceSecond[i:i+1] == "-" {
128+
sliceThird += fmt.Sprintf("%x", 15 & i)
129+
continue
130+
}
131+
num, err := strconv.ParseInt(sliceSecond[i:i+1], 16, 64)
132+
if err != nil {
133+
return rawMD5
134+
}
135+
sliceThird += fmt.Sprintf("%x", int(num) ^ (15 & i))
136+
}
137+
return sliceThird[8:16] + sliceThird[0:8] + sliceThird[24:32] + sliceThird[16:24]
138+
}

internal/pcscommand/share.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ func RunShareSet(paths []string, option *baidupcs.ShareOption) {
2525
fmt.Printf("%s失败: %s\n", baidupcs.OperationShareSet, err)
2626
return
2727
}
28-
29-
fmt.Printf("shareID: %d, 链接: %s, 密码: %s\n", shared.ShareID, shared.Link, shared.Pwd)
28+
if option.IsCombined {
29+
fmt.Printf("shareID: %d, 链接: %s?pwd=%s\n", shared.ShareID, shared.Link, shared.Pwd)
30+
} else {
31+
fmt.Printf("shareID: %d, 链接: %s, 密码: %s\n", shared.ShareID, shared.Link, shared.Pwd)
32+
}
3033
}
3134

3235
// RunShareCancel 执行取消分享

main.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const (
5555

5656
var (
5757
// Version 版本号
58-
Version = "v3.9.1-devel"
58+
Version = "v3.9.2-devel"
5959

6060
historyFilePath = filepath.Join(pcsconfig.GetConfigDir(), "pcs_command_history.txt")
6161
reloadFn = func(c *cli.Context) error {
@@ -1482,6 +1482,7 @@ func main() {
14821482
opt := &baidupcs.ShareOption{
14831483
Password: c.String("p"),
14841484
Period: c.Int("period"),
1485+
IsCombined: c.Bool("f"),
14851486
}
14861487
pcscommand.RunShareSet(c.Args(), opt)
14871488
return nil
@@ -1497,6 +1498,10 @@ func main() {
14971498
Usage: "有效天数, 0为永久",
14981499
Value: 0,
14991500
},
1501+
cli.BoolFlag{
1502+
Name: "f",
1503+
Usage: "输出带密码的完整链接格式",
1504+
},
15001505
},
15011506
},
15021507
{

versioninfo.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
"FileVersion": {
44
"Major": 3,
55
"Minor": 9,
6-
"Patch": 1,
6+
"Patch": 2,
77
"Build": 0
88
},
99
"ProductVersion": {
1010
"Major": 3,
1111
"Minor": 9,
12-
"Patch": 1,
12+
"Patch": 2,
1313
"Build": 0
1414
},
1515
"FileFlagsMask": "3f",
@@ -22,14 +22,14 @@
2222
"Comments": "",
2323
"CompanyName": "qjfoidnh",
2424
"FileDescription": "百度网盘客户端(加强版)",
25-
"FileVersion": "v3.9.1",
25+
"FileVersion": "v3.9.2",
2626
"InternalName": "",
2727
"LegalCopyright": "© 2016-2020 iikira.",
2828
"LegalTrademarks": "",
2929
"OriginalFilename": "",
3030
"PrivateBuild": "",
3131
"ProductName": "BaiduPCS-Go",
32-
"ProductVersion": "v3.9.1",
32+
"ProductVersion": "v3.9.2",
3333
"SpecialBuild": ""
3434
},
3535
"VarFileInfo": {

0 commit comments

Comments
 (0)