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"
|
||||
"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 {
|
||||
|
|
Loading…
Reference in a new issue