@@ -255,11 +255,21 @@ func UploadText(absPath string) (string, string, error) {
255255 SetRetryCount (2 ).
256256 SetRetryBackoffInterval (1 * time .Second , 5 * time .Second ).
257257 SetRetryFixedInterval (2 * time .Second )
258+ // 打开文件
258259 file , err := os .Open (absPath )
259260 if err != nil {
260261 return "" , "" , fmt .Errorf ("failed to open file: %w" , err )
261262 }
262263 defer file .Close ()
264+ // 获取文件信息并检查大小
265+ fileInfo , err := file .Stat ()
266+ if err != nil {
267+ return "" , "" , fmt .Errorf ("failed to get file info: %w" , err )
268+ }
269+ if fileInfo .Size () > 25 * 1024 { // 25KB
270+ return "" , "" , fmt .Errorf ("file size exceeds 25KB limit" )
271+ }
272+ // 上传逻辑
263273 upload := func (url string ) (string , string , error ) {
264274 file , err := os .Open (absPath )
265275 if err != nil {
@@ -288,10 +298,12 @@ func UploadText(absPath string) (string, string, error) {
288298 }
289299 return "" , "" , fmt .Errorf ("upload failed for %s with status code: %d" , url , resp .StatusCode )
290300 }
301+ // 尝试上传到主URL
291302 httpURL , httpsURL , err := upload (primaryURL )
292303 if err == nil {
293304 return httpURL , httpsURL , nil
294305 }
306+ // 尝试上传到备份URL
295307 httpURL , httpsURL , err = upload (backupURL )
296308 if err != nil {
297309 return "" , "" , fmt .Errorf ("failed to upload to both primary and backup URLs: %w" , err )
0 commit comments