1
0

Handle cURL and Wget clients.

This commit is contained in:
Alexander Andreev 2023-05-25 00:08:52 +04:00
parent b16ec84e86
commit 2ef85c6f29
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -86,7 +86,11 @@ func (h *UploadHandlers) Upload(w http.ResponseWriter, r *http.Request) {
if leftSpace < fHandler.Size { if leftSpace < fHandler.Size {
log.Println("not enough space left in storage, only", leftSpace>>20, "MiB left") log.Println("not enough space left in storage, only", leftSpace>>20, "MiB left")
if strings.Contains(r.UserAgent(), "curl") || strings.Contains(r.UserAgent(), "Wget") {
http.Error(w, "Not enough space left, sorry", http.StatusInternalServerError)
} else {
web.ErrorNoSpace(utils.MainSite(r.Host), w) web.ErrorNoSpace(utils.MainSite(r.Host), w)
}
return return
} }
@ -152,7 +156,11 @@ func (h *UploadHandlers) Upload(w http.ResponseWriter, r *http.Request) {
return return
} }
if strings.Contains(r.UserAgent(), "curl") || strings.Contains(r.UserAgent(), "Wget") {
fmt.Fprintln(w, downloadURLParsed.String(), "will be kept for", h.keepForHours)
} else {
web.Uploaded(utils.MainSite(r.Host), site, downloadURLParsed.String(), h.keepForHours, w) web.Uploaded(utils.MainSite(r.Host), site, downloadURLParsed.String(), h.keepForHours, w)
}
} }
func (h *UploadHandlers) Download(w http.ResponseWriter, r *http.Request) { func (h *UploadHandlers) Download(w http.ResponseWriter, r *http.Request) {
@ -214,7 +222,11 @@ func (h *UploadHandlers) Delete(w http.ResponseWriter, r *http.Request) {
h.logFile.Printf("dt | %s | %s | %s | %s", r.Header.Get("X-Real-IP"), netTyp, saltedHash, r.UserAgent()) h.logFile.Printf("dt | %s | %s | %s | %s", r.Header.Get("X-Real-IP"), netTyp, saltedHash, r.UserAgent())
w.WriteHeader(http.StatusNoContent) w.WriteHeader(http.StatusNoContent)
if strings.Contains(r.UserAgent(), "curl") || strings.Contains(r.UserAgent(), "Wget") {
fmt.Fprintln(w, "File was successfully deleted.")
} else {
web.Deleted(utils.MainSite(r.Host), w) web.Deleted(utils.MainSite(r.Host), w)
}
} }
func NotFound(w http.ResponseWriter, r *http.Request) { func NotFound(w http.ResponseWriter, r *http.Request) {