Skip to content

Commit

Permalink
fix some prefix error
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Mar 30, 2021
1 parent 5a7724d commit e99a12b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 37 deletions.
20 changes: 10 additions & 10 deletions assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="theme-color" content="#000000">
<title>[[.Title]]</title>
<link rel="shortcut icon" type="image/png" href="/-/assets/favicon.png" />
<link rel="stylesheet" type="text/css" href="/-/assets/bootstrap-3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/-/assets/font-awesome-4.6.3/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="/-/assets/css/github-markdown.css">
<link rel="stylesheet" type="text/css" href="/-/assets/css/dropzone.css">
<link rel="stylesheet" type="text/css" href="/-/assets/css/scrollUp-image.css">
<link rel="stylesheet" type="text/css" href="/-/assets/css/style.css">
<link rel="stylesheet" type="text/css" href="/-/assets/themes/[[.Theme]].css">
<link rel="shortcut icon" type="image/png" href="[[.Prefix]]/-/assets/favicon.png" />
<link rel="stylesheet" type="text/css" href="[[.Prefix]]/-/assets/bootstrap-3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="[[.Prefix]]/-/assets/font-awesome-4.6.3/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="[[.Prefix]]/-/assets/css/github-markdown.css">
<link rel="stylesheet" type="text/css" href="[[.Prefix]]/-/assets/css/dropzone.css">
<link rel="stylesheet" type="text/css" href="[[.Prefix]]/-/assets/css/scrollUp-image.css">
<link rel="stylesheet" type="text/css" href="[[.Prefix]]/-/assets/css/style.css">
<link rel="stylesheet" type="text/css" href="[[.Prefix]]/-/assets/themes/[[.Theme]].css">
</head>

<body id="app">
Expand All @@ -27,7 +27,7 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">[[.Title]]</a>
<a class="navbar-brand" href="[[.Prefix]]/">[[.Title]]</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-2">
<ul class="nav navbar-nav">
Expand Down Expand Up @@ -262,7 +262,7 @@ <h4 class="modal-title">
</div>
</div>
<script>
// window.URL_PFEFIX = "[[.Prefix]]"
window.URL_PFEFIX = "[[.Prefix]]"
</script>
<script src="[[.Prefix]]/-/assets/js/jquery-3.1.0.min.js"></script>
<script src="[[.Prefix]]/-/assets/js/jquery.qrcode.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ $(function () {
loadFileList(location.pathname + location.search)

// update version
$.getJSON("/-/sysinfo", function (res) {
$.getJSON(URL_PREFIX + "/-/sysinfo", function (res) {
vm.version = res.version;
})

Expand Down
31 changes: 5 additions & 26 deletions httpstaticserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ func (s *HTTPStaticServer) getRealPath(r *http.Request) string {
if !strings.HasPrefix(path, "/") {
path = "/" + path
}
path = cleanPath(path) // use cleanPath to prevent safe issues
relPath, err := filepath.Rel(s.Prefix, path)
path = filepath.Clean(path) // prevent .. for safe issues
relativePath, err := filepath.Rel(s.Prefix, path)
if err != nil {
relPath = filepath.Join(s.Prefix, path)
relativePath = path
}
return filepath.ToSlash(relPath)
realPath := filepath.Join(s.Root, relativePath)
return filepath.ToSlash(realPath)
}

func (s *HTTPStaticServer) hIndex(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -152,28 +153,6 @@ func (s *HTTPStaticServer) hIndex(w http.ResponseWriter, r *http.Request) {
}
}

// func (s *HTTPStaticServer) hMkdir(w http.ResponseWriter, req *http.Request) {
// path := filepath.Dir(mux.Vars(req)["path"])
// realPath := s.getRealPath(req)
// auth := s.readAccessConf(realPath)
// if !auth.canDelete(req) {
// http.Error(w, "Mkdir forbidden", http.StatusForbidden)
// return
// }

// name := filepath.Base(mux.Vars(req)["path"])
// if err := checkFilename(name); err != nil {
// http.Error(w, err.Error(), http.StatusForbidden)
// return
// }
// err := os.Mkdir(filepath.Join(s.Root, path, name), 0755)
// if err != nil {
// http.Error(w, err.Error(), 500)
// return
// }
// w.Write([]byte("Success"))
// }

func (s *HTTPStaticServer) hDelete(w http.ResponseWriter, req *http.Request) {
path := mux.Vars(req)["path"]
realPath := s.getRealPath(req)
Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ func main() {
rooter := mainRooter
if gcfg.Prefix != "" {
rooter = mainRooter.PathPrefix(gcfg.Prefix).Subrouter()
mainRooter.Handle(gcfg.Prefix, hdlr)
mainRooter.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, gcfg.Prefix, http.StatusTemporaryRedirect)
})
}

rooter.PathPrefix("/-/assets/").Handler(http.StripPrefix(gcfg.Prefix+"/-/assets/", http.FileServer(Assets)))
Expand Down

0 comments on commit e99a12b

Please sign in to comment.