summaryrefslogtreecommitdiff
path: root/internal/client/output/b2.go
diff refs
from: back
to: back
| flip
diff options
context:
space:
mode:
Diffstat (limited to 'internal/client/output/b2.go')
-rw-r--r--internal/client/output/b2.go17
1 files changed, 13 insertions, 4 deletions
diff --git a/internal/client/output/b2.go b/internal/client/output/b2.go
index 6979e5b..0616368 100644
--- a/internal/client/output/b2.go
+++ b/internal/client/output/b2.go
@@ -2,9 +2,10 @@ package output
import (
"context"
+ "encoding/json"
"fmt"
"io"
- "strconv"
+ "log/slog"
"github.com/Backblaze/blazer/b2"
"github.com/SayaAndy/saya-today-thumbnail-generator/config"
@@ -19,7 +20,7 @@ type B2OutputClient struct {
b2cl *b2.Client
}
-func NewB2OutputClient(cfg *config.OutputConfig) (*B2OutputClient, error) {
+func NewB2OutputClient(cfg *config.OutputConfig) (OutputClient, error) {
if cfg.Storage.Type != "b2" {
return nil, fmt.Errorf("invalid storage type for B2OutputClient")
}
@@ -38,7 +39,7 @@ func NewB2OutputClient(cfg *config.OutputConfig) (*B2OutputClient, error) {
return &B2OutputClient{b2cl: b2cl, bucket: bucket, prefix: b2cfg.Prefix}, nil
}
-func (c *B2OutputClient) GetWriter(path string, inputMetadata *input.MetadataStruct) (io.WriteCloser, error) {
+func (c *B2OutputClient) GetWriter(path string, inputMetadata *input.MetadataStruct, outputContentType string) (io.WriteCloser, error) {
obj := c.bucket.Object(c.prefix + path)
if obj == nil {
return nil, fmt.Errorf("failed to reference object in B2 bucket")
@@ -46,6 +47,7 @@ func (c *B2OutputClient) GetWriter(path string, inputMetadata *input.MetadataStr
attrs := &b2.Attrs{Info: make(map[string]string)}
attrs.Info["sha1-original"] = inputMetadata.Hash
+ attrs.ContentType = outputContentType
return obj.NewWriter(context.Background(), b2.WithAttrsOption(attrs)), nil
}
@@ -70,8 +72,8 @@ func (c *B2OutputClient) ReadMetadata(path string) (*MetadataStruct, error) {
FirstCreated: attrs.UploadTimestamp,
LastModified: attrs.LastModified,
Misc: attrs.Info,
+ Size: attrs.Size,
}
- metadata.Misc["Size"] = strconv.FormatInt(attrs.Size, 10)
switch attrs.Status {
case b2.Uploaded:
@@ -100,5 +102,12 @@ func (c *B2OutputClient) IsMissing(path string) bool {
return true
}
+ attrsJson, _ := json.Marshal(attrs)
+ slog.Debug("got object attrs", slog.String("path", path), slog.String("attrs", string(attrsJson)))
+
+ if attrs.Size == 0 {
+ return true
+ }
+
return attrs.Status == b2.Hider
}