Store metadata as map for albums
This commit is contained in:
parent
4294747d36
commit
12ff1ee552
6 changed files with 34 additions and 22 deletions
2
main.go
2
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(),
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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=======")
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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"`
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue