Added Delete handler to UploadHandlers.
This commit is contained in:
parent
023fdab96f
commit
43a2f6b9d5
@ -180,6 +180,31 @@ func (h *UploadHandlers) Download(w http.ResponseWriter, r *http.Request) {
|
||||
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) {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
if !strings.Contains(r.UserAgent(), "curl") {
|
||||
|
Loading…
Reference in New Issue
Block a user