Skip to content

Commit

Permalink
Lint corrections.
Browse files Browse the repository at this point in the history
  • Loading branch information
bengarrett committed Apr 12, 2024
1 parent 739014a commit 9e7a264
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 157 deletions.
19 changes: 11 additions & 8 deletions handler/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,14 @@ func errVal(name string) template.HTML {
}

const (
attr = " attributions"
br = "<br>"
ul0 = "<ul>"
ul1 = "</ul>"
fzip = ".zip"
attr = " attributions"
br = "<br>"
div1 = "</div>"
sect0 = "<section>"
sect1 = "</section>"
ul0 = "<ul>"
ul1 = "</ul>"
fzip = ".zip"
)

// Caching are values that are used throughout the app or layouts.
Expand Down Expand Up @@ -795,7 +798,7 @@ func recordsSub1(uri string) string { //nolint:cyclop
// released the artifact. The content should be a list of files contained
// in the artifact.
//
// This is a port of the CFML function, variables.findTextfile found in File.cfc
// This is a port of the CFML function, variables.findTextfile found in File.cfc.
func ReadmeSuggest(filename, group string, content ...string) string {
finds := readmeFinds(content...)
if len(finds) == 1 {
Expand All @@ -816,9 +819,9 @@ func ReadmeSuggest(filename, group string, content ...string) string {
}
}
}
const matchFileId = "file_id.diz"
const matchFileID = "file_id.diz"
for _, name := range finds {
if strings.EqualFold(matchFileId, name) {
if strings.EqualFold(matchFileID, name) {
return name
}
}
Expand Down
160 changes: 29 additions & 131 deletions handler/app/milestone.go

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions handler/app/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (web Web) Screenshot(uuid, desc string) template.HTML {
elm += img(srcP, alt, class, "")
}
elm += "</picture>"
return template.HTML(elm)
return elm
}
if sizeJ > 0 {
return img(srcJ, alt, class, "")
Expand Down Expand Up @@ -439,14 +439,13 @@ func (web Web) Thumb(uuid, desc string, bottom bool) template.HTML {
"</picture>"
return template.HTML(elm)
}
elm := ""
if w {
return img(webp, alt, class, style)
}
if p {
return img(png, alt, class, style)
}
return template.HTML(elm)
return ""
}

// ThumbSample returns a HTML image tag for the given uuid.
Expand Down
3 changes: 2 additions & 1 deletion handler/html3/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ func getTags(s Sugared, g *echo.Group) *echo.Group {
return g
}

// custom404 is a custom 404 error handler for the website, "The page cannot be found."
// custom404 is a custom 404 error handler for the website,
// "The page cannot be found.".
func custom404(g *echo.Group) *echo.Group {
g.GET("/:uri", func(x echo.Context) error {
return echo.NewHTTPError(http.StatusNotFound,
Expand Down
3 changes: 2 additions & 1 deletion handler/htmx/demozoo.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ func DemozooProd(c echo.Context) error {
}
html := `<div class="d-grid gap-2">`
html += fmt.Sprintf(`<button type="button" class="btn btn-outline-success" `+
`hx-post="/demozoo/production/submit/%d" hx-target="#demozoo-submission-results" hx-trigger="click once delay:500ms" `+
`hx-post="/demozoo/production/submit/%d" `+
`hx-target="#demozoo-submission-results" hx-trigger="click once delay:500ms" `+
`autofocus>Submit ID %d</button>`, id, id)
html += `</div>`
html += fmt.Sprintf(`<p class="mt-3">%s</p>`, strings.Join(info, " "))
Expand Down
20 changes: 9 additions & 11 deletions handler/htmx/htmx.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,21 @@ var (
ErrRoutes = errors.New("echo instance is nil")
)

const rateLimit = 2

// Routes for the /htmx sub-route group that returns HTML fragments
// using the htmx library for AJAX responses.
func Routes(e *echo.Echo, logger *zap.SugaredLogger) *echo.Echo {
if e == nil {
panic(ErrRoutes)
}
submit := e.Group("",
middleware.RateLimiter(middleware.NewRateLimiterMemoryStore(2)))
submit.POST("/demozoo/production", func(c echo.Context) error {
return DemozooProd(c)
})
middleware.RateLimiter(middleware.NewRateLimiterMemoryStore(rateLimit)))
submit.POST("/demozoo/production", DemozooProd)
submit.POST("/demozoo/production/submit/:id", func(c echo.Context) error {
return DemozooSubmit(logger, c)
})
submit.POST("/pouet/production", func(c echo.Context) error {
return PouetProd(c)
})
submit.POST("/pouet/production", PouetProd)
submit.POST("/pouet/production/submit/:id", func(c echo.Context) error {
return PouetSubmit(logger, c)
})
Expand Down Expand Up @@ -100,8 +98,8 @@ func holder(c echo.Context, name string) error {
if exist, err := model.ExistsHash(ctx, db, sum); err != nil {
return err
} else if exist {
return c.HTML(http.StatusOK, fmt.Sprintf("<p>Thanks, but the chosen file already exists on Defacto2.</p>%s",
html.EscapeString(input.Filename)))
return c.HTML(http.StatusOK, "<p>Thanks, but the chosen file already exists on Defacto2.</p>"+
html.EscapeString(input.Filename))
}

// reopen the file
Expand Down Expand Up @@ -187,7 +185,7 @@ func TemplateFuncMap() template.FuncMap {
func Suggestion(name, initialism string, count any) string {
s := name
if initialism != "" {
s += fmt.Sprintf(", %s", initialism)
s += ", " + initialism
}
switch val := count.(type) {
case int, int8, int16, int32, int64,
Expand All @@ -200,7 +198,7 @@ func Suggestion(name, initialism string, count any) string {
}
s += ")"
default:
s += fmt.Sprintf("suggestion type error: %s", reflect.TypeOf(count).String())
s += "suggestion type error: " + reflect.TypeOf(count).String()
return s
}
return s
Expand Down
9 changes: 7 additions & 2 deletions handler/htmx/pouet.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,13 @@ func PouetValid(c echo.Context, id int) (pouet.Response, error) {
if link.Link == "" {
continue
}
switch strings.ToLower(link.Type) {
case "youtube":
if strings.Contains(link.Link, "youtube") {
continue
}
if strings.Contains(link.Link, "sourceforge") {
continue
}
if strings.Contains(link.Link, "github") {
continue
}
valid = link.Link
Expand Down

0 comments on commit 9e7a264

Please sign in to comment.