1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-07-15 01:34:21 +02:00

feat(blob): content disposition

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker
2024-01-07 15:21:35 -03:00
parent be92144915
commit a342f027d7
6 changed files with 75 additions and 34 deletions

View File

@ -29,6 +29,9 @@ func (Pipe) Default(ctx *context.Context) error {
if blob.Folder == "" {
blob.Folder = "{{ .ProjectName }}/{{ .Tag }}"
}
if blob.ContentDisposition == "" {
blob.ContentDisposition = "attachment;filename={{.Filename}}"
}
if blob.OldDisableSSL {
deprecate.Notice(ctx, "blobs.disableSSL")
blob.DisableSSL = true

View File

@ -92,6 +92,7 @@ func TestMinioUpload(t *testing.T) {
Endpoint: "http://" + listen,
IDs: []string{"foo", "bar"},
CacheControl: []string{"max-age=9999"},
ContentDisposition: "inline",
ExtraFiles: []config.ExtraFile{
{
Glob: "./testdata/*.golden",

View File

@ -72,11 +72,19 @@ func TestDefaults(t *testing.T) {
Bucket: "foo",
Provider: "azblob",
IDs: []string{"foo", "bar"},
ContentDisposition: "inline",
},
{
Bucket: "foobar",
Provider: "gcs",
},
{
Bucket: "deprecated",
Provider: "s3",
Folder: "static",
OldDisableSSL: true,
OldKMSKey: "fake",
},
},
})
require.NoError(t, Pipe{}.Default(ctx))
@ -86,11 +94,23 @@ func TestDefaults(t *testing.T) {
Provider: "azblob",
Folder: "{{ .ProjectName }}/{{ .Tag }}",
IDs: []string{"foo", "bar"},
ContentDisposition: "inline",
},
{
Bucket: "foobar",
Provider: "gcs",
Folder: "{{ .ProjectName }}/{{ .Tag }}",
ContentDisposition: "attachment;filename={{.Filename}}",
},
{
Bucket: "deprecated",
Provider: "s3",
Folder: "static",
OldDisableSSL: true,
DisableSSL: true,
OldKMSKey: "fake",
KMSKey: "fake",
ContentDisposition: "attachment;filename={{.Filename}}",
},
}, ctx.Config.Blobs)
}

View File

@ -112,6 +112,7 @@ func doUpload(ctx *context.Context, conf config.Blob) error {
up := &productionUploader{
cacheControl: conf.CacheControl,
contentDisposition: conf.ContentDisposition,
}
if conf.Provider == "s3" && conf.ACL != "" {
up.beforeWrite = func(asFunc func(interface{}) bool) error {
@ -232,6 +233,7 @@ type productionUploader struct {
bucket *blob.Bucket
beforeWrite func(asFunc func(interface{}) bool) error
cacheControl []string
contentDisposition string
}
func (u *productionUploader) Close() error {
@ -255,8 +257,15 @@ func (u *productionUploader) Open(ctx *context.Context, bucket string) error {
func (u *productionUploader) Upload(ctx *context.Context, filepath string, data []byte) error {
log.WithField("path", filepath).Info("uploading")
disp, err := tmpl.New(ctx).WithExtraFields(tmpl.Fields{
"Filename": path.Base(filepath),
}).Apply(u.contentDisposition)
if err != nil {
return err
}
opts := &blob.WriterOptions{
ContentDisposition: "attachment; filename=" + path.Base(filepath),
ContentDisposition: disp,
BeforeWrite: u.beforeWrite,
CacheControl: strings.Join(u.cacheControl, ", "),
}

View File

@ -1106,6 +1106,7 @@ type Blob struct {
S3ForcePathStyle *bool `yaml:"s3_force_path_style,omitempty" json:"s3_force_path_style,omitempty"`
ACL string `yaml:"acl,omitempty" json:"acl,omitempty"`
CacheControl []string `yaml:"cache_control,omitempty" json:"cache_control,omitempty"`
ContentDisposition string `yaml:"content_disposition,omitempty" json:"content_disposition,omitempty"`
// Deprecated: use disable_ssl instead
OldDisableSSL bool `yaml:"disableSSL,omitempty" json:"disableSSL,omitempty" jsonschema:"deprecated=true,description=use disable_ssl instead"` // nolint:tagliatelle

View File

@ -105,6 +105,13 @@ blobs:
- max-age=9999
- public
# Allows to set the content disposition of the file.
#
# Default: attachment;filename={{.Filename}}
# Templates: allowed
# Since: v1.24
content_disposition: "inline"
- provider: gs
bucket: goreleaser-bucket
folder: "foo/bar/{{.Version}}"