Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Add file and page tags to the cache file #281

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions api/sync15/blobdoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
}
Expand Down
50 changes: 32 additions & 18 deletions archive/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down Expand Up @@ -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"`
}