can be hosted under a prefix
This commit is contained in:
parent
5edd16b326
commit
3bb3c9856e
5 changed files with 16 additions and 11 deletions
1
conf.go
1
conf.go
|
@ -125,6 +125,7 @@ type Global struct {
|
|||
Excluded Globs `yaml:"excluded"`
|
||||
ViewURLBase string `yaml:"viewurlbase"`
|
||||
ViewPathBase string `yaml:"viewpathbase"`
|
||||
RoutePrefix string `yaml:"routeprefix"` // if you want to proxy megauploader as a sub-location, that's for you
|
||||
}
|
||||
|
||||
// UserHome specifies rules for generating home shares on the fly
|
||||
|
|
16
http.go
16
http.go
|
@ -47,15 +47,17 @@ func (mu *MegaUploader) confAcquire(inner func(w http.ResponseWriter, r *http.Re
|
|||
|
||||
// SetupRoutes adds API routes
|
||||
func (mu *MegaUploader) SetupRoutes() {
|
||||
http.HandleFunc("/", requireUserMiddleware(mu.home))
|
||||
http.HandleFunc("/upload/", requireUserMiddleware(mu.uploadUI))
|
||||
prefix := strings.TrimRight(mu.Conf.Global.RoutePrefix, "/")
|
||||
|
||||
http.HandleFunc(prefix+"/", mu.confAcquire(requireUserMiddleware(mu.home)))
|
||||
http.HandleFunc(prefix+"/upload/", mu.confAcquire(requireUserMiddleware(mu.uploadUI)))
|
||||
static := rice.MustFindBox("res/static")
|
||||
http.HandleFunc("/static/", requireUserMiddleware(
|
||||
http.StripPrefix("/static/", http.FileServer(static.HTTPBox())).ServeHTTP,
|
||||
http.HandleFunc(prefix+"/static/", requireUserMiddleware(
|
||||
http.StripPrefix(prefix+"/static/", http.FileServer(static.HTTPBox())).ServeHTTP,
|
||||
))
|
||||
http.HandleFunc("/api/share", requireUserMiddleware(mu.listShares))
|
||||
http.HandleFunc("/api/share/", requireUserMiddleware(mu.getShare))
|
||||
http.HandleFunc("/api/upload/", requireUserMiddleware(mu.upload))
|
||||
http.HandleFunc(prefix+"/api/share", mu.confAcquire(requireUserMiddleware(mu.listShares)))
|
||||
http.HandleFunc(prefix+"/api/share/", mu.confAcquire(requireUserMiddleware(mu.getShare)))
|
||||
http.HandleFunc(prefix+"/api/upload/", mu.confAcquire(requireUserMiddleware(mu.upload)))
|
||||
}
|
||||
|
||||
func getUser(r *http.Request) (string, error) {
|
||||
|
|
|
@ -48,6 +48,7 @@ func (mu *MegaUploader) home(w http.ResponseWriter, r *http.Request) {
|
|||
shares := mu.Conf.GetAuthShares(user)
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
tmpl.Execute(w, map[string]interface{}{
|
||||
"Prefix": mu.Conf.Global.RoutePrefix,
|
||||
"Shares": shares,
|
||||
})
|
||||
}
|
||||
|
@ -73,6 +74,7 @@ func (mu *MegaUploader) uploadUI(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
tmpl.Execute(w, map[string]interface{}{
|
||||
"Prefix": mu.Conf.Global.RoutePrefix,
|
||||
"Share": share,
|
||||
"ViewURL": viewurl.String(),
|
||||
})
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<ul>
|
||||
{{range .Shares}}
|
||||
<li><span class="share-link">
|
||||
<a href="/upload/{{.Name}}">{{.Name}}</a>
|
||||
<a href="{{$.Prefix}}/upload/{{.Name}}">{{.Name}}</a>
|
||||
</span>
|
||||
<span class="share-description">{{.Description}}</span>
|
||||
{{ if ne .SizeLimit.Bytes 0 }}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
</ul>
|
||||
</div>
|
||||
<pre id="responses"></pre>
|
||||
<form id="uploadForm" class="dropzone" method="POST" action="/api/upload/{{.Share.Name}}">
|
||||
<form id="uploadForm" class="dropzone" method="POST" action="{{.Prefix}}/api/upload/{{.Share.Name}}">
|
||||
<noscript>
|
||||
<input type="file" name="file" />
|
||||
</noscript>
|
||||
|
@ -33,7 +33,7 @@
|
|||
{{end}}
|
||||
|
||||
{{define "scripts"}}
|
||||
<script type="text/javascript" src="/static/dropzone/dropzone.min.js"></script>
|
||||
<script type="text/javascript" src="{{.Prefix}}/static/dropzone/dropzone.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
Dropzone.options.uploadForm = {
|
||||
init: function() {
|
||||
|
@ -45,7 +45,7 @@ Dropzone.options.uploadForm = {
|
|||
</script>
|
||||
{{end}}
|
||||
{{define "styles"}}
|
||||
<link href="/static/dropzone/dropzone.min.css" rel="stylesheet" />
|
||||
<link href="{{.Prefix}}/static/dropzone/dropzone.min.css" rel="stylesheet" />
|
||||
<style>
|
||||
.share-description { font-style: italic; }
|
||||
</style>
|
||||
|
|
Loading…
Reference in a new issue