Skip to content

Commit

Permalink
conflict resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
chenwenxiao committed Feb 22, 2019
2 parents eaa82b8 + c8d67ed commit fdec6aa
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 57 deletions.
15 changes: 6 additions & 9 deletions assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down Expand Up @@ -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);
});
}

}
Expand Down
69 changes: 25 additions & 44 deletions httpstaticserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,45 +87,16 @@ 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
}

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)
Expand All @@ -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" {
Expand Down Expand Up @@ -180,15 +161,14 @@ 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
}

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 {
Expand All @@ -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)

Expand All @@ -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 {
Expand Down Expand Up @@ -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"
}
Expand Down
6 changes: 2 additions & 4 deletions oauth2-proxy.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -25,5 +24,4 @@ func handleOauth2() {
data, _ := json.Marshal(user)
w.Write(data)
})

}

0 comments on commit fdec6aa

Please sign in to comment.