Move maximum TTL to config file

This commit is contained in:
hgw 2023-12-13 13:57:31 +00:00
parent d84826ae66
commit e82b4661c6
Signed by: hgw
SSH Key Fingerprint: SHA256:diG7RVYHjd3aDYkZWHYcBJbImu+6zfptuUP+3k/wol4
2 changed files with 7 additions and 5 deletions

View File

@ -4,4 +4,5 @@ vhost = "hardfiles.org"
dbfile = "dbfile.db"
filelen = 6
folder = "files"
ttl_seconds = 86400
default_ttl = 86400
maximum_ttl = 432000

View File

@ -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() {
@ -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
}
@ -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