Start cleaner daemon after upload

This commit is contained in:
kamkow1
2025-06-21 18:22:26 +02:00
parent 099f4777cd
commit 5578822c3f
2 changed files with 52 additions and 0 deletions

42
lts.go
View File

@ -11,7 +11,9 @@ import (
"net"
"net/http"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
"sync"
@ -109,6 +111,34 @@ func handleUpload(w http.ResponseWriter, r *http.Request) {
limit := int64(10737418240) // 10GiB
r.ParseMultipartForm(limit)
hours_str := r.FormValue("hours")
mins_str := r.FormValue("mins")
secs_str := r.FormValue("secs")
hours, err := strconv.ParseInt(hours_str, 10, 32)
if err != nil {
http.Error(w, "Could not parse timeout hours", http.StatusBadRequest)
return
}
mins, err := strconv.ParseInt(mins_str, 10, 32)
if err != nil {
http.Error(w, "Could not parse timeout mins", http.StatusBadRequest)
return
}
secs, err := strconv.ParseInt(secs_str, 10, 32)
if err != nil {
http.Error(w, "Could not parse timeout secs", http.StatusBadRequest)
return
}
if (hours < 0 || hours > 24) || (mins < 0 || mins > 60) || (secs < 0 || secs > 60) {
http.Error(w, "Max values: 24 hours, 60 mins, 60 secs, all cannot be < 0", http.StatusBadRequest)
return
}
total := secs + mins*60 + hours*60*60
log.Printf("h: %d m: %d s: %d, total: %d\n", hours, mins, secs, total)
file, handler, err := r.FormFile("myfile")
if err != nil {
log.Println("Error getting file from form: ", err)
@ -130,7 +160,19 @@ func handleUpload(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Uploaded file: %s\n", handler.Filename)
fmt.Fprintf(w, "File size: %s\n", byteCountSI(handler.Size))
fmt.Fprintf(w, "Lifetime: %02d:%02d:%02d total %d\n", hours, mins, secs, total);
fmt.Fprintf(w, "Link: %s", fmt.Sprintf("%s/%s", listener.Addr().String(), dst.Name()))
cmd := exec.Command("./ltscleanerd", dst.Name(), strconv.FormatInt(total, 10))
log.Println("Started ", cmd.String())
err = cmd.Start()
if err != nil {
log.Println("Could not start cleaner daemon: ", err)
}
err = cmd.Process.Release()
if err != nil {
log.Fatal("Could not detach from cleaner daemon: ", err)
}
}
func handleHome(w http.ResponseWriter, r *http.Request) {