diff --git a/handler/app/context.go b/handler/app/context.go index e40137c3..8a91001e 100644 --- a/handler/app/context.go +++ b/handler/app/context.go @@ -16,7 +16,6 @@ import ( "github.com/Defacto2/releaser" "github.com/Defacto2/releaser/initialism" - namer "github.com/Defacto2/releaser/name" "github.com/Defacto2/server/handler/download" "github.com/Defacto2/server/handler/sess" "github.com/Defacto2/server/internal/archive" @@ -1030,22 +1029,6 @@ func PostName(logr *zap.SugaredLogger, c echo.Context, mode FileSearch) error { return nil } -// PostReleaser is the handler for the releaser search form post page. -func PostReleaser(logr *zap.SugaredLogger, c echo.Context) error { - const name = "searchList" - if logr == nil { - return InternalErr(logr, c, name, ErrZap) - } - input := c.FormValue("releaser-data-list") - val := helper.TrimRoundBraket(input) - slug := helper.Slug(val) - if slug == "" { - return SearchReleaser(logr, c) - } - // note, the redirect to a GET only works with 301 and 404 status codes. - return c.Redirect(http.StatusMovedPermanently, "/g/"+slug) -} - // PouetCache parses the cached data for the Pouet production votes. // If the cache is valid it is returned as JSON response. // If the cache is invalid or corrupt an error will be returned @@ -1711,27 +1694,9 @@ func SearchFile(logr *zap.SugaredLogger, c echo.Context) error { return nil } -// SearchReleaserX is the handler for the Releaser Search page. -func SearchReleaserX(logr *zap.SugaredLogger, c echo.Context) error { - const title, name = "Search for releasers", "searchHtmx" - if logr == nil { - return InternalErr(logr, c, name, ErrZap) - } - data := empty(c) - data["description"] = "Search form to discover releasers." - data["logo"] = title - data["title"] = title - data["info"] = "search for a group, initialism, magazine, board, or site" - err := c.Render(http.StatusOK, name, data) - if err != nil { - return InternalErr(logr, c, name, err) - } - return nil -} - // SearchReleaser is the handler for the Releaser Search page. func SearchReleaser(logr *zap.SugaredLogger, c echo.Context) error { - const title, name = "Search for releasers", "searchList" + const title, name = "Search for releasers", "searchHtmx" if logr == nil { return InternalErr(logr, c, name, ErrZap) } @@ -1740,32 +1705,7 @@ func SearchReleaser(logr *zap.SugaredLogger, c echo.Context) error { data["logo"] = title data["title"] = title data["info"] = "search for a group, initialism, magazine, board, or site" - ctx := context.Background() - db, err := postgres.ConnectDB() - if err != nil { - return DatabaseErr(logr, c, name, err) - } - defer db.Close() - x := model.ReleaserNames{} - if err := x.List(ctx, db); err != nil { - return DatabaseErr(logr, c, name, err) - } - s := make([]string, len(x)) - for i, v := range x { - id := strings.TrimSpace(v.Name) - slug := helper.Slug(id) - // use namer.Humanized instead of the releaser.link func as it is far more performant - name, _ := namer.Humanize(namer.Path(slug)) - ism := initialism.Initialism(initialism.Path(slug)) - opt := name - if len(ism) > 0 { - opt = fmt.Sprintf("%s (%s)", name, strings.Join(ism, ", ")) - } - s[i] = opt - } - data["releasers"] = s - - err = c.Render(http.StatusOK, name, data) + err := c.Render(http.StatusOK, name, data) if err != nil { return InternalErr(logr, c, name, err) } diff --git a/handler/htmx/htmx.go b/handler/htmx/htmx.go index 6c41050f..aa566171 100644 --- a/handler/htmx/htmx.go +++ b/handler/htmx/htmx.go @@ -22,7 +22,7 @@ import ( // Routes for the /htmx sub-route group that returns HTML fragments // using the htmx library for AJAX responses. func Routes(logr *zap.SugaredLogger, e *echo.Echo) *echo.Echo { - e.POST("/search/releaser-x", func(x echo.Context) error { + e.POST("/search/releaser", func(x echo.Context) error { return PostReleaser(logr, x) }) return e @@ -34,7 +34,7 @@ func GlobTo(name string) string { return strings.Join([]string{"view", "htmx", name}, "/") } -// PostReleaser is a handler for the /search/releaser-x route. +// PostReleaser is a handler for the /search/releaser route. func PostReleaser(logr *zap.SugaredLogger, c echo.Context) error { const maxResults = 14 ctx := context.Background() diff --git a/handler/router.go b/handler/router.go index 05487408..c2ed7123 100644 --- a/handler/router.go +++ b/handler/router.go @@ -10,6 +10,7 @@ import ( "github.com/Defacto2/releaser" "github.com/Defacto2/server/handler/app" + "github.com/Defacto2/server/handler/htmx" "github.com/Defacto2/server/internal/config" "github.com/Defacto2/server/internal/helper" "github.com/gorilla/sessions" @@ -248,9 +249,6 @@ func (c Configuration) Routes(e *echo.Echo, public embed.FS) (*echo.Echo, error) search.GET("/releaser", func(x echo.Context) error { return app.SearchReleaser(logr, x) }) - search.GET("/releaser-x", func(x echo.Context) error { - return app.SearchReleaserX(logr, x) - }) search.GET("/result", func(x echo.Context) error { // this legacy get result should be kept for (osx.xml) opensearch compatibility // and to keep possible backwards compatibility with third party site links. @@ -265,7 +263,7 @@ func (c Configuration) Routes(e *echo.Echo, public embed.FS) (*echo.Echo, error) return app.PostFilename(logr, x) }) search.POST("/releaser", func(x echo.Context) error { - return app.PostReleaser(logr, x) + return htmx.PostReleaser(logr, x) }) // Uploader for anonymous client uploads diff --git a/view/app/layout.tmpl b/view/app/layout.tmpl index 41be3a39..93d2cfcd 100644 --- a/view/app/layout.tmpl +++ b/view/app/layout.tmpl @@ -176,7 +176,6 @@ Search