From 4fe84522878290f91a69d8bc0793eacdb6a8af6d Mon Sep 17 00:00:00 2001 From: Xe Date: Thu, 15 Sep 2022 16:10:05 +0000 Subject: use tulpa.dev/cadey Signed-off-by: Xe --- cmd/uploud/main.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'cmd') diff --git a/cmd/uploud/main.go b/cmd/uploud/main.go index f33208c..ee36893 100644 --- a/cmd/uploud/main.go +++ b/cmd/uploud/main.go @@ -11,13 +11,13 @@ import ( "path/filepath" "runtime" - "github.com/Kagami/go-avif" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/s3" "github.com/chai2010/webp" "github.com/disintegration/imaging" + "tulpa.dev/cadey/avif" ) var ( @@ -124,7 +124,6 @@ func processImage(fname, tempDir string) error { } if err := doAVIF(src, filepath.Join(tempDir, fnameBase+".avif")); err != nil { - log.Fatal(err) return err } @@ -194,9 +193,10 @@ func main() { defer fin.Close() _, err = s3c.PutObject(&s3.PutObjectInput{ - Body: fin, - Bucket: b2Bucket, - Key: aws.String(flag.Arg(1) + "/" + finfo.Name()), + Body: fin, + Bucket: b2Bucket, + Key: aws.String(flag.Arg(1) + "/" + finfo.Name()), + ContentType: aws.String(mimeTypes[filepath.Ext(finfo.Name())]), }) if err != nil { log.Fatal(err) @@ -204,6 +204,13 @@ func main() { } } +var mimeTypes = map[string]string{ + ".avif": "image/avif", + ".webp": "image/webp", + ".jpg": "image/jpeg", + ".png": "image/png", +} + func mkS3Client() *s3.S3 { s3Config := &aws.Config{ Credentials: credentials.NewStaticCredentials(os.Getenv("B2_KEY_ID"), os.Getenv("B2_APPLICATION_KEY"), ""), -- cgit v1.2.3