1
0

Added Delete handler to UploadHandlers.

This commit is contained in:
Alexander Andreev 2022-07-01 03:31:33 +04:00
parent 023fdab96f
commit 43a2f6b9d5
Signed by: Arav
GPG Key ID: 0388CC8FAA51063F

View File

@ -180,6 +180,31 @@ func (h *UploadHandlers) Download(w http.ResponseWriter, r *http.Request) {
http.ServeContent(w, r, path, stat.ModTime(), fd) http.ServeContent(w, r, path, stat.ModTime(), fd)
} }
func (h *UploadHandlers) Delete(w http.ResponseWriter, r *http.Request) {
saltedHash := server.GetURLParam(r, "hash")
path := path.Join(h.conf.Uploads.Directory, saltedHash)
_, err := os.Stat(path)
if os.IsNotExist(err) {
h.NotFound(w, r)
return
}
err = os.Remove(path)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprint(w, err)
return
}
netTyp, _ := utils.NetworkType(r.Host)
h.logDelete.Printf("| %s | %s | %s | %s", r.Header.Get("X-Real-IP"), netTyp, saltedHash, r.UserAgent())
w.WriteHeader(http.StatusNoContent)
}
func (h *UploadHandlers) NotFound(w http.ResponseWriter, r *http.Request) { func (h *UploadHandlers) NotFound(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
if !strings.Contains(r.UserAgent(), "curl") { if !strings.Contains(r.UserAgent(), "curl") {