π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Fetch remote collection & print ids
Neeraj Guptab4f0994a349b
diff --git a/internal/api/client.go b/internal/api/client.goindex 36162e8ea1..7cd28c4302 100644--- a/internal/api/client.go+++ b/internal/api/client.go@@ -19,7 +19,6 @@ var tokenMap map[string]string = make(map[string]string)type Client struct {restClient *resty.Client- tokenMap map[string]string}type Params struct {diff --git a/pkg/remote_sync.go b/pkg/remote_sync.goindex add3a69227..843cc7bc22 100644--- a/pkg/remote_sync.go+++ b/pkg/remote_sync.go@@ -2,30 +2,60 @@ package pkgimport ("cli-go/pkg/model"+ "cli-go/utils"+ "context"+ "encoding/base64""fmt"bolt "go.etcd.io/bbolt""log")-func (c *ClICtrl) SyncAccount(account model.AccountInfo) error {- return createDataBuckets(c.DB, account)+func (c *ClICtrl) SyncAccount(account model.Account) error {+ log.SetPrefix(fmt.Sprintf("[%s] ", account.Email))+ cliSecret := GetOrCreateClISecret()+ err := createDataBuckets(c.DB, account)+ if err != nil {+ return err+ }+ token := account.Token.MustDecrypt(cliSecret)+ urlEncodedToken := base64.URLEncoding.EncodeToString(utils.Base64DecodeString(token))+ c.Client.AddToken(account.AccountKey(), urlEncodedToken)+ ctx := c.GetRequestContext(context.Background(), account)+ return c.syncRemoteCollections(ctx, account)+}++func (c *ClICtrl) GetRequestContext(ctx context.Context, account model.Account) context.Context {+ ctx = context.WithValue(ctx, "app", string(account.App))+ ctx = context.WithValue(ctx, "account_id", account.AccountKey())+ return ctx}var dataCategories = []string{"remote-collections", "local-collections", "remote-files", "local-files", "remote-collection-removed", "remote-files-removed"}-func createDataBuckets(db *bolt.DB, account model.AccountInfo) error {+func createDataBuckets(db *bolt.DB, account model.Account) error {return db.Update(func(tx *bolt.Tx) error {dataBucket, err := tx.CreateBucketIfNotExists([]byte(account.DataBucket()))if err != nil {return fmt.Errorf("create bucket: %s", err)}for _, category := range dataCategories {- exists, err := dataBucket.CreateBucketIfNotExists([]byte(fmt.Sprintf(category)))+ _, err := dataBucket.CreateBucketIfNotExists([]byte(fmt.Sprintf(category)))if err != nil {return err}- log.Println("SubBucket for category", category, "with parent", account.DataBucket(), "exists:", exists)}return nil})}++func (c *ClICtrl) syncRemoteCollections(ctx context.Context, info model.Account) error {+ collections, err := c.Client.GetCollections(ctx, 0)+ if err != nil {+ log.Printf("failed to get collections: %s\n", err)+ return err+ }+ for _, collection := range collections {+ fmt.Printf("Collection %d\n", collection.ID)+ }+ return nil+}diff --git a/pkg/sync.go b/pkg/sync.goindex 1928bab84d..3476d2e8e0 100644--- a/pkg/sync.go+++ b/pkg/sync.go@@ -1,15 +1,24 @@package pkg-import "context"+import (+ "context"+ "fmt"+)func (c *ClICtrl) StartSync() error {accounts, err := c.GetAccounts(context.Background())if err != nil {return err}+ if len(accounts) == 0 {+ fmt.Printf("No accounts to sync\n")+ return nil+ }for _, account := range accounts {+ fmt.Printf("Syncing account %s\n", account.Email)err = c.SyncAccount(account)if err != nil {+ fmt.Printf("Error syncing account %s: %s\n", account.Email, err)return err}}