π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Refactor
Neeraj Gupta840e475848fa
diff --git a/pkg/bolt_store.go b/pkg/bolt_store.gonew file mode 100644index 0000000000..b13c3e28b9--- /dev/null+++ b/pkg/bolt_store.go@@ -0,0 +1,20 @@+package pkg++import (+ "cli-go/pkg/model"+ "cli-go/utils/encoding"+ "context"+ "fmt"+)++func boltAEKey(entry *model.AlbumFileEntry) []byte {+ return []byte(fmt.Sprintf("%d:%d", entry.AlbumID, entry.FileID))+}++func (c *ClICtrl) DeleteAlbumEntry(ctx context.Context, entry *model.AlbumFileEntry) error {+ return c.DeleteValue(ctx, model.RemoteAlbumEntries, boltAEKey(entry))+}++func (c *ClICtrl) UpsertAlbumEntry(ctx context.Context, entry *model.AlbumFileEntry) error {+ return c.PutValue(ctx, model.RemoteAlbumEntries, boltAEKey(entry), encoding.MustMarshalJSON(entry))+}diff --git a/pkg/remote_sync.go b/pkg/remote_sync.goindex 6b3fb54c78..44e7a31ccf 100644--- a/pkg/remote_sync.go+++ b/pkg/remote_sync.go@@ -93,8 +93,7 @@ func (c *ClICtrl) fetchRemoteFiles(ctx context.Context) error {continue}albumEntry := model.AlbumFileEntry{AlbumID: album.ID, FileID: file.ID, IsDeleted: file.IsDeleted, SyncedLocally: false}- albumEntryJson := encoding.MustMarshalJSON(albumEntry)- putErr := c.PutValue(ctx, model.RemoteAlbumEntries, []byte(fmt.Sprintf("%d:%d", album.ID, file.ID)), albumEntryJson)+ putErr := c.UpsertAlbumEntry(ctx, &albumEntry)if putErr != nil {return putErr}diff --git a/pkg/remote_to_disk_file.go b/pkg/remote_to_disk_file.goindex dec7e153fa..de2937412e 100644--- a/pkg/remote_to_disk_file.go+++ b/pkg/remote_to_disk_file.go@@ -44,14 +44,13 @@ func (c *ClICtrl) syncFiles(ctx context.Context) error {}if albumInfo.IsDeleted {- entry.IsDeleted = true- putErr := c.DeleteValue(ctx, model.RemoteAlbumEntries, []byte(fmt.Sprintf("%d:%d", entry.AlbumID, entry.FileID)))+ putErr := c.DeleteAlbumEntry(ctx, entry)if putErr != nil {return putErr}continue}- fmt.Println("entry", i, albumInfo.AlbumName, entry.FileID, entry.SyncedLocally)+if albumDiskInfo == nil || albumDiskInfo.AlbumMeta.ID != albumInfo.ID {albumDiskInfo, err = readFilesMetadata(exportRoot, albumInfo)if err != nil {@@ -69,6 +68,7 @@ func (c *ClICtrl) syncFiles(ctx context.Context) error {return err}if existingEntry.GetFileType() != model.LivePhoto && albumDiskInfo.AlbumMeta.ID == 1580559962519759 {+ fmt.Println("entry", i, albumInfo.AlbumName, entry.FileID, entry.SyncedLocally)err = c.downloadEntry(ctx, albumDiskInfo, *existingEntry, entry)if err != nil {return err@@ -84,7 +84,8 @@ func (c *ClICtrl) syncFiles(ctx context.Context) error {func (c *ClICtrl) downloadEntry(ctx context.Context,diskInfo *albumDiskInfo,file model.RemoteFile,- albumEntry *model.AlbumFileEntry) error {+ albumEntry *model.AlbumFileEntry,+) error {if !diskInfo.AlbumMeta.IsDeleted && albumEntry.IsDeleted {albumEntry.IsDeleted = truediskFileMeta := diskInfo.GetDiskFileMetadata(file)@@ -94,10 +95,11 @@ func (c *ClICtrl) downloadEntry(ctx context.Context,return removeErr}}- putErr := c.DeleteValue(ctx, model.RemoteAlbumEntries, []byte(fmt.Sprintf("%d:%d", albumEntry.AlbumID, albumEntry.FileID)))- if putErr != nil {- return putErr+ delErr := c.DeleteAlbumEntry(ctx, albumEntry)+ if delErr != nil {+ return delErr}+ return nil}if !diskInfo.IsFilePresent(file) {decrypt, err := c.downloadAndDecrypt(ctx, file, c.KeyHolder.DeviceKey)@@ -134,6 +136,11 @@ func (c *ClICtrl) downloadEntry(ctx context.Context,if err != nil {return err}+ albumEntry.SyncedLocally = true+ putErr := c.UpsertAlbumEntry(ctx, albumEntry)+ if putErr != nil {+ return putErr+ }}return nil}