fup/fuphttp: add filename generator to options and application
This commit is contained in:
parent
7b969570a9
commit
5d9b444a56
1 changed files with 10 additions and 0 deletions
|
@ -18,6 +18,7 @@ import (
|
||||||
shuncheckedconversions "github.com/google/safehtml/uncheckedconversions"
|
shuncheckedconversions "github.com/google/safehtml/uncheckedconversions"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"gocloud.dev/blob"
|
"gocloud.dev/blob"
|
||||||
|
"hg.lukegb.com/lukegb/depot/web/fup/fuphttp/fngen"
|
||||||
"hg.lukegb.com/lukegb/depot/web/fup/hashfs"
|
"hg.lukegb.com/lukegb/depot/web/fup/hashfs"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -40,6 +41,9 @@ type Config struct {
|
||||||
// Set one of these, but not both.
|
// Set one of these, but not both.
|
||||||
StorageURL string
|
StorageURL string
|
||||||
StorageBackend *blob.Bucket
|
StorageBackend *blob.Bucket
|
||||||
|
|
||||||
|
// FilenameGenerator returns a new filename based on the provided prefix and extension.
|
||||||
|
FilenameGenerator fngen.FilenameGenerator
|
||||||
}
|
}
|
||||||
|
|
||||||
type Application struct {
|
type Application struct {
|
||||||
|
@ -49,6 +53,8 @@ type Application struct {
|
||||||
|
|
||||||
redirectToBlobstore bool
|
redirectToBlobstore bool
|
||||||
redirectExpiry time.Duration
|
redirectExpiry time.Duration
|
||||||
|
|
||||||
|
filenameGenerator fngen.FilenameGenerator
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Application) Handler() http.Handler {
|
func (a *Application) Handler() http.Handler {
|
||||||
|
@ -109,10 +115,14 @@ func New(ctx context.Context, cfg *Config) (*Application, error) {
|
||||||
a := &Application{
|
a := &Application{
|
||||||
redirectToBlobstore: cfg.RedirectToBlobstore,
|
redirectToBlobstore: cfg.RedirectToBlobstore,
|
||||||
redirectExpiry: cfg.RedirectExpiry,
|
redirectExpiry: cfg.RedirectExpiry,
|
||||||
|
filenameGenerator: cfg.FilenameGenerator,
|
||||||
}
|
}
|
||||||
if a.redirectExpiry == 0 {
|
if a.redirectExpiry == 0 {
|
||||||
a.redirectExpiry = defaultRedirectExpiry
|
a.redirectExpiry = defaultRedirectExpiry
|
||||||
}
|
}
|
||||||
|
if a.filenameGenerator == nil {
|
||||||
|
a.filenameGenerator = fngen.PetnameGenerator
|
||||||
|
}
|
||||||
|
|
||||||
bkt := cfg.StorageBackend
|
bkt := cfg.StorageBackend
|
||||||
if bkt == nil {
|
if bkt == nil {
|
||||||
|
|
Loading…
Reference in a new issue