From 605773deccdf4d85f9e59fe65f2709549f5fd76a Mon Sep 17 00:00:00 2001 From: ZizzyDizzyMC Date: Mon, 22 Feb 2021 00:13:04 -0500 Subject: [PATCH] Adding in Large Files adjustable expiry limit. --- server.go | 4 ++++ upload.go | 12 ++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/server.go b/server.go index fcce5ce..08f3b7b 100644 --- a/server.go +++ b/server.go @@ -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() diff --git a/upload.go b/upload.go index 3ba7329..e24a8b7 100644 --- a/upload.go +++ b/upload.go @@ -321,9 +321,17 @@ 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 { - fileExpiry = expiry.NeverExpire + if upReq.size > Config.maxDurationSize && Config.maxDurationTime > 0 { + fileExpiry = time.Now().Add(Config.maxDurationTime) + } else { + fileExpiry = expiry.NeverExpire + } } else { - fileExpiry = time.Now().Add(upReq.expiry) + 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 == "" {