format code and remove useless code

This commit is contained in:
codeskyblue
2019-02-21 20:23:29 +08:00
parent 41ba422675
commit c8d67edf2c
4 changed files with 40 additions and 63 deletions

View File

@@ -111,7 +111,7 @@ docker run -it --rm -p 8000:8000 -v $PWD:/app/public --name gohttpserver \
$ gohttpserver --auth-type openid --auth-openid https://login.example-hostname.com/openid/ $ gohttpserver --auth-type openid --auth-openid https://login.example-hostname.com/openid/
``` ```
- Use oauth2 with - Use oauth2 with (TODO: need more details)
```sh ```sh
$ gohttpserver --auth-type oauth2-proxy $ gohttpserver --auth-type oauth2-proxy

View File

@@ -235,7 +235,7 @@ var vm = new Vue({
$.ajax({ $.ajax({
url: pathJoin(["/", location.pathname, f.name]), url: pathJoin(["/", location.pathname, f.name]),
data: { data: {
op: "info", op: "info",
}, },
method: "GET", method: "GET",
success: function (res) { success: function (res) {
@@ -254,9 +254,6 @@ var vm = new Vue({
} }
$.ajax({ $.ajax({
url: pathJoin(["/", location.pathname, "/", name]), url: pathJoin(["/", location.pathname, "/", name]),
data: {
op: "mkdir",
},
method: "POST", method: "POST",
success: function (res) { success: function (res) {
console.log(res) console.log(res)
@@ -348,10 +345,10 @@ window.onpopstate = function (event) {
function loadFileOrDir(reqPath) { function loadFileOrDir(reqPath) {
let requestUri = reqPath + location.search let requestUri = reqPath + location.search
var retObj = loadFileList(requestUri) var retObj = loadFileList(requestUri)
if(retObj !== null) { if (retObj !== null) {
retObj.done(function (value) { retObj.done(function () {
window.history.pushState({}, "", requestUri); window.history.pushState({}, "", requestUri);
}); });
} }
} }
@@ -374,12 +371,12 @@ function loadFileList(pathname) {
vm.auth = res.auth; vm.auth = res.auth;
}, },
error: function (jqXHR, textStatus, errorThrown) { error: function (jqXHR, textStatus, errorThrown) {
let errMsg = jqXHR.getResponseHeader("x-auth-authentication-message") let errMsg = jqXHR.getResponseHeader("x-auth-authentication-message")
if(errMsg==null){ if (errMsg == null) {
errMsg = jqXHR.statusText errMsg = jqXHR.statusText
} }
alert(String(jqXHR.status).concat(":", errMsg)); alert(String(jqXHR.status).concat(":", errMsg));
console.error(errMsg) console.error(errMsg)
}, },
}); });

View File

@@ -84,20 +84,20 @@ func NewHTTPStaticServer(root string) *HTTPStaticServer {
}() }()
m.HandleFunc("/-/status", s.hStatus) //unused m.HandleFunc("/-/status", s.hStatus) //unused
m.HandleFunc("/-/zip/{path:.*}", s.hZip) //unused m.HandleFunc("/-/zip/{path:.*}", s.hZip)
m.HandleFunc("/-/unzip/{zip_path:.*}/-/{path:.*}", s.hUnzip) //unused m.HandleFunc("/-/unzip/{zip_path:.*}/-/{path:.*}", s.hUnzip)
m.HandleFunc("/-/json/{path:.*}", s.hJSONList) //unused m.HandleFunc("/-/json/{path:.*}", s.hJSONList)
// routers for Apple *.ipa // routers for Apple *.ipa
m.HandleFunc("/-/ipa/plist/{path:.*}", s.hPlist) //unused m.HandleFunc("/-/ipa/plist/{path:.*}", s.hPlist)
m.HandleFunc("/-/ipa/link/{path:.*}", s.hIpaLink) //unused m.HandleFunc("/-/ipa/link/{path:.*}", s.hIpaLink)
// TODO: /ipa/info // TODO: /ipa/info
m.HandleFunc("/-/info/{path:.*}", s.hInfo) //unused m.HandleFunc("/-/info/{path:.*}", s.hInfo)
m.HandleFunc("/-/mkdir/{path:.*}", s.hMkdir) //unused m.HandleFunc("/-/mkdir/{path:.*}", s.hMkdir)
m.HandleFunc("/{path:.*}", s.hGet).Methods("GET", "HEAD") m.HandleFunc("/{path:.*}", s.hIndex).Methods("GET", "HEAD")
m.HandleFunc("/{path:.*}", s.hPOST).Methods("POST") m.HandleFunc("/{path:.*}", s.hUploadOrMkdir).Methods("POST")
m.HandleFunc("/{path:.*}", s.hDELETE).Methods("DELETE") m.HandleFunc("/{path:.*}", s.hDelete).Methods("DELETE")
return s return s
} }
@@ -105,29 +105,6 @@ func (s *HTTPStaticServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s.m.ServeHTTP(w, r) s.m.ServeHTTP(w, r)
} }
func (s *HTTPStaticServer) hGet(w http.ResponseWriter, r *http.Request) {
if r.FormValue("op") == "info" {
s.hInfo(w, r)
}else {
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) { func (s *HTTPStaticServer) hIndex(w http.ResponseWriter, r *http.Request) {
path := mux.Vars(r)["path"] path := mux.Vars(r)["path"]
relPath := filepath.Join(s.Root, path) relPath := filepath.Join(s.Root, path)
@@ -136,6 +113,11 @@ func (s *HTTPStaticServer) hIndex(w http.ResponseWriter, r *http.Request) {
return return
} }
if r.FormValue("op") == "info" {
s.hInfo(w, r)
return
}
log.Println("GET", path, relPath) log.Println("GET", path, relPath)
if r.FormValue("raw") == "false" || isDir(relPath) { if r.FormValue("raw") == "false" || isDir(relPath) {
if r.Method == "HEAD" { if r.Method == "HEAD" {
@@ -188,7 +170,6 @@ func (s *HTTPStaticServer) hDelete(w http.ResponseWriter, req *http.Request) {
// only can delete file now // only can delete file now
path := mux.Vars(req)["path"] path := mux.Vars(req)["path"]
auth := s.readAccessConf(path) auth := s.readAccessConf(path)
log.Printf("%#v", auth)
if !auth.canDelete(req) { if !auth.canDelete(req) {
http.Error(w, "Delete forbidden", http.StatusForbidden) http.Error(w, "Delete forbidden", http.StatusForbidden)
return return
@@ -201,7 +182,7 @@ func (s *HTTPStaticServer) hDelete(w http.ResponseWriter, req *http.Request) {
w.Write([]byte("Success")) 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"] path := mux.Vars(req)["path"]
dirpath := filepath.Join(s.Root, path) dirpath := filepath.Join(s.Root, path)
@@ -220,14 +201,15 @@ func (s *HTTPStaticServer) hUpload(w http.ResponseWriter, req *http.Request) {
http.Error(w, "Directory create "+err.Error(), http.StatusInternalServerError) http.Error(w, "Directory create "+err.Error(), http.StatusInternalServerError)
return return
} }
if file == nil { }
w.Header().Set("Content-Type", "application/json;charset=utf-8")
json.NewEncoder(w).Encode(map[string]interface{}{ if file == nil { // only mkdir
"success": true, w.Header().Set("Content-Type", "application/json;charset=utf-8")
"destination": dirpath, json.NewEncoder(w).Encode(map[string]interface{}{
}) "success": true,
return "destination": dirpath,
} })
return
} }
if err != nil { if err != nil {
@@ -337,7 +319,7 @@ func (s *HTTPStaticServer) hInfo(w http.ResponseWriter, r *http.Request) {
fji.Type = "apk" fji.Type = "apk"
fji.Extra = parseApkInfo(relPath) fji.Extra = parseApkInfo(relPath)
case "": case "":
fji.Type = "Dir" fji.Type = "dir"
default: default:
fji.Type = "text" fji.Type = "text"
} }

View File

@@ -1,15 +1,14 @@
package main package main
import ( import (
"net/http"
"encoding/json" "encoding/json"
"net/http"
"net/url" "net/url"
) )
func handleOauth2() { func handleOauth2() {
http.HandleFunc("/-/user", func(w http.ResponseWriter, r *http.Request) { 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 var fullName string
for k := range fullNameMap { for k := range fullNameMap {
fullName = k fullName = k
@@ -25,5 +24,4 @@ func handleOauth2() {
data, _ := json.Marshal(user) data, _ := json.Marshal(user)
w.Write(data) w.Write(data)
}) })
} }