serve http, serve webdav: Added a --template flag for user defined markup

This commit is contained in:
calistri 2020-04-30 14:24:11 -04:00 committed by Nick Craig-Wood
parent dcf945ed58
commit 4362ca7bb9
10 changed files with 241 additions and 25 deletions

View file

@ -52,6 +52,27 @@ inserts leading and trailing "/" on --baseurl, so --baseurl "rclone",
--baseurl "/rclone" and --baseurl "/rclone/" are all treated
identically.
--template allows a user to specify a custom markup template for http
and webdav serve functions. The server exports the following markup
to be used within the template to server pages:
.Name The full path of a file/directory.
.Title "Directory listing of .Name".
.Sort The current sort used. This is changble via ?sort= parameter
Sort Options: namedirfist,name,size,time (defailt namedirfirst)
.Order The current ordering used. This is changable via ?order= paramter
Order Options: asc,desc (default asc)
.Query Currently unused.
.Breacrumb Allows for creating a relative navigation
-- .Link The relative to the root link of the Text.
-- .Text The Name of the directory.
.Entries Information about a specific file/directory.
-- .URL The 'url' of an entry.
-- .Leaf Currently same as 'URL' but intended to be 'just' the name.
-- .IsDir Boolean for if an entry is a directory or not.
-- .Size Size in Bytes of the entry.
-- .ModTime The UTC timestamp of an entry.
#### Authentication
By default this will serve files without needing a login.
@ -101,6 +122,7 @@ type Options struct {
BasicUser string // single username for basic auth if not using Htpasswd
BasicPass string // password for BasicUser
Auth AuthFn `json:"-"` // custom Auth (not set by command line flags)
Template string // User specified template
}
// AuthFn if used will be used to authenticate user, pass. If an error
@ -281,7 +303,7 @@ func NewServer(handler http.Handler, opt *Options) *Server {
s.httpServer.TLSConfig.ClientAuth = tls.RequireAndVerifyClientCert
}
htmlTemplate, templateErr := data.GetTemplate()
htmlTemplate, templateErr := data.GetTemplate(s.Opt.Template)
if templateErr != nil {
log.Fatalf(templateErr.Error())
}