diff --git a/hyphae/count.go b/hyphae/count.go index 5744d6b..4d67c81 100644 --- a/hyphae/count.go +++ b/hyphae/count.go @@ -4,7 +4,7 @@ import ( "sync" ) -// Its value is number of all existing hyphae. Hypha mutators are expected to manipulate the value. It is concurrent-safe. +// Its value is number of all existing hyphae. MediaHypha mutators are expected to manipulate the value. It is concurrent-safe. var count = struct { value int sync.Mutex diff --git a/hyphae/files.go b/hyphae/files.go index 24d41dd..6d9e25d 100644 --- a/hyphae/files.go +++ b/hyphae/files.go @@ -21,9 +21,9 @@ func Index(path string) { for h := range ch { // It's safe to ignore the mutex because there is a single worker right now. if oh := ByName(h.CanonicalName()); oh.DoesExist() { - oh.(*Hypha).mergeIn(h.(*Hypha)) + oh.(*MediaHypha).mergeIn(h.(*MediaHypha)) } else { - insert(h.(*Hypha)) + insert(h.(*MediaHypha)) } } log.Println("Indexed", Count(), "hyphae") @@ -49,7 +49,7 @@ func indexHelper(path string, nestLevel uint, ch chan Hypher) { var ( hyphaPartPath = filepath.Join(path, node.Name()) hyphaName, isText, skip = mimetype.DataFromFilename(hyphaPartPath) - hypha = &Hypha{name: hyphaName, Exists: true} + hypha = &MediaHypha{name: hyphaName, Exists: true} ) if !skip { if isText { diff --git a/hyphae/hyphae.go b/hyphae/hyphae.go index a2c482f..936ca33 100644 --- a/hyphae/hyphae.go +++ b/hyphae/hyphae.go @@ -1,4 +1,4 @@ -// Package hyphae is for the Hypha type, hypha storage and stuff like that. It shall not depend on mycorrhiza modules other than util. +// Package hyphae is for the MediaHypha type, hypha storage and stuff like that. It shall not depend on mycorrhiza modules other than util. package hyphae import ( @@ -27,8 +27,8 @@ func IsValidName(hyphaName string) bool { return true } -// Hypha keeps vital information about a hypha -type Hypha struct { +// MediaHypha keeps vital information about a media hypha +type MediaHypha struct { sync.RWMutex name string // Canonical name @@ -37,16 +37,16 @@ type Hypha struct { binaryPath string // == "" => no attachment } -func (h *Hypha) SetName(s string) { h.name = s } +func (h *MediaHypha) SetName(s string) { h.name = s } -func (h *Hypha) BinaryPath() string { return h.binaryPath } -func (h *Hypha) SetBinaryPath(s string) { h.binaryPath = s } +func (h *MediaHypha) BinaryPath() string { return h.binaryPath } +func (h *MediaHypha) SetBinaryPath(s string) { h.binaryPath = s } -func (h *Hypha) CanonicalName() string { +func (h *MediaHypha) CanonicalName() string { return h.name } -func (h *Hypha) Kind() HyphaKind { +func (h *MediaHypha) Kind() HyphaKind { if !h.DoesExist() { return HyphaEmpty } @@ -56,16 +56,16 @@ func (h *Hypha) Kind() HyphaKind { return HyphaText } -func (h *Hypha) DoesExist() bool { // TODO: rename +func (h *MediaHypha) DoesExist() bool { // TODO: rename return h.Exists } -func (h *Hypha) HasTextPart() bool { +func (h *MediaHypha) HasTextPart() bool { return h.TextPath != "" } // TextPartPath returns rooted path to the file where the text part should be. -func (h *Hypha) TextPartPath() string { +func (h *MediaHypha) TextPartPath() string { if h.TextPath == "" { return filepath.Join(files.HyphaeDir(), h.name+".myco") } @@ -73,7 +73,7 @@ func (h *Hypha) TextPartPath() string { } // HasAttachment is true if the hypha has an attachment. -func (h *Hypha) HasAttachment() bool { +func (h *MediaHypha) HasAttachment() bool { return h.binaryPath != "" } @@ -81,8 +81,8 @@ var byNames = make(map[string]Hypher) var byNamesMutex = sync.Mutex{} // EmptyHypha returns an empty hypha struct with given name. -func EmptyHypha(hyphaName string) *Hypha { - return &Hypha{ +func EmptyHypha(hyphaName string) *MediaHypha { + return &MediaHypha{ name: hyphaName, Exists: false, TextPath: "", @@ -105,7 +105,7 @@ func storeHypha(h Hypher) { byNamesMutex.Unlock() h.Lock() - h.(*Hypha).Exists = true + h.(*MediaHypha).Exists = true h.Unlock() } @@ -113,7 +113,7 @@ func storeHypha(h Hypher) { func insert(h Hypher) (madeNewRecord bool) { hp, recorded := byNames[h.CanonicalName()] if recorded { - hp.(*Hypha).mergeIn(h) + hp.(*MediaHypha).mergeIn(h) } else { storeHypha(h) incrementCount() @@ -131,7 +131,7 @@ func InsertIfNew(h Hypher) (madeNewRecord bool) { } // mergeIn merges in content file paths from a different hypha object. Prints warnings sometimes. -func (h *Hypha) mergeIn(oh Hypher) { +func (h *MediaHypha) mergeIn(oh Hypher) { if h == oh { return } @@ -139,7 +139,7 @@ func (h *Hypha) mergeIn(oh Hypher) { if h.TextPath == "" && oh.HasTextPart() { h.TextPath = oh.TextPartPath() } - if oh := oh.(*Hypha); oh.Kind() == HyphaMedia { + if oh := oh.(*MediaHypha); oh.Kind() == HyphaMedia { if h.binaryPath != "" { log.Println("There is a file collision for attachment of a hypha:", h.binaryPath, "and", oh.binaryPath, "-- going on with the latter") } diff --git a/hyphae/interface.go b/hyphae/interface.go index 78e94d0..b704b44 100644 --- a/hyphae/interface.go +++ b/hyphae/interface.go @@ -10,7 +10,7 @@ const ( HyphaMedia ) -// Hypher is a temporary name for this interface. The name will become Hypha, once the struct with the said name is deprecated for good. +// Hypher is a temporary name for this interface. The name will become MediaHypha, once the struct with the said name is deprecated for good. type Hypher interface { sync.Locker @@ -37,8 +37,8 @@ func RenameHyphaTo(h Hypher, newName string) { byNamesMutex.Lock() h.Lock() delete(byNames, h.CanonicalName()) - h.(*Hypha).SetName(newName) - byNames[h.CanonicalName()] = h.(*Hypha) + h.(*MediaHypha).SetName(newName) + byNames[h.CanonicalName()] = h.(*MediaHypha) byNamesMutex.Unlock() h.Unlock() } diff --git a/shroom/delete.go b/shroom/delete.go index 4721b93..73cb236 100644 --- a/shroom/delete.go +++ b/shroom/delete.go @@ -21,7 +21,7 @@ func DeleteHypha(u *user.User, h hyphae.Hypher, lc *l18n.Localizer) (hop *histor originalText, _ := FetchTextPart(h) hop. - WithFilesRemoved(h.TextPartPath(), h.(*hyphae.Hypha).BinaryPath()). + WithFilesRemoved(h.TextPartPath(), h.(*hyphae.MediaHypha).BinaryPath()). WithMsg(fmt.Sprintf("Delete ā%sā", h.CanonicalName())). WithUser(u). Apply() diff --git a/shroom/init.go b/shroom/init.go index a338618..b220a40 100644 --- a/shroom/init.go +++ b/shroom/init.go @@ -16,12 +16,12 @@ func init() { globals.HyphaAccess = func(hyphaName string) (rawText, binaryBlock string, err error) { if h := hyphae.ByName(hyphaName); h.DoesExist() { rawText, err = FetchTextPart(h) - if h.(*hyphae.Hypha).BinaryPath() != "" { + if h := h.(*hyphae.MediaHypha); h.Kind() == hyphae.HyphaMedia { // the view is localized, but we can't pass it, so... binaryBlock = views.AttachmentHTMLRaw(h) } } else { - err = errors.New("Hypha " + hyphaName + " does not exist") + err = errors.New("MediaHypha " + hyphaName + " does not exist") } return } diff --git a/shroom/rename.go b/shroom/rename.go index 5aa1423..2322b6c 100644 --- a/shroom/rename.go +++ b/shroom/rename.go @@ -69,7 +69,7 @@ func RenameHypha(h hyphae.Hypher, newHypha hyphae.Hypher, recursive bool, u *use Apply() if len(hop.Errs) == 0 { for _, h := range hyphaeToRename { - h := h.(*hyphae.Hypha) // ontology think + h := h.(*hyphae.MediaHypha) // ontology think oldName := h.CanonicalName() hyphae.RenameHyphaTo(h, replaceName(h.CanonicalName())) h.Lock() @@ -100,13 +100,13 @@ func renamingPairs(hyphaeToRename []hyphae.Hypher, replaceName func(string) stri renameMap[h.TextPartPath()] = replaceName(h.TextPartPath()) } if h.Kind() == hyphae.HyphaMedia { // ontology think - h := h.(*hyphae.Hypha) + h := h.(*hyphae.MediaHypha) renameMap[h.BinaryPath()] = replaceName(h.BinaryPath()) } h.Unlock() } if firstFailure, ok := hyphae.AreFreeNames(newNames...); !ok { - return nil, errors.New("Hypha " + firstFailure + " already exists") + return nil, errors.New("MediaHypha " + firstFailure + " already exists") } return renameMap, nil } diff --git a/shroom/unattach.go b/shroom/unattach.go index 7245f0f..5897e4a 100644 --- a/shroom/unattach.go +++ b/shroom/unattach.go @@ -17,7 +17,7 @@ func UnattachHypha(u *user.User, h hyphae.Hypher, lc *l18n.Localizer) (hop *hist hop.WithErrAbort(err) return hop, errtitle } - H := h.(*hyphae.Hypha) + H := h.(*hyphae.MediaHypha) hop. WithFilesRemoved(H.BinaryPath()). diff --git a/shroom/upload.go b/shroom/upload.go index bced1e4..f6573aa 100644 --- a/shroom/upload.go +++ b/shroom/upload.go @@ -77,7 +77,7 @@ func uploadHelp(h hyphae.Hypher, hop *history.Op, ext string, data []byte, u *us err := errors.New("bad path") return hop.WithErrAbort(err), err.Error() } - if h := h.(*hyphae.Hypha); hop.Type == history.TypeEditBinary { + if h := h.(*hyphae.MediaHypha); hop.Type == history.TypeEditBinary { sourceFullPath = h.BinaryPath() } @@ -105,7 +105,7 @@ func uploadHelp(h hyphae.Hypher, hop *history.Op, ext string, data []byte, u *us return hop.Abort(), "No changes" } // TODO: test - if h := h.(*hyphae.Hypha); hop.Type == history.TypeEditBinary { + if h := h.(*hyphae.MediaHypha); hop.Type == history.TypeEditBinary { h.SetBinaryPath(fullPath) } else { h.TextPath = fullPath diff --git a/tree/tree.go b/tree/tree.go index f766cc9..5a354b9 100644 --- a/tree/tree.go +++ b/tree/tree.go @@ -20,7 +20,7 @@ func findSiblings(hyphaName string) []*sibling { siblingsMap = make(map[string]bool) siblingCheck = func(h hyphae.Hypher) hyphae.CheckResult { switch { - case h.CanonicalName() == hyphaName, // Hypha is no sibling of itself + case h.CanonicalName() == hyphaName, // MediaHypha is no sibling of itself h.CanonicalName() == parentHyphaName: // Parent hypha is no sibling of its child return hyphae.CheckContinue } diff --git a/views/hypha.qtpl b/views/hypha.qtpl index a5f9a1f..a41621f 100644 --- a/views/hypha.qtpl +++ b/views/hypha.qtpl @@ -75,10 +75,10 @@ {% endfunc %} -{% func AttachmentHTMLRaw(h hyphae.Hypher) %}{%= AttachmentHTML(h, l18n.New("en", "en")) %}{% endfunc %} +{% func AttachmentHTMLRaw(h *hyphae.MediaHypha) %}{%= AttachmentHTML(h, l18n.New("en", "en")) %}{% endfunc %} -{% func AttachmentHTML(h hyphae.Hypher, lc *l18n.Localizer) %} - {% switch filepath.Ext(h.(*hyphae.Hypha).BinaryPath()) %} +{% func AttachmentHTML(h *hyphae.MediaHypha, lc *l18n.Localizer) %} + {% switch filepath.Ext(h.BinaryPath()) %} {% case ".jpg", ".gif", ".png", ".webp", ".svg", ".ico" %}