From 12ff1ee552cb4b906e747d263c3c5de796e4719e Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Mon, 25 Sep 2023 14:03:58 +0530 Subject: [PATCH] Store metadata as map for albums --- main.go | 2 +- pkg/collections.go | 6 ++++++ pkg/log/debug_print.go | 6 +++--- pkg/mappers.go | 20 +++++++++++++------- pkg/model/album.go | 20 ++++++++++---------- pkg/model/photo_file.go | 2 +- 6 files changed, 34 insertions(+), 22 deletions(-) diff --git a/main.go b/main.go index c5831e766..be12a1ef5 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,7 @@ func main() { ctrl := pkg.ClICtrl{ Client: api.NewClient(api.Params{ Debug: false, - Host: "http://localhost:8080", + //Host: "http://localhost:8080", }), DB: db, CliKey: secrets.GetOrCreateClISecret(), diff --git a/pkg/collections.go b/pkg/collections.go index 4272ed910..d8cca3e4a 100644 --- a/pkg/collections.go +++ b/pkg/collections.go @@ -9,6 +9,7 @@ import ( "fmt" "log" "strconv" + "time" ) func (c *ClICtrl) fetchRemoteCollections(ctx context.Context) error { @@ -64,9 +65,14 @@ func (c *ClICtrl) fetchRemoteFiles(ctx context.Context) error { } isFirstSync := lastSyncTime == 0 for { + if lastSyncTime == album.LastUpdatedAt { break } + if !isFirstSync { + t := time.UnixMicro(lastSyncTime) + log.Printf("Fetching files for album %s from %v\n", album.AlbumName, t) + } files, hasMore, err := c.Client.GetFiles(ctx, album.ID, lastSyncTime) if err != nil { return err diff --git a/pkg/log/debug_print.go b/pkg/log/debug_print.go index 35ac29c38..d161e5c52 100644 --- a/pkg/log/debug_print.go +++ b/pkg/log/debug_print.go @@ -16,13 +16,13 @@ func PrintAlbum(a *model.Album) { } fmt.Printf(" Name: %s\n", a.AlbumName) if a.PrivateMeta != nil { - fmt.Printf("PrivateMeta: %s\n", *a.PrivateMeta) + fmt.Printf("PrivateMeta: %s\n", a.PrivateMeta) } if a.PublicMeta != nil { - fmt.Printf("PublicMeta: %s\n", *a.PublicMeta) + fmt.Printf("PublicMeta: %s\n", a.PublicMeta) } if a.SharedMeta != nil { - fmt.Printf("SharedMeta: %s\n", *a.SharedMeta) + fmt.Printf("SharedMeta: %s\n", a.SharedMeta) } fmt.Printf("LastUpdatedAt: %d", a.LastUpdatedAt) fmt.Printf("\n=======") diff --git a/pkg/mappers.go b/pkg/mappers.go index cd9b223b4..49c839964 100644 --- a/pkg/mappers.go +++ b/pkg/mappers.go @@ -41,24 +41,30 @@ func (c *ClICtrl) mapCollectionToAlbum(ctx context.Context, collection api.Colle if err != nil { return nil, err } - var val = string(encodedJsonBytes) - album.PrivateMeta = &val + err = json.Unmarshal(encodedJsonBytes, &album.PrivateMeta) + if err != nil { + return nil, err + } } if collection.PublicMagicMetadata != nil { _, encodedJsonBytes, err := enteCrypto.DecryptChaChaBase64(collection.PublicMagicMetadata.Data, collectionKey, collection.PublicMagicMetadata.Header) if err != nil { return nil, err } - var val = string(encodedJsonBytes) - album.PublicMeta = &val + err = json.Unmarshal(encodedJsonBytes, &album.PublicMeta) + if err != nil { + return nil, err + } } if album.IsShared && collection.SharedMagicMetadata != nil { _, encodedJsonBytes, err := enteCrypto.DecryptChaChaBase64(collection.SharedMagicMetadata.Data, collectionKey, collection.SharedMagicMetadata.Header) if err != nil { return nil, err } - var val = string(encodedJsonBytes) - album.SharedMeta = &val + err = json.Unmarshal(encodedJsonBytes, &album.SharedMeta) + if err != nil { + return nil, err + } } return &album, nil } @@ -82,7 +88,7 @@ func (c *ClICtrl) mapApiFileToPhotoFile(ctx context.Context, album model.Album, photoFile.ThumbnailNonce = file.Thumbnail.DecryptionHeader photoFile.OwnerID = file.OwnerID if file.Info != nil { - photoFile.PhotoInfo = model.PhotoInfo{ + photoFile.Info = model.PhotoInfo{ FileSize: file.Info.FileSize, ThumbnailSize: file.Info.ThumbnailSize, } diff --git a/pkg/model/album.go b/pkg/model/album.go index dc4b1742c..203fe1449 100644 --- a/pkg/model/album.go +++ b/pkg/model/album.go @@ -1,14 +1,14 @@ package model type Album struct { - ID int64 `json:"id"` - OwnerID int64 `json:"ownerID"` - IsShared bool `json:"isShared"` - IsDeleted bool `json:"isDeleted"` - AlbumName string `json:"albumName"` - AlbumKey EncString `json:"albumKey"` - PublicMeta *string `json:"publicMeta"` - PrivateMeta *string `json:"privateMeta"` - SharedMeta *string `json:"sharedMeta"` - LastUpdatedAt int64 `json:"lastUpdatedAt"` + ID int64 `json:"id"` + OwnerID int64 `json:"ownerID"` + IsShared bool `json:"isShared"` + IsDeleted bool `json:"isDeleted"` + AlbumName string `json:"albumName"` + AlbumKey EncString `json:"albumKey"` + PublicMeta map[string]interface{} `json:"publicMeta"` + PrivateMeta map[string]interface{} `json:"privateMeta"` + SharedMeta map[string]interface{} `json:"sharedMeta"` + LastUpdatedAt int64 `json:"lastUpdatedAt"` } diff --git a/pkg/model/photo_file.go b/pkg/model/photo_file.go index 467be6a2a..f84c1556a 100644 --- a/pkg/model/photo_file.go +++ b/pkg/model/photo_file.go @@ -9,7 +9,7 @@ type PhotoFile struct { ThumbnailNonce string `json:"thumbnailNonce"` PrivateMetadata map[string]interface{} `json:"privateMetadata"` PublicMetadata map[string]interface{} `json:"publicMetadata"` - PhotoInfo PhotoInfo `` + Info PhotoInfo `json:"info"` } type PhotoInfo struct {