Adding in Large Files adjustable expiry limit.

This commit is contained in:
ZizzyDizzyMC 2021-02-22 00:13:04 -05:00
parent 7953f31ff5
commit 605773decc
2 changed files with 14 additions and 2 deletions

View File

@ -75,6 +75,8 @@ var Config struct {
customPagesDir string
cleanupEveryMinutes uint64
extraFooterText string
maxDurationTime uint64
maxDurationSize int64
}
var Templates = make(map[string]*pongo2.Template)
@ -309,6 +311,8 @@ func main() {
"How often to clean up expired files in minutes (default is 0, which means files will be cleaned up as they are accessed)")
flag.StringVar(&Config.extraFooterText, "extra-footer-text", "",
"Extra text above the footer for notices.")
flag.Uint64Var(&Config.maxDurationTime, "max-duration-time", 0, "Time till expiry for files over max-duration-size")
flag.Int64Var(&Config.maxDurationSize, "max-duration-size", 4*1024*1024*1024, "Size of file before max-duration-time is used to determine expiry max time.")
iniflags.Parse()

View File

@ -321,10 +321,18 @@ func processUpload(upReq UploadRequest) (upload Upload, err error) {
// Get the rest of the metadata needed for storage
var fileExpiry time.Time
if upReq.expiry == 0 {
if upReq.size > Config.maxDurationSize && Config.maxDurationTime > 0 {
fileExpiry = time.Now().Add(Config.maxDurationTime)
} else {
fileExpiry = expiry.NeverExpire
}
} else {
if upReq.size > Config.maxDurationSize && upReq.expiry > Config.maxDurationTime {
fileExpiry = time.Now().Add(Config.maxDurationTime)
} else {
fileExpiry = time.Now().Add(upReq.expiry)
}
}
if upReq.deleteKey == "" {
upReq.deleteKey = uniuri.NewLen(30)