1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-01-05 17:40:26 +00:00

Rename Hypha to MediaHypha

This commit is contained in:
Timur Ismagilov 2022-02-04 16:00:38 +05:00 committed by Timur Ismagilov
parent 154069091e
commit a30d581bfd
17 changed files with 54 additions and 54 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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")
}

View File

@ -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()
}

View File

@ -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()

View File

@ -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
}

View File

@ -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
}

View File

@ -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()).

View File

@ -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

View File

@ -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
}

View File

@ -75,10 +75,10 @@
</h1>
{% 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" %}
<div class="binary-container binary-container_with-img">

View File

@ -349,14 +349,14 @@ func NaviTitleHTML(h hyphae.Hypher) string {
}
//line views/hypha.qtpl:78
func StreamAttachmentHTMLRaw(qw422016 *qt422016.Writer, h hyphae.Hypher) {
func StreamAttachmentHTMLRaw(qw422016 *qt422016.Writer, h *hyphae.MediaHypha) {
//line views/hypha.qtpl:78
StreamAttachmentHTML(qw422016, h, l18n.New("en", "en"))
//line views/hypha.qtpl:78
}
//line views/hypha.qtpl:78
func WriteAttachmentHTMLRaw(qq422016 qtio422016.Writer, h hyphae.Hypher) {
func WriteAttachmentHTMLRaw(qq422016 qtio422016.Writer, h *hyphae.MediaHypha) {
//line views/hypha.qtpl:78
qw422016 := qt422016.AcquireWriter(qq422016)
//line views/hypha.qtpl:78
@ -367,7 +367,7 @@ func WriteAttachmentHTMLRaw(qq422016 qtio422016.Writer, h hyphae.Hypher) {
}
//line views/hypha.qtpl:78
func AttachmentHTMLRaw(h hyphae.Hypher) string {
func AttachmentHTMLRaw(h *hyphae.MediaHypha) string {
//line views/hypha.qtpl:78
qb422016 := qt422016.AcquireByteBuffer()
//line views/hypha.qtpl:78
@ -382,12 +382,12 @@ func AttachmentHTMLRaw(h hyphae.Hypher) string {
}
//line views/hypha.qtpl:80
func StreamAttachmentHTML(qw422016 *qt422016.Writer, h hyphae.Hypher, lc *l18n.Localizer) {
func StreamAttachmentHTML(qw422016 *qt422016.Writer, h *hyphae.MediaHypha, lc *l18n.Localizer) {
//line views/hypha.qtpl:80
qw422016.N().S(`
`)
//line views/hypha.qtpl:81
switch filepath.Ext(h.(*hyphae.Hypha).BinaryPath()) {
switch filepath.Ext(h.BinaryPath()) {
//line views/hypha.qtpl:83
case ".jpg", ".gif", ".png", ".webp", ".svg", ".ico":
//line views/hypha.qtpl:83
@ -486,7 +486,7 @@ func StreamAttachmentHTML(qw422016 *qt422016.Writer, h hyphae.Hypher, lc *l18n.L
}
//line views/hypha.qtpl:109
func WriteAttachmentHTML(qq422016 qtio422016.Writer, h hyphae.Hypher, lc *l18n.Localizer) {
func WriteAttachmentHTML(qq422016 qtio422016.Writer, h *hyphae.MediaHypha, lc *l18n.Localizer) {
//line views/hypha.qtpl:109
qw422016 := qt422016.AcquireWriter(qq422016)
//line views/hypha.qtpl:109
@ -497,7 +497,7 @@ func WriteAttachmentHTML(qq422016 qtio422016.Writer, h hyphae.Hypher, lc *l18n.L
}
//line views/hypha.qtpl:109
func AttachmentHTML(h hyphae.Hypher, lc *l18n.Localizer) string {
func AttachmentHTML(h *hyphae.MediaHypha, lc *l18n.Localizer) string {
//line views/hypha.qtpl:109
qb422016 := qt422016.AcquireByteBuffer()
//line views/hypha.qtpl:109

View File

@ -11,7 +11,7 @@
{% import "github.com/bouncepaw/mycorrhiza/user" %}
{% import "github.com/bouncepaw/mycorrhiza/util" %}
{% func AttachmentMenuHTML(rq *http.Request, h *hyphae.Hypha, u *user.User) %}
{% func AttachmentMenuHTML(rq *http.Request, h *hyphae.MediaHypha, u *user.User) %}
{% code
lc := l18n.FromRequest(rq)
%}

View File

@ -51,7 +51,7 @@ var (
)
//line views/readers.qtpl:14
func StreamAttachmentMenuHTML(qw422016 *qt422016.Writer, rq *http.Request, h *hyphae.Hypha, u *user.User) {
func StreamAttachmentMenuHTML(qw422016 *qt422016.Writer, rq *http.Request, h *hyphae.MediaHypha, u *user.User) {
//line views/readers.qtpl:14
qw422016.N().S(`
`)
@ -265,7 +265,7 @@ func StreamAttachmentMenuHTML(qw422016 *qt422016.Writer, rq *http.Request, h *hy
}
//line views/readers.qtpl:78
func WriteAttachmentMenuHTML(qq422016 qtio422016.Writer, rq *http.Request, h *hyphae.Hypha, u *user.User) {
func WriteAttachmentMenuHTML(qq422016 qtio422016.Writer, rq *http.Request, h *hyphae.MediaHypha, u *user.User) {
//line views/readers.qtpl:78
qw422016 := qt422016.AcquireWriter(qq422016)
//line views/readers.qtpl:78
@ -276,7 +276,7 @@ func WriteAttachmentMenuHTML(qq422016 qtio422016.Writer, rq *http.Request, h *hy
}
//line views/readers.qtpl:78
func AttachmentMenuHTML(rq *http.Request, h *hyphae.Hypha, u *user.User) string {
func AttachmentMenuHTML(rq *http.Request, h *hyphae.MediaHypha, u *user.User) string {
//line views/readers.qtpl:78
qb422016 := qt422016.AcquireByteBuffer()
//line views/readers.qtpl:78

View File

@ -266,7 +266,7 @@ sort.Strings(editors)
<li class="hypha-list__entry">
<a class="hypha-list__link" href="/hypha/{%s hypha.CanonicalName() %}">{%s util.BeautifulName(hypha.CanonicalName()) %}</a>
{% if hypha.Kind() == hyphae.HyphaMedia %}
<span class="hypha-list__amnt-type">{%s filepath.Ext(hypha.(*hyphae.Hypha).BinaryPath())[1:] %}</span>
<span class="hypha-list__amnt-type">{%s filepath.Ext(hypha.(*hyphae.MediaHypha).BinaryPath())[1:] %}</span>
{% endif %}
</li>
{% endfor %}

View File

@ -1041,7 +1041,7 @@ func StreamHyphaListHTML(qw422016 *qt422016.Writer, lc *l18n.Localizer) {
qw422016.N().S(`
<span class="hypha-list__amnt-type">`)
//line views/stuff.qtpl:269
qw422016.E().S(filepath.Ext(hypha.(*hyphae.Hypha).BinaryPath())[1:])
qw422016.E().S(filepath.Ext(hypha.(*hyphae.MediaHypha).BinaryPath())[1:])
//line views/stuff.qtpl:269
qw422016.N().S(`</span>
`)

View File

@ -47,7 +47,7 @@ func handlerAttachment(w http.ResponseWriter, rq *http.Request) {
util.HTTP200Page(w,
views.BaseHTML(
lc.Get("ui.attach_title", &l18n.Replacements{"name": util.BeautifulName(hyphaName)}),
views.AttachmentMenuHTML(rq, h.(*hyphae.Hypha), u),
views.AttachmentMenuHTML(rq, h.(*hyphae.MediaHypha), u),
lc,
u))
}
@ -149,7 +149,7 @@ func handlerText(w http.ResponseWriter, rq *http.Request) {
func handlerBinary(w http.ResponseWriter, rq *http.Request) {
util.PrepareRq(rq)
hyphaName := util.HyphaNameFromRq(rq, "binary")
if h := hyphae.ByName(hyphaName).(*hyphae.Hypha); h.DoesExist() {
if h := hyphae.ByName(hyphaName).(*hyphae.MediaHypha); h.DoesExist() {
log.Println("Serving", h.BinaryPath())
w.Header().Set("Content-Type", mimetype.FromExtension(filepath.Ext(h.BinaryPath())))
http.ServeFile(w, rq, h.BinaryPath())
@ -178,7 +178,7 @@ func handlerHypha(w http.ResponseWriter, rq *http.Request) {
openGraph = getOpenGraph()
}
if h.Kind() == hyphae.HyphaMedia {
contents = views.AttachmentHTML(h, lc) + contents
contents = views.AttachmentHTML(h.(*hyphae.MediaHypha), lc) + contents
}
}
if contents == "" {