1
0
Fork 0

Saved 2 lines by deferring each of two calls instead of wrapping in an anonymous func.

Also, removed old cURL handling in an Upload handler.
This commit is contained in:
Alexander Andreev 2023-05-26 22:17:03 +04:00
parent 345869608e
commit 9a889e746a
Signed by: Arav
GPG Key ID: D22A817D95815393
1 changed files with 3 additions and 10 deletions

View File

@ -74,10 +74,8 @@ func (h *UploadHandlers) Upload(w http.ResponseWriter, r *http.Request) {
Error(w, r, http.StatusInternalServerError, "Error reading an incoming file.")
return
}
defer func() {
os.Remove(fHandler.Filename)
f.Close()
}()
defer os.Remove(fHandler.Filename)
defer f.Close()
var leftSpace int64 = storCapacity - *h.uploadDirSize
@ -148,13 +146,8 @@ func (h *UploadHandlers) Upload(w http.ResponseWriter, r *http.Request) {
_, scheme := utils.NetworkType(r.Host)
site := scheme + "://" + r.Host
if strings.Contains(r.UserAgent(), "curl") {
w.Write([]byte(site + downloadURLParsed.String() + "\r\n"))
return
}
if strings.Contains(r.UserAgent(), "curl") || strings.Contains(r.UserAgent(), "Wget") {
fmt.Fprintln(w, downloadURLParsed.String(), "will be kept for", h.keepForHours)
fmt.Fprintln(w, site+downloadURLParsed.String(), "will be kept for", h.keepForHours)
} else {
web.Uploaded(utils.MainSite(r.Host), site, downloadURLParsed.String(), h.keepForHours, w)
}