Forráskód Böngészése

Store metadata as map for albums

Neeraj Gupta 1 éve
szülő
commit
12ff1ee552
6 módosított fájl, 34 hozzáadás és 22 törlés
  1. 1 1
      main.go
  2. 6 0
      pkg/collections.go
  3. 3 3
      pkg/log/debug_print.go
  4. 13 7
      pkg/mappers.go
  5. 10 10
      pkg/model/album.go
  6. 1 1
      pkg/model/photo_file.go

+ 1 - 1
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(),

+ 6 - 0
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

+ 3 - 3
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=======")

+ 13 - 7
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,
 		}

+ 10 - 10
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"`
 }

+ 1 - 1
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 {