@@ -13,13 +13,15 @@ type UploadConfig struct {
1313 EnableChunk int `json:"enable_chunk"` // 是否启用分片上传 0-禁用 1-启用
1414 ChunkSize int64 `json:"chunk_size"` // 分片大小(字节)
1515 MaxSaveSeconds int `json:"max_save_seconds"` // 最大保存时间(秒)
16+ RequireLogin int `json:"require_login"` // 上传是否强制登录 0-否 1-是
1617}
1718
1819// DownloadConfig 下载配置
1920type DownloadConfig struct {
2021 EnableConcurrentDownload int `json:"enable_concurrent_download"` // 是否启用并发下载
2122 MaxConcurrentDownloads int `json:"max_concurrent_downloads"` // 最大并发下载数
2223 DownloadTimeout int `json:"download_timeout"` // 下载超时时间(秒)
24+ RequireLogin int `json:"require_login"` // 下载是否强制登录 0-否 1-是
2325}
2426
2527// TransferConfig 文件传输配置(包含上传和下载)
@@ -36,6 +38,7 @@ func NewUploadConfig() *UploadConfig {
3638 EnableChunk : 0 ,
3739 ChunkSize : 2 * 1024 * 1024 , // 2MB
3840 MaxSaveSeconds : 0 , // 0表示不限制
41+ RequireLogin : 0 ,
3942 }
4043}
4144
@@ -45,6 +48,7 @@ func NewDownloadConfig() *DownloadConfig {
4548 EnableConcurrentDownload : 1 , // 默认启用
4649 MaxConcurrentDownloads : 10 , // 最大10个并发
4750 DownloadTimeout : 300 , // 5分钟超时
51+ RequireLogin : 0 ,
4852 }
4953}
5054
@@ -86,6 +90,10 @@ func (uc *UploadConfig) Validate() error {
8690 errors = append (errors , "最大保存时间不能为负数" )
8791 }
8892
93+ if uc .RequireLogin != 0 && uc .RequireLogin != 1 {
94+ errors = append (errors , "上传登录开关只能是0或1" )
95+ }
96+
8997 if len (errors ) > 0 {
9098 return fmt .Errorf ("上传配置验证失败: %s" , strings .Join (errors , "; " ))
9199 }
@@ -113,6 +121,10 @@ func (dc *DownloadConfig) Validate() error {
113121 errors = append (errors , "下载超时时间不能超过1小时" )
114122 }
115123
124+ if dc .RequireLogin != 0 && dc .RequireLogin != 1 {
125+ errors = append (errors , "下载登录开关只能是0或1" )
126+ }
127+
116128 if len (errors ) > 0 {
117129 return fmt .Errorf ("下载配置验证失败: %s" , strings .Join (errors , "; " ))
118130 }
@@ -138,6 +150,11 @@ func (uc *UploadConfig) IsChunkEnabled() bool {
138150 return uc .EnableChunk == 1
139151}
140152
153+ // IsLoginRequired 判断是否需要登录才能上传
154+ func (uc * UploadConfig ) IsLoginRequired () bool {
155+ return uc .RequireLogin == 1
156+ }
157+
141158// GetUploadSizeMB 获取上传大小限制(MB)
142159func (uc * UploadConfig ) GetUploadSizeMB () float64 {
143160 return float64 (uc .UploadSize ) / (1024 * 1024 )
@@ -161,6 +178,11 @@ func (dc *DownloadConfig) IsDownloadConcurrentEnabled() bool {
161178 return dc .EnableConcurrentDownload == 1
162179}
163180
181+ // IsLoginRequired 判断是否需要登录才能下载
182+ func (dc * DownloadConfig ) IsLoginRequired () bool {
183+ return dc .RequireLogin == 1
184+ }
185+
164186// GetDownloadTimeoutMinutes 获取下载超时时间(分钟)
165187func (dc * DownloadConfig ) GetDownloadTimeoutMinutes () float64 {
166188 return float64 (dc .DownloadTimeout ) / 60
@@ -174,6 +196,7 @@ func (uc *UploadConfig) Clone() *UploadConfig {
174196 EnableChunk : uc .EnableChunk ,
175197 ChunkSize : uc .ChunkSize ,
176198 MaxSaveSeconds : uc .MaxSaveSeconds ,
199+ RequireLogin : uc .RequireLogin ,
177200 }
178201}
179202
@@ -183,6 +206,7 @@ func (dc *DownloadConfig) Clone() *DownloadConfig {
183206 EnableConcurrentDownload : dc .EnableConcurrentDownload ,
184207 MaxConcurrentDownloads : dc .MaxConcurrentDownloads ,
185208 DownloadTimeout : dc .DownloadTimeout ,
209+ RequireLogin : dc .RequireLogin ,
186210 }
187211}
188212
0 commit comments