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"`
|
Excluded Globs `yaml:"excluded"`
|
||||||
ViewURLBase string `yaml:"viewurlbase"`
|
ViewURLBase string `yaml:"viewurlbase"`
|
||||||
ViewPathBase string `yaml:"viewpathbase"`
|
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
|
// 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
|
// SetupRoutes adds API routes
|
||||||
func (mu *MegaUploader) SetupRoutes() {
|
func (mu *MegaUploader) SetupRoutes() {
|
||||||
http.HandleFunc("/", requireUserMiddleware(mu.home))
|
prefix := strings.TrimRight(mu.Conf.Global.RoutePrefix, "/")
|
||||||
http.HandleFunc("/upload/", requireUserMiddleware(mu.uploadUI))
|
|
||||||
|
http.HandleFunc(prefix+"/", mu.confAcquire(requireUserMiddleware(mu.home)))
|
||||||
|
http.HandleFunc(prefix+"/upload/", mu.confAcquire(requireUserMiddleware(mu.uploadUI)))
|
||||||
static := rice.MustFindBox("res/static")
|
static := rice.MustFindBox("res/static")
|
||||||
http.HandleFunc("/static/", requireUserMiddleware(
|
http.HandleFunc(prefix+"/static/", requireUserMiddleware(
|
||||||
http.StripPrefix("/static/", http.FileServer(static.HTTPBox())).ServeHTTP,
|
http.StripPrefix(prefix+"/static/", http.FileServer(static.HTTPBox())).ServeHTTP,
|
||||||
))
|
))
|
||||||
http.HandleFunc("/api/share", requireUserMiddleware(mu.listShares))
|
http.HandleFunc(prefix+"/api/share", mu.confAcquire(requireUserMiddleware(mu.listShares)))
|
||||||
http.HandleFunc("/api/share/", requireUserMiddleware(mu.getShare))
|
http.HandleFunc(prefix+"/api/share/", mu.confAcquire(requireUserMiddleware(mu.getShare)))
|
||||||
http.HandleFunc("/api/upload/", requireUserMiddleware(mu.upload))
|
http.HandleFunc(prefix+"/api/upload/", mu.confAcquire(requireUserMiddleware(mu.upload)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func getUser(r *http.Request) (string, error) {
|
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)
|
shares := mu.Conf.GetAuthShares(user)
|
||||||
w.Header().Set("Content-Type", "text/html")
|
w.Header().Set("Content-Type", "text/html")
|
||||||
tmpl.Execute(w, map[string]interface{}{
|
tmpl.Execute(w, map[string]interface{}{
|
||||||
|
"Prefix": mu.Conf.Global.RoutePrefix,
|
||||||
"Shares": shares,
|
"Shares": shares,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -73,6 +74,7 @@ func (mu *MegaUploader) uploadUI(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", "text/html")
|
w.Header().Set("Content-Type", "text/html")
|
||||||
tmpl.Execute(w, map[string]interface{}{
|
tmpl.Execute(w, map[string]interface{}{
|
||||||
|
"Prefix": mu.Conf.Global.RoutePrefix,
|
||||||
"Share": share,
|
"Share": share,
|
||||||
"ViewURL": viewurl.String(),
|
"ViewURL": viewurl.String(),
|
||||||
})
|
})
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<ul>
|
<ul>
|
||||||
{{range .Shares}}
|
{{range .Shares}}
|
||||||
<li><span class="share-link">
|
<li><span class="share-link">
|
||||||
<a href="/upload/{{.Name}}">{{.Name}}</a>
|
<a href="{{$.Prefix}}/upload/{{.Name}}">{{.Name}}</a>
|
||||||
</span>
|
</span>
|
||||||
<span class="share-description">{{.Description}}</span>
|
<span class="share-description">{{.Description}}</span>
|
||||||
{{ if ne .SizeLimit.Bytes 0 }}
|
{{ if ne .SizeLimit.Bytes 0 }}
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<pre id="responses"></pre>
|
<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>
|
<noscript>
|
||||||
<input type="file" name="file" />
|
<input type="file" name="file" />
|
||||||
</noscript>
|
</noscript>
|
||||||
|
@ -33,7 +33,7 @@
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "scripts"}}
|
{{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">
|
<script type="text/javascript">
|
||||||
Dropzone.options.uploadForm = {
|
Dropzone.options.uploadForm = {
|
||||||
init: function() {
|
init: function() {
|
||||||
|
@ -45,7 +45,7 @@ Dropzone.options.uploadForm = {
|
||||||
</script>
|
</script>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{define "styles"}}
|
{{define "styles"}}
|
||||||
<link href="/static/dropzone/dropzone.min.css" rel="stylesheet" />
|
<link href="{{.Prefix}}/static/dropzone/dropzone.min.css" rel="stylesheet" />
|
||||||
<style>
|
<style>
|
||||||
.share-description { font-style: italic; }
|
.share-description { font-style: italic; }
|
||||||
</style>
|
</style>
|
||||||
|
|
Loading…
Reference in a new issue