diff --git a/hyphae/existing_hypha.go b/hyphae/existing_hypha.go index d75523a..3f230f9 100644 --- a/hyphae/existing_hypha.go +++ b/hyphae/existing_hypha.go @@ -2,6 +2,8 @@ package hyphae import ( "github.com/bouncepaw/mycorrhiza/util" + "os" + "path/filepath" ) // ExistingHypha is not EmptyHypha. *MediaHypha and *TextualHypha implement this interface. @@ -59,3 +61,19 @@ func Insert(h ExistingHypha) (madeNewRecord bool) { return !recorded } + +func WriteToMycoFile(h ExistingHypha, data []byte) error { + if err := os.MkdirAll(filepath.Dir(h.TextFilePath()), 0777); err != nil { + return err + } + if err := os.WriteFile(h.TextFilePath(), data, 0666); err != nil { + return err + } + switch h := h.(type) { + case *MediaHypha: + if !h.HasTextFile() { + h.mycoFilePath = h.TextFilePath() + } + } + return nil +} diff --git a/shroom/upload.go b/shroom/upload.go index 97f0e7e..04045f4 100644 --- a/shroom/upload.go +++ b/shroom/upload.go @@ -33,11 +33,7 @@ func historyMessageForTextUpload(h hyphae.Hypha, userMessage string) string { } func writeTextToDisk(h hyphae.ExistingHypha, data []byte, hop *history.Op) error { - if err := os.MkdirAll(filepath.Dir(h.TextFilePath()), 0777); err != nil { - return err - } - - if err := os.WriteFile(h.TextFilePath(), data, 0666); err != nil { + if err := hyphae.WriteToMycoFile(h, data); err != nil { return err } hop.WithFiles(h.TextFilePath()) @@ -92,6 +88,7 @@ func UploadText(h hyphae.Hypha, data []byte, userMessage string, u *user.User) e } hyphae.Insert(H) + backlinks.UpdateBacklinksAfterEdit(H, "") case *hyphae.MediaHypha: oldText, err := FetchTextFile(h) if err != nil { diff --git a/user/user.go b/user/user.go index 26b0ffe..fe35bf1 100644 --- a/user/user.go +++ b/user/user.go @@ -31,6 +31,10 @@ type User struct { // Route — Right (more is more right) var minimalRights = map[string]int{ + "text": 0, + "backlinks": 0, + "history": 0, + "attachment": 1, "edit": 1, "upload-binary": 1, "upload-text": 1, diff --git a/views/nav.qtpl b/views/nav.qtpl index 5bf2897..592d34f 100644 --- a/views/nav.qtpl +++ b/views/nav.qtpl @@ -24,7 +24,7 @@