Reformat more imports

This commit is contained in:
Timur Ismagilov 2024-09-07 22:53:22 +03:00
parent b3626ee546
commit 8466e2d613
10 changed files with 59 additions and 54 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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