fix(terabox): big file upload issue (#7498 close #7490)

This commit is contained in:
Jason-Fly
2024-11-16 13:18:49 +08:00
committed by GitHub
parent 0a46979c51
commit 6c38c5972d
3 changed files with 88 additions and 59 deletions

View File

@ -17,6 +17,11 @@ import (
log "github.com/sirupsen/logrus"
)
const (
initialChunkSize int64 = 4 << 20 // 4MB
initialSizeThreshold int64 = 4 << 30 // 4GB
)
func getStrBetween(raw, start, end string) string {
regexPattern := fmt.Sprintf(`%s(.*?)%s`, regexp.QuoteMeta(start), regexp.QuoteMeta(end))
regex := regexp.MustCompile(regexPattern)
@ -258,3 +263,19 @@ func encodeURIComponent(str string) string {
r = strings.ReplaceAll(r, "+", "%20")
return r
}
func calculateChunkSize(streamSize int64) int64 {
chunkSize := initialChunkSize
sizeThreshold := initialSizeThreshold
if streamSize < chunkSize {
return streamSize
}
for streamSize > sizeThreshold {
chunkSize <<= 1
sizeThreshold <<= 1
}
return chunkSize
}