Skip to content

Commit

Permalink
Allow to have other target metadata fields for shortcuts (#4455)
Browse files Browse the repository at this point in the history
  • Loading branch information
nono authored Aug 22, 2024
2 parents 970a56c + 8bbccfd commit 01ad103
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions model/vfs/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ func NewMetaExtractor(doc *FileDoc) *MetaExtractor {
if doc.CozyMetadata != nil {
instance = doc.CozyMetadata.CreatedOn
}
e = NewShortcutExtractor(instance)
var target map[string]interface{}
if doc.Metadata != nil {
target, _ = doc.Metadata["target"].(map[string]interface{})
}
e = NewShortcutExtractor(instance, target)
}
if e != nil {
return &e
Expand Down Expand Up @@ -453,12 +457,14 @@ type ShortcutExtractor struct {
r *io.PipeReader
ch chan interface{}
instance string
target map[string]interface{}
}

// NewShortcutExtractor returns an extractor for .url files
func NewShortcutExtractor(instance string) *ShortcutExtractor {
func NewShortcutExtractor(instance string, target map[string]interface{}) *ShortcutExtractor {
e := &ShortcutExtractor{}
e.instance = instance
e.target = target
e.r, e.w = io.Pipe()
e.ch = make(chan interface{})
go e.Start()
Expand Down Expand Up @@ -512,10 +518,12 @@ func (e *ShortcutExtractor) Result() Metadata {
if link, ok := link.(shortcut.Result); ok {
cozy, app := extractCozyLink(link, e.instance)
if cozy != "" {
target := map[string]interface{}{
"cozyMetadata": map[string]interface{}{
"instance": cozy,
},
target := e.target
if target == nil {
target = map[string]interface{}{}
}
target["cozyMetadata"] = map[string]interface{}{
"instance": cozy,
}
if app != "" {
target["app"] = app
Expand Down

0 comments on commit 01ad103

Please sign in to comment.