diff --git a/pkg/collections.go b/pkg/collections.go index d78d8a2daeab85485486e430976d1687b5b4b631..85d8582595e090c262aa56444761336f1f10b050 100644 --- a/pkg/collections.go +++ b/pkg/collections.go @@ -3,6 +3,7 @@ package pkg import ( debuglog "cli-go/pkg/log" "cli-go/pkg/model" + "cli-go/utils/encoding" "context" "fmt" "strconv" @@ -36,6 +37,11 @@ func (c *ClICtrl) syncRemoteCollections(ctx context.Context, info model.Account) if album.LastUpdatedAt > maxUpdated { maxUpdated = album.LastUpdatedAt } + albumJson := encoding.MustMarshalJSON(album) + err := c.PutValue(ctx, model.RemoteAlbums, []byte(strconv.FormatInt(album.ID, 10)), albumJson) + if err != nil { + return err + } debuglog.PrintAlbum(album) } if maxUpdated > lastSyncTime { diff --git a/pkg/store.go b/pkg/store.go index c75bbde51caeb81ebd8a923656b6736f329e50f3..93456c3b3144dee81b7f13a9691c2cba61d6b8e4 100644 --- a/pkg/store.go +++ b/pkg/store.go @@ -40,6 +40,15 @@ func (c *ClICtrl) PutConfigValue(ctx context.Context, key string, value []byte) return kvBucket.Put([]byte(key), value) }) } +func (c *ClICtrl) PutValue(ctx context.Context, store model.PhotosStore, key []byte, value []byte) error { + return c.DB.Update(func(tx *bolt.Tx) error { + kvBucket, err := getAccountStore(ctx, tx, store) + if err != nil { + return err + } + return kvBucket.Put(key, value) + }) +} func getAccountStore(ctx context.Context, tx *bolt.Tx, storeType model.PhotosStore) (*bolt.Bucket, error) { accountId := ctx.Value("account_id").(string) diff --git a/utils/encoding/encoding.go b/utils/encoding/encoding.go index b5cec0b5fbac7ae51499c59f2afc5278ef9fdebd..a88eceff7c2c6620b8f834a7caa9d93f4ecae373 100644 --- a/utils/encoding/encoding.go +++ b/utils/encoding/encoding.go @@ -2,6 +2,7 @@ package encoding import ( "encoding/base64" + "encoding/json" ) func DecodeBase64(s string) []byte { @@ -15,3 +16,11 @@ func DecodeBase64(s string) []byte { func EncodeBase64(b []byte) string { return base64.StdEncoding.EncodeToString(b) } + +func MustMarshalJSON(v interface{}) []byte { + b, err := json.Marshal(v) + if err != nil { + panic(err) + } + return b +}