Skip to content

Commit d827497

Browse files
committed
Add upload space check and update version to v4.0.0
Introduced a check to skip uploading files that exceed the user's available space for files larger than 64MB. Updated version references to v4.0.0 in README, main.go, and versioninfo.json. Minor documentation and config table formatting improvements.
1 parent f023c76 commit d827497

File tree

7 files changed

+43
-11
lines changed

7 files changed

+43
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ iikira/BaiduPCS-Go was largely inspired by [GangZhuo/BaiduPCS](https://github.co
9595
[离线下载](#离线下载), 支持http/https/ftp/电驴/磁力链协议.
9696
# 版本更新
9797

98-
**2025.10.28** v4.0.0
98+
**2025.10.29** v4.0.0
9999
- 上传重新支持跳过秒传`--norapid`
100100
- 上传同名文件覆盖策略`--policy`支持`skip`,`overwrite`,`rsync`; 支持`config`配置全局默认策略
101101
- 因接口变化上传不再支持断点续传, 下载不受影响

baidupcs/quota.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,24 @@ func (pcs *BaiduPCS) QuotaInfo() (quota, used int64, pcsError pcserror.Error) {
3030

3131
return quotaInfo.Quota, quotaInfo.Used, nil
3232
}
33+
34+
// SpaceLeftInfo 获取当前用户剩余空间
35+
func (pcs *BaiduPCS) SpaceLeftInfo() (free int64, pcsError pcserror.Error) {
36+
dataReadCloser, pcsError := pcs.PrepareQuotaInfo()
37+
if pcsError != nil {
38+
return
39+
}
40+
41+
defer dataReadCloser.Close()
42+
43+
quotaInfo := &quotaInfo{
44+
PCSErrInfo: pcserror.NewPCSErrorInfo(OperationQuotaInfo),
45+
}
46+
47+
pcsError = pcserror.HandleJSONParse(OperationQuotaInfo, dataReadCloser, quotaInfo)
48+
if pcsError != nil {
49+
return
50+
}
51+
52+
return quotaInfo.Quota - quotaInfo.Used, nil
53+
}

baidupcs/upload.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const (
3030
MiddleUploadThreshold = 8 * converter.GB
3131
// MaxUploadThreshold 最大分片对应的文件大小
3232
MaxUploadThreshold = 32 * converter.GB
33+
// MinCheckLeftSpaceThreshold 需要检查剩余空间是否足够的最小文件大小
34+
MinCheckLeftSpaceThreshold = 64 * converter.MB
3335
)
3436

3537
var (

internal/pcsconfig/export.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (c *PCSConfig) PrintTable() {
7373
[]string{"max_download_load", strconv.Itoa(c.MaxDownloadLoad), "1 ~ 5", "同时进行下载文件的最大数量"},
7474
[]string{"max_download_rate", showMaxRate(c.MaxDownloadRate), "", "限制最大下载速度, 0代表不限制"},
7575
[]string{"max_upload_rate", showMaxRate(c.MaxUploadRate), "", "限制最大上传速度, 0代表不限制"},
76-
[]string{"max_upload_load", strconv.Itoa(c.MaxUploadLoad), "1-4", "同时进行上传文件的最大数量"},
76+
[]string{"max_upload_load", strconv.Itoa(c.MaxUploadLoad), "1 ~ 4", "同时进行上传文件的最大数量"},
7777
[]string{"savedir", c.SaveDir, "", "下载文件的储存目录"},
7878
[]string{"enable_https", fmt.Sprint(c.EnableHTTPS), "true", "启用 https"},
7979
[]string{"force_login_username", fmt.Sprint(c.ForceLogin), "留空", "强制登录指定用户名, 适用于tieba用户信息接口不可用的情况, 如登录正常请留空"},

internal/pcsfunctions/pcsupload/upload_task_unit.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ func (utu *UploadTaskUnit) prepareFile() {
9191
fmt.Printf("[%s] 文件超过32GB, 上传有可能失败, 建议分割文件...\n", utu.taskInfo.Id())
9292
}
9393

94+
if utu.LocalFileChecksum.Length > baidupcs.MinCheckLeftSpaceThreshold {
95+
freeSpace, err := utu.PCS.SpaceLeftInfo()
96+
if err == nil && freeSpace < utu.LocalFileChecksum.Length {
97+
fmt.Printf("[%s] 目标文件大小超过剩余空间, 跳过...\n", utu.taskInfo.Id())
98+
utu.Step = JustGoon
99+
return
100+
}
101+
}
102+
94103
if utu.NoRapidUpload {
95104
//fmt.Printf("[%s] 注意: 跳过秒传将无法使用断点续传...\n", utu.taskInfo.Id())
96105
pcsError, jsonData := utu.PCS.FakeRapidUpload(utu.SavePath, utu.Policy, utu.LocalFileChecksum.Length)

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const (
5555

5656
var (
5757
// Version 版本号
58-
Version = "v3.9.9-devel"
58+
Version = "v4.0.0-stable"
5959

6060
historyFilePath = filepath.Join(pcsconfig.GetConfigDir(), "pcs_command_history.txt")
6161
reloadFn = func(c *cli.Context) error {

versioninfo.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"FixedFileInfo": {
33
"FileVersion": {
4-
"Major": 3,
5-
"Minor": 9,
6-
"Patch": 9,
4+
"Major": 4,
5+
"Minor": 0,
6+
"Patch": 0,
77
"Build": 0
88
},
99
"ProductVersion": {
10-
"Major": 3,
11-
"Minor": 9,
12-
"Patch": 9,
10+
"Major": 4,
11+
"Minor": 0,
12+
"Patch": 0,
1313
"Build": 0
1414
},
1515
"FileFlagsMask": "3f",
@@ -22,14 +22,14 @@
2222
"Comments": "",
2323
"CompanyName": "qjfoidnh",
2424
"FileDescription": "百度网盘客户端(加强版)",
25-
"FileVersion": "v3.9.9",
25+
"FileVersion": "v4.0.0",
2626
"InternalName": "",
2727
"LegalCopyright": "© 2018-2025 qjfoidnh.",
2828
"LegalTrademarks": "",
2929
"OriginalFilename": "",
3030
"PrivateBuild": "",
3131
"ProductName": "BaiduPCS-Go",
32-
"ProductVersion": "v3.9.9",
32+
"ProductVersion": "v4.0.0",
3333
"SpecialBuild": ""
3434
},
3535
"VarFileInfo": {

0 commit comments

Comments
 (0)