Store remote albums in local db
This commit is contained in:
parent
47fbe0140b
commit
ed3d4edaad
3 changed files with 24 additions and 0 deletions
|
@ -3,6 +3,7 @@ package pkg
|
|||
import (
|
||||
debuglog "cli-go/pkg/log"
|
||||
"cli-go/pkg/model"
|
||||
"cli-go/utils/encoding"
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
@ -36,6 +37,11 @@ func (c *ClICtrl) syncRemoteCollections(ctx context.Context, info model.Account)
|
|||
if album.LastUpdatedAt > maxUpdated {
|
||||
maxUpdated = album.LastUpdatedAt
|
||||
}
|
||||
albumJson := encoding.MustMarshalJSON(album)
|
||||
err := c.PutValue(ctx, model.RemoteAlbums, []byte(strconv.FormatInt(album.ID, 10)), albumJson)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
debuglog.PrintAlbum(album)
|
||||
}
|
||||
if maxUpdated > lastSyncTime {
|
||||
|
|
|
@ -40,6 +40,15 @@ func (c *ClICtrl) PutConfigValue(ctx context.Context, key string, value []byte)
|
|||
return kvBucket.Put([]byte(key), value)
|
||||
})
|
||||
}
|
||||
func (c *ClICtrl) PutValue(ctx context.Context, store model.PhotosStore, key []byte, value []byte) error {
|
||||
return c.DB.Update(func(tx *bolt.Tx) error {
|
||||
kvBucket, err := getAccountStore(ctx, tx, store)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return kvBucket.Put(key, value)
|
||||
})
|
||||
}
|
||||
|
||||
func getAccountStore(ctx context.Context, tx *bolt.Tx, storeType model.PhotosStore) (*bolt.Bucket, error) {
|
||||
accountId := ctx.Value("account_id").(string)
|
||||
|
|
|
@ -2,6 +2,7 @@ package encoding
|
|||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
func DecodeBase64(s string) []byte {
|
||||
|
@ -15,3 +16,11 @@ func DecodeBase64(s string) []byte {
|
|||
func EncodeBase64(b []byte) string {
|
||||
return base64.StdEncoding.EncodeToString(b)
|
||||
}
|
||||
|
||||
func MustMarshalJSON(v interface{}) []byte {
|
||||
b, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue