diff --git a/assets/js/index.js b/assets/js/index.js index 23899b5..bc97c25 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -251,7 +251,7 @@ var vm = new Vue({ $.ajax({ url: pathJoin(["/", location.pathname, f.name]), data: { - op: "info", + op: "info", }, method: "GET", success: function (res) { @@ -276,10 +276,7 @@ var vm = new Vue({ return } $.ajax({ - url: pathJoin(["/", location.pathname, name]), - data: { - op: "mkdir", - }, + url: pathJoin(["/", location.pathname, "/", name]), method: "POST", success: function (res) { console.log(res) @@ -371,10 +368,10 @@ window.onpopstate = function (event) { function loadFileOrDir(reqPath) { let requestUri = reqPath + location.search var retObj = loadFileList(requestUri) - if(retObj !== null) { - retObj.done(function (value) { - window.history.pushState({}, "", requestUri); - }); + if (retObj !== null) { + retObj.done(function () { + window.history.pushState({}, "", requestUri); + }); } } diff --git a/httpstaticserver.go b/httpstaticserver.go index 302bd0d..1754421 100644 --- a/httpstaticserver.go +++ b/httpstaticserver.go @@ -87,12 +87,9 @@ func NewHTTPStaticServer(root string) *HTTPStaticServer { m.HandleFunc("/-/ipa/plist/{path:.*}", s.hPlist) m.HandleFunc("/-/ipa/link/{path:.*}", s.hIpaLink) - // TODO: /ipa/info - - - m.HandleFunc("/{path:.*}", s.hGet).Methods("GET", "HEAD") - m.HandleFunc("/{path:.*}", s.hPOST).Methods("POST") - m.HandleFunc("/{path:.*}", s.hDELETE).Methods("DELETE") + m.HandleFunc("/{path:.*}", s.hIndex).Methods("GET", "HEAD") + m.HandleFunc("/{path:.*}", s.hUploadOrMkdir).Methods("POST") + m.HandleFunc("/{path:.*}", s.hDelete).Methods("DELETE") return s } @@ -100,32 +97,6 @@ func (s *HTTPStaticServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { s.m.ServeHTTP(w, r) } -func (s *HTTPStaticServer) hGet(w http.ResponseWriter, r *http.Request) { - switch r.FormValue("op") { - case "info": - s.hInfo(w, r) - case "archive": - s.hZip(w, r) - default: - s.hIndex(w, r) - } - return -} - -func (s *HTTPStaticServer) hPOST(w http.ResponseWriter, r *http.Request) { - if r.FormValue("op") == "mkdir" { - s.hMkdir(w, r) - }else { - s.hUpload(w, r) - } - return -} - -func (s *HTTPStaticServer) hDELETE(w http.ResponseWriter, r *http.Request) { - s.hDelete(w, r) - return -} - func (s *HTTPStaticServer) hIndex(w http.ResponseWriter, r *http.Request) { path := mux.Vars(r)["path"] relPath := filepath.Join(s.Root, path) @@ -134,6 +105,16 @@ func (s *HTTPStaticServer) hIndex(w http.ResponseWriter, r *http.Request) { return } + if r.FormValue("op") == "info" { + s.hInfo(w, r) + return + } + + if r.FormValue("op") == "archive" { + s.hZip(w, r) + return + } + log.Println("GET", path, relPath) if r.FormValue("raw") == "false" || isDir(relPath) { if r.Method == "HEAD" { @@ -180,7 +161,6 @@ func (s *HTTPStaticServer) hDelete(w http.ResponseWriter, req *http.Request) { // only can delete file now path := mux.Vars(req)["path"] auth := s.readAccessConf(path) - log.Printf("%#v", auth) if !auth.canDelete(req) { http.Error(w, "Delete forbidden", http.StatusForbidden) return @@ -188,7 +168,7 @@ func (s *HTTPStaticServer) hDelete(w http.ResponseWriter, req *http.Request) { err := os.Remove(filepath.Join(s.Root, path)) if err != nil { - pathErr, ok:= err.(*os.PathError) + pathErr, ok := err.(*os.PathError) if ok{ http.Error(w, pathErr.Op + " " + path + ": " + pathErr.Err.Error(), 500) } else { @@ -199,7 +179,7 @@ func (s *HTTPStaticServer) hDelete(w http.ResponseWriter, req *http.Request) { w.Write([]byte("Success")) } -func (s *HTTPStaticServer) hUpload(w http.ResponseWriter, req *http.Request) { +func (s *HTTPStaticServer) hUploadOrMkdir(w http.ResponseWriter, req *http.Request) { path := mux.Vars(req)["path"] dirpath := filepath.Join(s.Root, path) @@ -218,14 +198,15 @@ func (s *HTTPStaticServer) hUpload(w http.ResponseWriter, req *http.Request) { http.Error(w, "Directory create "+err.Error(), http.StatusInternalServerError) return } - if file == nil { - w.Header().Set("Content-Type", "application/json;charset=utf-8") - json.NewEncoder(w).Encode(map[string]interface{}{ - "success": true, - "destination": dirpath, - }) - return - } + } + + if file == nil { // only mkdir + w.Header().Set("Content-Type", "application/json;charset=utf-8") + json.NewEncoder(w).Encode(map[string]interface{}{ + "success": true, + "destination": dirpath, + }) + return } if err != nil { @@ -335,7 +316,7 @@ func (s *HTTPStaticServer) hInfo(w http.ResponseWriter, r *http.Request) { fji.Type = "apk" fji.Extra = parseApkInfo(relPath) case "": - fji.Type = "Dir" + fji.Type = "dir" default: fji.Type = "text" } diff --git a/oauth2-proxy.go b/oauth2-proxy.go index 6e7faf8..9b9215d 100644 --- a/oauth2-proxy.go +++ b/oauth2-proxy.go @@ -1,15 +1,14 @@ package main import ( - "net/http" "encoding/json" + "net/http" "net/url" ) func handleOauth2() { - http.HandleFunc("/-/user", func(w http.ResponseWriter, r *http.Request) { - fullNameMap, _:= url.ParseQuery(r.Header.Get("X-Auth-Request-Fullname")) + fullNameMap, _ := url.ParseQuery(r.Header.Get("X-Auth-Request-Fullname")) var fullName string for k := range fullNameMap { fullName = k @@ -25,5 +24,4 @@ func handleOauth2() { data, _ := json.Marshal(user) w.Write(data) }) - }