diff --git a/api/sync15/blobdoc.go b/api/sync15/blobdoc.go index d20d19b..232ce88 100644 --- a/api/sync15/blobdoc.go +++ b/api/sync15/blobdoc.go @@ -109,6 +109,42 @@ func (d *BlobDoc) IndexReader() (io.ReadCloser, error) { return pipeReader, nil } +func (d *BlobDoc) ReadContentTags(fileEntry *Entry, r RemoteStorage) error { + if strings.HasSuffix(fileEntry.DocumentID, ".content") { + contentFile := archive.Content{} + + meta, err := r.GetReader(fileEntry.Hash) + if err != nil { + return err + } + defer meta.Close() + content, err := ioutil.ReadAll(meta) + if err != nil { + return err + } + err = json.Unmarshal(content, &contentFile) + if err != nil { + return err + } + if contentFile.FileTags != nil { + fileTags := []string{} + for _, t := range contentFile.FileTags { + fileTags = append(fileTags, t.Name) + } + d.MetadataFile.FileTags = fileTags + } + if contentFile.Tags != nil { + pageTags := []string{} + for _, t := range contentFile.Tags { + pageTags = append(pageTags, t.Name) + } + d.MetadataFile.PageTags = pageTags + } + } + + return nil +} + // ReadMetadata the document metadata from remote blob func (d *BlobDoc) ReadMetadata(fileEntry *Entry, r RemoteStorage) error { if strings.HasSuffix(fileEntry.DocumentID, ".metadata") { @@ -184,6 +220,10 @@ func (d *BlobDoc) Mirror(e *Entry, r RemoteStorage) error { if err != nil { return err } + err = d.ReadContentTags(newEntry, r) + if err != nil { + return err + } currentEntry.Hash = newEntry.Hash } head = append(head, currentEntry) @@ -198,6 +238,10 @@ func (d *BlobDoc) Mirror(e *Entry, r RemoteStorage) error { if err != nil { return err } + err = d.ReadContentTags(newEntry, r) + if err != nil { + return err + } head = append(head, newEntry) } } diff --git a/archive/file.go b/archive/file.go index 08062ea..b319b35 100644 --- a/archive/file.go +++ b/archive/file.go @@ -87,25 +87,37 @@ type Layer struct { Name string `json:"name"` } +type FileTag struct { + Name string `json:"name"` + Timestamp int `json:"timestamp"` +} + +type PageTag struct { + Name string `json:"name"` + PageId string `json:"pageId"` + Timestamp int `json:"timestamp"` +} + // Content represents the structure of a .content json file. type Content struct { DummyDocument bool `json:"dummyDocument"` ExtraMetadata ExtraMetadata `json:"extraMetadata"` // FileType is "pdf", "epub" or empty for a simple note - FileType string `json:"fileType"` - FontName string `json:"fontName"` - LastOpenedPage int `json:"lastOpenedPage"` - LineHeight int `json:"lineHeight"` - Margins int `json:"margins"` + FileType string `json:"fileType"` + FileTags []FileTag `json:"fileTags"` + FontName string `json:"fontName"` + LastOpenedPage int `json:"lastOpenedPage"` + LineHeight int `json:"lineHeight"` + Margins int `json:"margins"` // Orientation can take "portrait" or "landscape". Orientation string `json:"orientation"` PageCount int `json:"pageCount"` // Pages is a list of page IDs - Pages []string `json:"pages"` - Tags []string `json:"pageTags"` - RedirectionMap []int `json:"redirectionPageMap"` - TextScale int `json:"textScale"` + Pages []string `json:"pages"` + Tags []PageTag `json:"pageTags"` + RedirectionMap []int `json:"redirectionPageMap"` + TextScale int `json:"textScale"` Transform Transform `json:"transform"` } @@ -147,13 +159,15 @@ type MetadataFile struct { CollectionType string `json:"type"` Parent string `json:"parent"` //LastModified in milliseconds - LastModified string `json:"lastModified"` - LastOpened string `json:"lastOpened"` - LastOpenedPage int `json:"lastOpenedPage"` - Version int `json:"version"` - Pinned bool `json:"pinned"` - Synced bool `json:"synced"` - Modified bool `json:"modified"` - Deleted bool `json:"deleted"` - MetadataModified bool `json:"metadatamodified"` + LastModified string `json:"lastModified"` + LastOpened string `json:"lastOpened"` + LastOpenedPage int `json:"lastOpenedPage"` + Version int `json:"version"` + Pinned bool `json:"pinned"` + Synced bool `json:"synced"` + Modified bool `json:"modified"` + Deleted bool `json:"deleted"` + MetadataModified bool `json:"metadatamodified"` + FileTags []string `json:"fileTags"` + PageTags []string `json:"pageTags"` }