Move file expiry time to config file

This commit is contained in:
hgw 2023-12-10 05:32:53 +00:00
parent 579a2ac26b
commit 979c7e34d4
Signed by: hgw
SSH Key Fingerprint: SHA256:diG7RVYHjd3aDYkZWHYcBJbImu+6zfptuUP+3k/wol4
2 changed files with 10 additions and 8 deletions

View File

@ -4,3 +4,4 @@ vhost = "hardfiles.org"
dbfile = "dbfile.db" dbfile = "dbfile.db"
filelen = 6 filelen = 6
folder = "files" folder = "files"
fileexpiry = 86400

15
main.go
View File

@ -23,12 +23,13 @@ var (
) )
type Config struct { type Config struct {
Webroot string `toml:"webroot"` Webroot string `toml:"webroot"`
LPort string `toml:"lport"` LPort string `toml:"lport"`
VHost string `toml:"vhost"` VHost string `toml:"vhost"`
DBFile string `toml:"dbfile"` DBFile string `toml:"dbfile"`
FileLen int `toml:"filelen"` FileLen int `toml:"filelen"`
FileFolder string `toml:"folder"` FileFolder string `toml:"folder"`
FileExpirySeconds int `toml:"fileexpiry"`
} }
func LoadConf() { func LoadConf() {
@ -120,7 +121,7 @@ func CheckFile(name string) bool { // false if doesn't exist, true if exists
func UploadHandler(w http.ResponseWriter, r *http.Request) { func UploadHandler(w http.ResponseWriter, r *http.Request) {
// expiry sanitize // expiry sanitize
twentyfour := int64(86400) twentyfour := int64(conf.FileExpirySeconds)
file, _, err := r.FormFile("file") file, _, err := r.FormFile("file")
if err != nil { if err != nil {