From 8466e2d6133c172b30fc51d2170e40a8ef949338 Mon Sep 17 00:00:00 2001 From: Timur Ismagilov Date: Sat, 7 Sep 2024 22:53:22 +0300 Subject: [PATCH] Reformat more imports --- internal/shroom/can.go | 14 +++++------ internal/shroom/delete.go | 13 +++++----- internal/shroom/header_links.go | 18 +++++++------- internal/shroom/log.go | 3 ++- internal/shroom/rename.go | 42 ++++++++++++++++----------------- internal/shroom/search.go | 2 +- internal/shroom/unattach.go | 10 ++++---- internal/user/files.go | 2 +- internal/user/net.go | 6 ++--- internal/user/user.go | 3 ++- 10 files changed, 59 insertions(+), 54 deletions(-) diff --git a/internal/shroom/can.go b/internal/shroom/can.go index c9d1f3d..8a4ccc3 100644 --- a/internal/shroom/can.go +++ b/internal/shroom/can.go @@ -2,23 +2,23 @@ package shroom import ( "errors" - hyphae2 "github.com/bouncepaw/mycorrhiza/internal/hyphae" - "github.com/bouncepaw/mycorrhiza/internal/user" + "github.com/bouncepaw/mycorrhiza/internal/hyphae" + "github.com/bouncepaw/mycorrhiza/internal/user" "github.com/bouncepaw/mycorrhiza/l18n" ) // TODO: get rid of this abomination func canFactory( - rejectLogger func(hyphae2.Hypha, *user.User, string), + rejectLogger func(hyphae.Hypha, *user.User, string), action string, - dispatcher func(hyphae2.Hypha, *user.User, *l18n.Localizer) (string, string), + dispatcher func(hyphae.Hypha, *user.User, *l18n.Localizer) (string, string), noRightsMsg string, notExistsMsg string, mustExist bool, -) func(*user.User, hyphae2.Hypha, *l18n.Localizer) error { - return func(u *user.User, h hyphae2.Hypha, lc *l18n.Localizer) error { +) func(*user.User, hyphae.Hypha, *l18n.Localizer) error { + return func(u *user.User, h hyphae.Hypha, lc *l18n.Localizer) error { if !u.CanProceed(action) { rejectLogger(h, u, "no rights") return errors.New(noRightsMsg) @@ -26,7 +26,7 @@ func canFactory( if mustExist { switch h.(type) { - case *hyphae2.EmptyHypha: + case *hyphae.EmptyHypha: rejectLogger(h, u, "does not exist") return errors.New(notExistsMsg) } diff --git a/internal/shroom/delete.go b/internal/shroom/delete.go index 701fd0c..f07df9d 100644 --- a/internal/shroom/delete.go +++ b/internal/shroom/delete.go @@ -2,29 +2,30 @@ package shroom import ( "fmt" + "github.com/bouncepaw/mycorrhiza/history" "github.com/bouncepaw/mycorrhiza/internal/backlinks" "github.com/bouncepaw/mycorrhiza/internal/categories" - hyphae2 "github.com/bouncepaw/mycorrhiza/internal/hyphae" + "github.com/bouncepaw/mycorrhiza/internal/hyphae" "github.com/bouncepaw/mycorrhiza/internal/user" ) // Delete deletes the hypha and makes a history record about that. -func Delete(u *user.User, h hyphae2.ExistingHypha) error { +func Delete(u *user.User, h hyphae.ExistingHypha) error { hop := history. Operation(history.TypeDeleteHypha). WithMsg(fmt.Sprintf("Delete ā€˜%s’", h.CanonicalName())). WithUser(u) - originalText, _ := hyphae2.FetchMycomarkupFile(h) + originalText, _ := hyphae.FetchMycomarkupFile(h) switch h := h.(type) { - case *hyphae2.MediaHypha: + case *hyphae.MediaHypha: if h.HasTextFile() { hop.WithFilesRemoved(h.MediaFilePath(), h.TextFilePath()) } else { hop.WithFilesRemoved(h.MediaFilePath()) } - case *hyphae2.TextualHypha: + case *hyphae.TextualHypha: hop.WithFilesRemoved(h.TextFilePath()) } if hop.Apply().HasErrors() { @@ -32,6 +33,6 @@ func Delete(u *user.User, h hyphae2.ExistingHypha) error { } backlinks.UpdateBacklinksAfterDelete(h, originalText) categories.RemoveHyphaFromAllCategories(h.CanonicalName()) - hyphae2.DeleteHypha(h) + hyphae.DeleteHypha(h) return nil } diff --git a/internal/shroom/header_links.go b/internal/shroom/header_links.go index dd3ff1b..af28f75 100644 --- a/internal/shroom/header_links.go +++ b/internal/shroom/header_links.go @@ -1,22 +1,24 @@ package shroom import ( + "os" + + "github.com/bouncepaw/mycorrhiza/internal/cfg" + "github.com/bouncepaw/mycorrhiza/internal/hyphae" + "github.com/bouncepaw/mycorrhiza/mycoopts" + "github.com/bouncepaw/mycorrhiza/web/viewutil" + "git.sr.ht/~bouncepaw/mycomarkup/v5" "git.sr.ht/~bouncepaw/mycomarkup/v5/blocks" "git.sr.ht/~bouncepaw/mycomarkup/v5/mycocontext" - "github.com/bouncepaw/mycorrhiza/internal/cfg" - hyphae2 "github.com/bouncepaw/mycorrhiza/internal/hyphae" - "github.com/bouncepaw/mycorrhiza/mycoopts" - "github.com/bouncepaw/mycorrhiza/web/viewutil" - "os" ) // SetHeaderLinks initializes header links by reading the configured hypha, if there is any, or resorting to default values. func SetHeaderLinks() { - switch userLinksHypha := hyphae2.ByName(cfg.HeaderLinksHypha).(type) { - case *hyphae2.EmptyHypha: + switch userLinksHypha := hyphae.ByName(cfg.HeaderLinksHypha).(type) { + case *hyphae.EmptyHypha: setDefaultHeaderLinks() - case hyphae2.ExistingHypha: + case hyphae.ExistingHypha: contents, err := os.ReadFile(userLinksHypha.TextFilePath()) if err != nil || len(contents) == 0 { setDefaultHeaderLinks() diff --git a/internal/shroom/log.go b/internal/shroom/log.go index 2aef825..14a2f07 100644 --- a/internal/shroom/log.go +++ b/internal/shroom/log.go @@ -1,9 +1,10 @@ package shroom import ( + "log" + "github.com/bouncepaw/mycorrhiza/internal/hyphae" "github.com/bouncepaw/mycorrhiza/internal/user" - "log" ) func rejectRenameLog(h hyphae.Hypha, u *user.User, errmsg string) { diff --git a/internal/shroom/rename.go b/internal/shroom/rename.go index 3aeeeb7..6150c92 100644 --- a/internal/shroom/rename.go +++ b/internal/shroom/rename.go @@ -3,36 +3,36 @@ package shroom import ( "errors" "fmt" - "github.com/bouncepaw/mycorrhiza/internal/backlinks" - "github.com/bouncepaw/mycorrhiza/internal/categories" - "github.com/bouncepaw/mycorrhiza/internal/cfg" - "github.com/bouncepaw/mycorrhiza/internal/files" - hyphae2 "github.com/bouncepaw/mycorrhiza/internal/hyphae" - "github.com/bouncepaw/mycorrhiza/internal/user" "path" "path/filepath" "regexp" "strings" "github.com/bouncepaw/mycorrhiza/history" + "github.com/bouncepaw/mycorrhiza/internal/backlinks" + "github.com/bouncepaw/mycorrhiza/internal/categories" + "github.com/bouncepaw/mycorrhiza/internal/cfg" + "github.com/bouncepaw/mycorrhiza/internal/files" + "github.com/bouncepaw/mycorrhiza/internal/hyphae" + "github.com/bouncepaw/mycorrhiza/internal/user" "github.com/bouncepaw/mycorrhiza/util" ) // Rename renames the old hypha to the new name and makes a history record about that. Call if and only if the user has the permission to rename. -func Rename(oldHypha hyphae2.ExistingHypha, newName string, recursive bool, leaveRedirections bool, u *user.User) error { +func Rename(oldHypha hyphae.ExistingHypha, newName string, recursive bool, leaveRedirections bool, u *user.User) error { // * bouncepaw hates this function and related renaming functions if newName == "" { rejectRenameLog(oldHypha, u, "no new name given") return errors.New("ui.rename_noname_tip") } - if !hyphae2.IsValidName(newName) { + if !hyphae.IsValidName(newName) { rejectRenameLog(oldHypha, u, fmt.Sprintf("new name ā€˜%s’ invalid", newName)) return errors.New("ui.rename_badname_tip") // FIXME: There is a bug related to this. } - switch targetHypha := hyphae2.ByName(newName); targetHypha.(type) { - case hyphae2.ExistingHypha: + switch targetHypha := hyphae.ByName(newName); targetHypha.(type) { + case hyphae.ExistingHypha: if targetHypha.CanonicalName() == oldHypha.CanonicalName() { return nil } @@ -81,7 +81,7 @@ func Rename(oldHypha hyphae2.ExistingHypha, newName string, recursive bool, leav oldName = h.CanonicalName() newName = re.ReplaceAllString(oldName, newName) ) - hyphae2.RenameHyphaTo(h, newName, replaceName) + hyphae.RenameHyphaTo(h, newName, replaceName) backlinks.UpdateBacklinksAfterRename(h, oldName) categories.RenameHyphaInAllCategories(oldName, newName) if leaveRedirections { @@ -104,12 +104,12 @@ const redirectionTemplate = `=> %[1]s | šŸ‘ļøāž”ļø %[2]s func leaveRedirection(oldName, newName string, hop *history.Op) error { var ( text = fmt.Sprintf(redirectionTemplate, newName, util.BeautifulName(newName)) - emptyHypha = hyphae2.ByName(oldName) + emptyHypha = hyphae.ByName(oldName) ) switch emptyHypha := emptyHypha.(type) { - case *hyphae2.EmptyHypha: - h := hyphae2.ExtendEmptyToTextual(emptyHypha, filepath.Join(files.HyphaeDir(), oldName+".myco")) - hyphae2.Insert(h) + case *hyphae.EmptyHypha: + h := hyphae.ExtendEmptyToTextual(emptyHypha, filepath.Join(files.HyphaeDir(), oldName+".myco")) + hyphae.Insert(h) categories.AddHyphaToCategory(oldName, cfg.RedirectionCategory) defer backlinks.UpdateBacklinksAfterEdit(h, "") return writeTextToDisk(h, []byte(text), hop) @@ -118,15 +118,15 @@ func leaveRedirection(oldName, newName string, hop *history.Op) error { } } -func findHyphaeToRename(superhypha hyphae2.ExistingHypha, recursive bool) []hyphae2.ExistingHypha { - hyphaList := []hyphae2.ExistingHypha{superhypha} +func findHyphaeToRename(superhypha hyphae.ExistingHypha, recursive bool) []hyphae.ExistingHypha { + hyphaList := []hyphae.ExistingHypha{superhypha} if recursive { - hyphaList = append(hyphaList, hyphae2.Subhyphae(superhypha)...) + hyphaList = append(hyphaList, hyphae.Subhyphae(superhypha)...) } return hyphaList } -func renamingPairs(hyphaeToRename []hyphae2.ExistingHypha, replaceName func(string) string) (map[string]string, error) { +func renamingPairs(hyphaeToRename []hyphae.ExistingHypha, replaceName func(string) string) (map[string]string, error) { var ( renameMap = make(map[string]string) newNames = make([]string, len(hyphaeToRename)) @@ -138,12 +138,12 @@ func renamingPairs(hyphaeToRename []hyphae2.ExistingHypha, replaceName func(stri renameMap[h.TextFilePath()] = replaceName(h.TextFilePath()) } switch h := h.(type) { - case *hyphae2.MediaHypha: + case *hyphae.MediaHypha: renameMap[h.MediaFilePath()] = replaceName(h.MediaFilePath()) } h.Unlock() } - if firstFailure, ok := hyphae2.AreFreeNames(newNames...); !ok { + if firstFailure, ok := hyphae.AreFreeNames(newNames...); !ok { return nil, errors.New("Hypha " + firstFailure + " already exists") } return renameMap, nil diff --git a/internal/shroom/search.go b/internal/shroom/search.go index 57efad0..666752d 100644 --- a/internal/shroom/search.go +++ b/internal/shroom/search.go @@ -1,9 +1,9 @@ package shroom import ( - "github.com/bouncepaw/mycorrhiza/internal/hyphae" "strings" + "github.com/bouncepaw/mycorrhiza/internal/hyphae" "github.com/bouncepaw/mycorrhiza/util" ) diff --git a/internal/shroom/unattach.go b/internal/shroom/unattach.go index 74b76b4..613cae3 100644 --- a/internal/shroom/unattach.go +++ b/internal/shroom/unattach.go @@ -2,14 +2,14 @@ package shroom import ( "fmt" - hyphae2 "github.com/bouncepaw/mycorrhiza/internal/hyphae" - "github.com/bouncepaw/mycorrhiza/internal/user" "github.com/bouncepaw/mycorrhiza/history" + "github.com/bouncepaw/mycorrhiza/internal/hyphae" + "github.com/bouncepaw/mycorrhiza/internal/user" ) // RemoveMedia removes media from the media hypha and makes a history record about that. If it only had media, the hypha will be deleted. If it also had text, the hypha will become textual. -func RemoveMedia(u *user.User, h *hyphae2.MediaHypha) error { +func RemoveMedia(u *user.User, h *hyphae.MediaHypha) error { hop := history. Operation(history.TypeRemoveMedia). WithFilesRemoved(h.MediaFilePath()). @@ -24,9 +24,9 @@ func RemoveMedia(u *user.User, h *hyphae2.MediaHypha) error { } if h.HasTextFile() { - hyphae2.Insert(hyphae2.ShrinkMediaToTextual(h)) + hyphae.Insert(hyphae.ShrinkMediaToTextual(h)) } else { - hyphae2.DeleteHypha(h) + hyphae.DeleteHypha(h) } return nil } diff --git a/internal/user/files.go b/internal/user/files.go index d48d8a9..c77caa0 100644 --- a/internal/user/files.go +++ b/internal/user/files.go @@ -3,10 +3,10 @@ package user import ( "encoding/json" "errors" - "github.com/bouncepaw/mycorrhiza/internal/cfg" "log" "os" + "github.com/bouncepaw/mycorrhiza/internal/cfg" "github.com/bouncepaw/mycorrhiza/internal/files" "github.com/bouncepaw/mycorrhiza/util" ) diff --git a/internal/user/net.go b/internal/user/net.go index 00f60c2..29eec3c 100644 --- a/internal/user/net.go +++ b/internal/user/net.go @@ -6,16 +6,16 @@ import ( "encoding/hex" "errors" "fmt" - "github.com/bouncepaw/mycorrhiza/internal/cfg" "log" "net/http" "sort" "strings" "time" - "golang.org/x/crypto/bcrypt" - + "github.com/bouncepaw/mycorrhiza/internal/cfg" "github.com/bouncepaw/mycorrhiza/util" + + "golang.org/x/crypto/bcrypt" ) // CanProceed returns `true` if the user in `rq` has enough rights to access `route`. diff --git a/internal/user/user.go b/internal/user/user.go index 6aa500a..eec2ff7 100644 --- a/internal/user/user.go +++ b/internal/user/user.go @@ -2,12 +2,13 @@ package user import ( "fmt" - "github.com/bouncepaw/mycorrhiza/internal/cfg" "net/http" "strings" "sync" "time" + "github.com/bouncepaw/mycorrhiza/internal/cfg" + "golang.org/x/crypto/bcrypt" )