Skip to content

Commit

Permalink
Move maximum TTL to config file
Browse files Browse the repository at this point in the history
  • Loading branch information
hgw8 committed Dec 13, 2023
1 parent d84826a commit e82b466
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ vhost = "hardfiles.org"
dbfile = "dbfile.db"
filelen = 6
folder = "files"
ttl_seconds = 86400
default_ttl = 86400
maximum_ttl = 432000
9 changes: 5 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ type Config struct {
DBFile string `toml:"dbfile"`
FileLen int `toml:"filelen"`
FileFolder string `toml:"folder"`
TTLSeconds int `toml:"ttl_seconds"`
DefaultTTL int `toml:"default_ttl"`
MaxTTL int `toml:"maximum_ttl"`
}

func LoadConf() {
Expand Down Expand Up @@ -144,8 +145,8 @@ func UploadHandler(w http.ResponseWriter, r *http.Request) {
if err != nil {
log.Error().Err(err).Msg("expiry could not be parsed")
} else {
// 5 days max
if ttl < 1 || ttl > 432000 {
// Get maximum ttl length from config and kill upload if specified ttl is too long, this can probably be handled better in the future
if ttl < 1 || ttl > int64(conf.MaxTTL) {
w.WriteHeader(http.StatusBadRequest)
return
}
Expand All @@ -154,7 +155,7 @@ func UploadHandler(w http.ResponseWriter, r *http.Request) {

// Default to conf if not present
if ttl == 0 {
ttl = int64(conf.TTLSeconds)
ttl = int64(conf.DefaultTTL)
}

// Check if the file length parameter exists and also if it's too long
Expand Down

0 comments on commit e82b466

Please sign in to comment.