-
Notifications
You must be signed in to change notification settings - Fork 55
/
mutate.go
60 lines (53 loc) · 1.56 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package serverHandler
import (
"net/http"
"strings"
)
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(data.AuthUserName, h.root+data.handlerReqPath, data.CanMkdir, data.CanDelete, data.AliasSubItems, r)
}
case data.IsMkdir:
if data.CanMkdir && !h.errHandler.LogError(r.ParseForm()) {
success = h.mkdirs(data.AuthUserName, h.root+data.handlerReqPath, r.Form["name"], data.AliasSubItems, r)
}
case data.IsDelete:
if data.CanDelete && !h.errHandler.LogError(r.ParseForm()) {
success = h.deleteItems(data.AuthUserName, h.root+data.handlerReqPath, r.Form["name"], data.AliasSubItems, r)
}
}
if data.WantJson {
header := w.Header()
header.Set("Content-Type", "application/json; charset=utf-8")
header.Set("Cache-Control", "public, max-age=0")
if success {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"success":true}`))
} else {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(`{"success":false}`))
}
} else {
reqPath := r.RequestURI
qsIndex := strings.IndexByte(reqPath, '?')
if qsIndex >= 0 {
reqPath = reqPath[:qsIndex]
}
ctxQsList := r.Form["contextquerystring"]
ctxQsListLen := len(ctxQsList)
if ctxQsListLen > 0 {
ctxQs := ctxQsList[ctxQsListLen-1]
if len(ctxQs) > 0 {
reqPath += ctxQs
}
}
if success {
http.Redirect(w, r, reqPath, http.StatusFound)
} else {
w.WriteHeader(http.StatusInternalServerError)
}
}
}