π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add logic to map remoteFile to diskMetadata
Neeraj Guptaee1cc3ca91ba
diff --git a/pkg/download.go b/pkg/download.goindex 22b0feab3d..785e0d76e5 100644--- a/pkg/download.go+++ b/pkg/download.go@@ -3,7 +3,6 @@ package pkgimport ("context""fmt"- "log""os")@@ -16,13 +15,14 @@ func (c *ClICtrl) initiateDownload(ctx context.Context) error {if err != nil {return err}- for _, file := range files {- downloadPath := fmt.Sprintf("%s/%d", dir, file.ID)- log.Printf("Downloading file %d to %s", file.ID, downloadPath)- //err = c.Client.DownloadFile(ctx, file.ID, downloadPath)- //if err != nil {- // return err- //}- }+ fmt.Println("total files to download: in diroector", len(files), dir)+ //for _, file := range files {+ // //downloadPath := fmt.Sprintf("%s/%d", dir, file.ID)+ // //log.Printf("Downloading file %d to %s", file.ID, downloadPath)+ // //err = c.Client.DownloadFile(ctx, file.ID, downloadPath)+ // //if err != nil {+ // // return err+ // //}+ //}return nil}diff --git a/pkg/mapper/photo.go b/pkg/mapper/photo.goindex 63617c5adf..f35c49b993 100644--- a/pkg/mapper/photo.go+++ b/pkg/mapper/photo.go@@ -4,6 +4,7 @@ import ("cli-go/internal/api"eCrypto "cli-go/internal/crypto""cli-go/pkg/model"+ "cli-go/pkg/model/export""cli-go/pkg/secrets""cli-go/utils/encoding""context"@@ -126,5 +127,20 @@ func MapApiFileToPhotoFile(ctx context.Context, album model.RemoteAlbum, file ap}}return &photoFile, nil+}+func MapRemoteFileToDiskMetadata(file model.RemoteFile) export.DiskFileMetadata {+ result := export.DiskFileMetadata{+ Title: file.GetTitle(),+ Description: file.GetCaption(),+ CreationTime: file.GetCreationTime(),+ ModificationTime: file.GetModificationTime(),+ Location: file.GetLatlong(),+ Info: &export.Info{+ ID: file.ID,+ Hash: file.GetFileHash(),+ OwnerID: file.OwnerID,+ },+ }+ return result}diff --git a/pkg/model/export/location.go b/pkg/model/export/location.gonew file mode 100644index 0000000000..5dff62c266--- /dev/null+++ b/pkg/model/export/location.go@@ -0,0 +1,6 @@+package export++type Location struct {+ Latitude float64 `json:"latitude"`+ Longitude float64 `json:"longitude"`+}diff --git a/pkg/model/export/metadata.go b/pkg/model/export/metadata.goindex de48c4675c..e7ce17bd4b 100644--- a/pkg/model/export/metadata.go+++ b/pkg/model/export/metadata.go@@ -1,5 +1,7 @@package export+import "time"+type AlbumMetadata struct {ID int64 `json:"id"`OwnerID int64 `json:"ownerID"`@@ -26,3 +28,20 @@ func (a *AlbumMetadata) AddAccountOwner(id int64) bool {a.AccountOwnerIDs = append(a.AccountOwnerIDs, id)return true}++// DiskFileMetadata is the metadata for a file when exported to disk+// For S3 compliant storage, we will introduce a new struct that will contain references to the albums+type DiskFileMetadata struct {+ Title string `json:"title"`+ Description *string `json:"description"`+ Location *Location `json:"location"`+ CreationTime time.Time `json:"creationTime"`+ ModificationTime time.Time `json:"modificationTime"`+ Info *Info `json:"info"`+}++type Info struct {+ ID int64 `json:"id"`+ Hash *string `json:"hash"`+ OwnerID int64 `json:"ownerID"`+}diff --git a/pkg/model/remote.go b/pkg/model/remote.goindex e3dd4e1ee1..52f97104e0 100644--- a/pkg/model/remote.go+++ b/pkg/model/remote.go@@ -1,5 +1,20 @@package model+import (+ "cli-go/pkg/model/export"+ "fmt"+ "time"+)++type FileType int8++const (+ Image FileType = iota+ Video+ LivePhoto+ Unknown = 127+)+type RemoteFile struct {ID int64 `json:"id"`OwnerID int64 `json:"ownerID"`@@ -37,3 +52,105 @@ type AlbumFileEntry struct {IsDeleted bool `json:"isDeleted"`SyncedLocally bool `json:"localSync"`}++func (r *RemoteFile) GetFileType() FileType {+ value, ok := r.Metadata["fileType"]+ if !ok {+ panic("fileType not found in metadata")+ }+ switch value.(int8) {+ case 0:+ return Image+ case 1:+ return Video+ case 2:+ return LivePhoto+ }+ panic(fmt.Sprintf("invalid fileType %d", value.(int8)))+}++func (r *RemoteFile) GetFileHash() *string {+ value, ok := r.Metadata["hash"]+ if !ok {+ return nil+ }+ if str, ok := value.(string); ok {+ return &str+ }+ return nil+}++func (r *RemoteFile) GetTitle() string {+ if r.PublicMetadata != nil {+ if value, ok := r.PublicMetadata["editedName"]; ok {+ return value.(string)+ }+ }+ value, ok := r.Metadata["title"]+ if !ok {+ panic("title not found in metadata")+ }+ return value.(string)+}++func (r *RemoteFile) GetCaption() *string {+ if r.PublicMetadata != nil {+ if value, ok := r.PublicMetadata["caption"]; ok {+ if str, ok := value.(string); ok {+ return &str+ }+ }+ }+ return nil+}++func (r *RemoteFile) GetCreationTime() time.Time {++ if r.PublicMetadata != nil {+ if value, ok := r.PublicMetadata["editedTime"]; ok && value.(float64) != 0 {+ return time.UnixMicro(int64(value.(float64)))+ }+ }+ value, ok := r.Metadata["creationTime"]+ if !ok {+ panic("creationTime not found in metadata")+ }+ return time.UnixMicro(int64(value.(float64)))+}++func (r *RemoteFile) GetModificationTime() time.Time {+ value, ok := r.Metadata["modificationTime"]+ if !ok {+ panic("creationTime not found in metadata")+ }+ return time.UnixMicro(int64(value.(float64)))+}++func (r *RemoteFile) GetLatlong() *export.Location {+ if r.ID == 10698020 {+ fmt.Println("found 10698020")+ }+ if r.PublicMetadata != nil {+ // check if lat and long key exists+ if lat, ok := r.PublicMetadata["lat"]; ok {+ if long, ok := r.PublicMetadata["long"]; ok {+ if lat.(float64) == 0 && long.(float64) == 0 {+ return nil+ }+ return &export.Location{+ Latitude: lat.(float64),+ Longitude: long.(float64),+ }+ }+ }+ }+ if lat, ok := r.Metadata["latitude"]; ok && lat != nil {+ if long, ok2 := r.Metadata["longitude"]; ok2 && long != nil {+ return &export.Location{+ Latitude: lat.(float64),+ Longitude: long.(float64),+ }+ }+ }+ return nil+}diff --git a/pkg/remote_sync.go b/pkg/remote_sync.goindex 07bb1ebd38..6b3fb54c78 100644--- a/pkg/remote_sync.go+++ b/pkg/remote_sync.go@@ -163,14 +163,14 @@ func (c *ClICtrl) getRemoteFiles(ctx context.Context) ([]model.RemoteFile, errorreturn files, nil}-func (c *ClICtrl) getRemoteAlbumEntries(ctx context.Context) ([]model.AlbumFileEntry, error) {- entries := make([]model.AlbumFileEntry, 0)+func (c *ClICtrl) getRemoteAlbumEntries(ctx context.Context) ([]*model.AlbumFileEntry, error) {+ entries := make([]*model.AlbumFileEntry, 0)entryBytes, err := c.GetAllValues(ctx, model.RemoteAlbumEntries)if err != nil {return nil, err}for _, entryJson := range entryBytes {- entry := model.AlbumFileEntry{}+ entry := &model.AlbumFileEntry{}err = json.Unmarshal(entryJson, &entry)if err != nil {return nil, errdiff --git a/pkg/remote_to_local_file_sync.go b/pkg/remote_to_local_file_sync.goindex 7cd649baa5..8bb820eea8 100644--- a/pkg/remote_to_local_file_sync.go+++ b/pkg/remote_to_local_file_sync.go@@ -1,6 +1,7 @@package pkgimport (+ "cli-go/pkg/mapper""cli-go/pkg/model""cli-go/utils/encoding""context"@@ -10,6 +11,7 @@ import ()func (c *ClICtrl) syncFiles(ctx context.Context) error {+ log.Printf("Starting sync files")home, err := exportHome(ctx)if err != nil {return err@@ -22,6 +24,7 @@ func (c *ClICtrl) syncFiles(ctx context.Context) error {if err != nil {return err}+ log.Println("total entries", len(entries))for _, entry := range entries {if entry.SyncedLocally {continue@@ -40,17 +43,20 @@ func (c *ClICtrl) syncFiles(ctx context.Context) error {}continue}- fileBytes, err := c.GetValue(ctx, model.RemoteAlbumEntries, []byte(fmt.Sprintf("%d:%d", entry.AlbumID, entry.FileID)))+ fileBytes, err := c.GetValue(ctx, model.RemoteFiles, []byte(fmt.Sprintf("%d", entry.FileID)))if err != nil {return err}if fileBytes != nil {- var existingEntry model.RemoteFile+ var existingEntry *model.RemoteFileerr = json.Unmarshal(fileBytes, &existingEntry)if err != nil {return err}- log.Printf("Should download %s into %s", existingEntry.Metadata["name"], albumInfo.FolderName)+ fileDiskMetadata := mapper.MapRemoteFileToDiskMetadata(*existingEntry)+ log.Printf("File %+v\\n ", fileDiskMetadata)+ } else {+ log.Fatalf("remoteFile %d not found in remoteFiles", entry.FileID)}}return nil