summaryrefslogtreecommitdiff
path: root/model/source.go
diff options
context:
space:
mode:
authorewy <ewy0@protonmail.com>2026-04-14 16:37:17 +0200
committerewy <ewy0@protonmail.com>2026-04-14 16:37:17 +0200
commit45a297a8e526094e8fce6e2c5c0fd89b381d1765 (patch)
tree852ebc3a0112c94dc9726d0b27ab057bf6383660 /model/source.go
i have to commit at some point!
Diffstat (limited to 'model/source.go')
-rw-r--r--model/source.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/model/source.go b/model/source.go
new file mode 100644
index 0000000..3a5fe10
--- /dev/null
+++ b/model/source.go
@@ -0,0 +1,61 @@
+package model
+
+import (
+ "pik/identity"
+ "pik/paths"
+ "pik/spool"
+)
+
+type Source struct {
+ identity.Identity
+ Tags
+ Path string
+ Targets []Target
+}
+
+type HydratedSource struct {
+ *Source
+ HydratedTargets []HydratedTarget
+ Aliases []string
+ Icon string
+}
+
+func (s *Source) Label() string {
+ return s.Identity.Full
+}
+
+func (s *HydratedSource) Label() string {
+ if len(s.Aliases) > 0 {
+ return s.Aliases[0]
+ }
+ return s.Identity.Full
+}
+
+func (s *Source) Hydrate(hydrators []Hydrator) *HydratedSource {
+ hs := &HydratedSource{
+ Source: s,
+ HydratedTargets: make([]HydratedTarget, 0, len(s.Targets)),
+ }
+ for _, h := range hydrators {
+ err := h.Hydrate(s, hs)
+ if err != nil {
+ spool.Warn("%v", err)
+ }
+ }
+ for _, t := range s.Targets {
+ if !t.Visible() {
+ continue
+ }
+ ht, err := t.Hydrate(s)
+ if err != nil {
+ spool.Warn("%v", err)
+ continue
+ }
+ hs.HydratedTargets = append(hs.HydratedTargets, ht)
+ }
+ return hs
+}
+
+func (s *Source) ShortPath() string {
+ return paths.ReplaceHome(s.Path)
+}