-
Notifications
You must be signed in to change notification settings - Fork 56
/
mutate.go
39 lines (34 loc) · 1.13 KB
/
mutate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package serverHandler
import "net/http"
func (h *handler) mutate(w http.ResponseWriter, r *http.Request, data *responseData) {
success := false
switch {
case data.IsUpload:
if data.CanUpload && r.Method == http.MethodPost {
success = h.saveUploadFiles(h.root+data.handlerReqPath, data.CanDelete, data.AliasSubItems, r)
}
case data.IsMkdir:
if data.CanMkdir && !h.errHandler.LogError(r.ParseForm()) {
success = h.mkdirs(h.root+data.handlerReqPath, r.Form["name"], data.AliasSubItems)
}
case data.IsDelete:
if data.CanDelete && !h.errHandler.LogError(r.ParseForm()) {
success = h.deleteItems(h.root+data.handlerReqPath, r.Form["name"], data.AliasSubItems)
}
}
if data.WantJson {
header := w.Header()
header.Set("Content-Type", "application/json; charset=utf-8")
header.Set("Cache-Control", "public, max-age=0")
w.WriteHeader(http.StatusOK)
w.Write([]byte{'{', '"', 's', 'u', 'c', 'c', 'e', 's', 's', '"', ':'})
if success {
w.Write([]byte{'t', 'r', 'u', 'e'})
} else {
w.Write([]byte{'f', 'a', 'l', 's', 'e'})
}
w.Write([]byte{'}'})
} else {
http.Redirect(w, r, r.URL.Path, http.StatusFound)
}
}