Generate upload link

This commit is contained in:
kamkow1
2025-06-21 16:12:16 +02:00
parent 8ce2789588
commit 8d470cbe68

11
lts.go
View File

@ -117,10 +117,6 @@ func handleUpload(w http.ResponseWriter, r *http.Request) {
}
defer file.Close()
fmt.Fprintf(w, "Uploaded file: %s\n", handler.Filename)
fmt.Fprintf(w, "File size: %s\n", byteCountSI(handler.Size))
fmt.Fprintf(w, "Link: ")
dst, err := createFile(storePath, handler.Filename)
if err != nil {
http.Error(w, "Could not save file", http.StatusInternalServerError)
@ -131,6 +127,10 @@ func handleUpload(w http.ResponseWriter, r *http.Request) {
if _, err := dst.ReadFrom(file); err != nil {
http.Error(w, "Error saving file", http.StatusInternalServerError)
}
fmt.Fprintf(w, "Uploaded file: %s\n", handler.Filename)
fmt.Fprintf(w, "File size: %s\n", byteCountSI(handler.Size))
fmt.Fprintf(w, "Link: %s", fmt.Sprintf("%s/%s", listener.Addr().String(), dst.Name()))
}
func handleHome(w http.ResponseWriter, r *http.Request) {
@ -248,10 +248,11 @@ func main() {
http.Handle("/etc/", http.FileServerFS(etc))
http.Handle("/store/", http.StripPrefix("/store/", http.FileServer(http.Dir(storePath))))
listener, err := net.Listen("tcp", LISTEN_ADDR)
listener_tcp, err := net.Listen("tcp", LISTEN_ADDR)
if err != nil {
log.Fatal("Error starting server: ", err)
}
listener = listener_tcp
log.Printf("Listening on %s\n", listener.Addr().String())