π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Refactor
Neeraj Guptaf91a424e44a0
diff --git a/pkg/collections.go b/pkg/collections.goindex 85d8582595..246f9eb37c 100644--- a/pkg/collections.go+++ b/pkg/collections.go@@ -9,17 +9,10 @@ import ("strconv")-func (c *ClICtrl) syncRemoteCollections(ctx context.Context, info model.Account) error {- valueBytes, err := c.GetConfigValue(ctx, model.CollectionsSyncKey)- if err != nil {- return fmt.Errorf("failed to get last sync time: %s", err)- }- var lastSyncTime int64- if valueBytes != nil {- lastSyncTime, err = strconv.ParseInt(string(valueBytes), 10, 64)- if err != nil {- return err- }+func (c *ClICtrl) fetchRemoteCollections(ctx context.Context, info model.Account) error {+ lastSyncTime, err2 := c.GetInt64ConfigValue(ctx, model.CollectionsSyncKey)+ if err2 != nil {+ return err2}collections, err := c.Client.GetCollections(ctx, lastSyncTime)if err != nil {@@ -30,17 +23,17 @@ func (c *ClICtrl) syncRemoteCollections(ctx context.Context, info model.Account)if lastSyncTime == 0 && collection.IsDeleted {continue}- album, err2 := c.mapCollectionToAlbum(ctx, collection)- if err2 != nil {- return err2+ album, mapErr := c.mapCollectionToAlbum(ctx, collection)+ if mapErr != nil {+ return mapErr}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+ putErr := c.PutValue(ctx, model.RemoteAlbums, []byte(strconv.FormatInt(album.ID, 10)), albumJson)+ if putErr != nil {+ return putErr}debuglog.PrintAlbum(album)}diff --git a/pkg/remote_sync.go b/pkg/remote_sync.goindex b4747d05b1..45e1598d20 100644--- a/pkg/remote_sync.go+++ b/pkg/remote_sync.go@@ -21,7 +21,7 @@ func (c *ClICtrl) SyncAccount(account model.Account) error {return err}c.Client.AddToken(account.AccountKey(), base64.URLEncoding.EncodeToString(secretInfo.Token))- return c.syncRemoteCollections(ctx, account)+ return c.fetchRemoteCollections(ctx, account)}func (c *ClICtrl) buildRequestContext(ctx context.Context, account model.Account) context.Context {diff --git a/pkg/store.go b/pkg/store.goindex 93456c3b31..56adf5a87c 100644--- a/pkg/store.go+++ b/pkg/store.go@@ -5,6 +5,7 @@ import ("context""fmt""log"+ "strconv""time"bolt "go.etcd.io/bbolt"@@ -31,6 +32,21 @@ func (c *ClICtrl) GetConfigValue(ctx context.Context, key string) ([]byte, errorreturn value, err}+func (c *ClICtrl) GetInt64ConfigValue(ctx context.Context, key string) (int64, error) {+ value, err := c.GetConfigValue(ctx, key)+ if err != nil {+ return 0, err+ }+ var result int64+ if value != nil {+ result, err = strconv.ParseInt(string(value), 10, 64)+ if err != nil {+ return 0, err+ }+ }+ return result, nil+}+func (c *ClICtrl) PutConfigValue(ctx context.Context, key string, value []byte) error {return c.DB.Update(func(tx *bolt.Tx) error {kvBucket, err := getAccountStore(ctx, tx, model.KVConfig)