fup/fuphttp: add filename generator to options and application

This commit is contained in:
Luke Granger-Brown 2021-03-21 17:07:47 +00:00
parent 7b969570a9
commit 5d9b444a56

View file

@ -18,6 +18,7 @@ import (
shuncheckedconversions "github.com/google/safehtml/uncheckedconversions"
"github.com/gorilla/mux"
"gocloud.dev/blob"
"hg.lukegb.com/lukegb/depot/web/fup/fuphttp/fngen"
"hg.lukegb.com/lukegb/depot/web/fup/hashfs"
)
@ -40,6 +41,9 @@ type Config struct {
// Set one of these, but not both.
StorageURL string
StorageBackend *blob.Bucket
// FilenameGenerator returns a new filename based on the provided prefix and extension.
FilenameGenerator fngen.FilenameGenerator
}
type Application struct {
@ -49,6 +53,8 @@ type Application struct {
redirectToBlobstore bool
redirectExpiry time.Duration
filenameGenerator fngen.FilenameGenerator
}
func (a *Application) Handler() http.Handler {
@ -109,10 +115,14 @@ func New(ctx context.Context, cfg *Config) (*Application, error) {
a := &Application{
redirectToBlobstore: cfg.RedirectToBlobstore,
redirectExpiry: cfg.RedirectExpiry,
filenameGenerator: cfg.FilenameGenerator,
}
if a.redirectExpiry == 0 {
a.redirectExpiry = defaultRedirectExpiry
}
if a.filenameGenerator == nil {
a.filenameGenerator = fngen.PetnameGenerator
}
bkt := cfg.StorageBackend
if bkt == nil {