Skip to content

Commit

Permalink
Lint fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
bengarrett committed Apr 22, 2024
1 parent 7bd3111 commit c2eff1c
Show file tree
Hide file tree
Showing 13 changed files with 277 additions and 261 deletions.
41 changes: 1 addition & 40 deletions handler/htmx/demozoo.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,44 +133,5 @@ func DemozooValid(c echo.Context, id int) (demozoo.Production, error) {
// the Demozoo production ID. If the Demozoo production ID is already in
// use, an error message is returned.
func DemozooSubmit(c echo.Context, logger *zap.SugaredLogger) error {
if logger == nil {
return c.String(http.StatusInternalServerError,
"error, demozoo submit logger is nil")
}

sid := c.Param("id")
id, err := strconv.ParseUint(sid, 10, 64)
if err != nil {
return c.String(http.StatusNotAcceptable,
"The Demozoo production ID must be a numeric value, "+sid)
}
if id < 1 || id > demozoo.Sanity {
return c.String(http.StatusNotAcceptable,
"The Demozoo production ID is invalid, "+sid)
}

db, err := postgres.ConnectDB()
if err != nil {
return ErrDB
}
defer db.Close()
ctx := context.Background()

if exist, err := model.ExistDemozooFile(ctx, db, int64(id)); err != nil {
return c.String(http.StatusServiceUnavailable,
"error, the database query failed")
} else if exist {
return c.String(http.StatusForbidden,
"error, the demozoo key is already in use")
}

key, err := model.InsertDemozooFile(ctx, db, int64(id))
if err != nil || key == 0 {
logger.Error(err, id)
return c.String(http.StatusServiceUnavailable,
"error, the database insert failed")
}

html := fmt.Sprintf("Thanks for the submission of Demozoo production: %d", id)
return c.HTML(http.StatusOK, html)
return submit(c, logger, "demozoo")
}
14 changes: 12 additions & 2 deletions handler/htmx/htmx.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ func Routes(e *echo.Echo, logger *zap.SugaredLogger, prod bool) *echo.Echo {
}

func releaser1(c echo.Context) string {
lookups := []string{"uploader-intro-releaser1", "uploader-text-releaser1", "uploader-image-releaser1", "uploader-advanced-releaser1"}
lookups := []string{
"uploader-intro-releaser1",
"uploader-text-releaser1",
"uploader-image-releaser1",
"uploader-advanced-releaser1",
}
for _, lookup := range lookups {
if val := c.FormValue(lookup); val != "" {
return val
Expand All @@ -92,7 +97,12 @@ func releaser1(c echo.Context) string {
}

func releaser2(c echo.Context) string {
lookups := []string{"uploader-intro-releaser2", "uploader-text-releaser2", "uploader-image-releaser2", "uploader-advanced-releaser2"}
lookups := []string{
"uploader-intro-releaser2",
"uploader-text-releaser2",
"uploader-image-releaser2",
"uploader-advanced-releaser2",
}
for _, lookup := range lookups {
if val := c.FormValue(lookup); val != "" {
return val
Expand Down
54 changes: 9 additions & 45 deletions handler/htmx/pouet.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,17 @@ func PouetProd(c echo.Context) error {
if prod.Platfs.String() != "" {
info = append(info, "for", prod.Platfs.String())
}
return c.HTML(http.StatusOK, htmler(id, info...))
}

html := `<div class="d-grid gap-2">`
html += fmt.Sprintf(`<button type="button" class="btn btn-outline-success" `+
func htmler(id int, info ...string) string {
s := `<div class="d-grid gap-2">`
s += fmt.Sprintf(`<button type="button" class="btn btn-outline-success" `+
`hx-post="/pouet/production/submit/%d" hx-target="#pouet-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, " "))
return c.HTML(http.StatusOK, html)
s += `</div>`
s += fmt.Sprintf(`<p class="mt-3">%s</p>`, strings.Join(info, " "))
return s
}

// PouetValid fetches the first usable download link from the Pouet API.
Expand Down Expand Up @@ -150,44 +153,5 @@ func PouetValid(c echo.Context, id int) (pouet.Response, error) {
// the Pouet production ID. If the Pouet production ID is already in
// use, an error message is returned.
func PouetSubmit(c echo.Context, logger *zap.SugaredLogger) error {
if logger == nil {
return c.String(http.StatusInternalServerError,
"error, pouet submit logger is nil")
}

sid := c.Param("id")
id, err := strconv.ParseUint(sid, 10, 64)
if err != nil {
return c.String(http.StatusNotAcceptable,
"The Pouet production ID must be a numeric value, "+sid)
}
if id < 1 || id > pouet.Sanity {
return c.String(http.StatusNotAcceptable,
"The Pouet production ID is invalid, "+sid)
}

db, err := postgres.ConnectDB()
if err != nil {
return ErrDB
}
defer db.Close()
ctx := context.Background()

if exist, err := model.ExistPouetFile(ctx, db, int64(id)); err != nil {
return c.String(http.StatusServiceUnavailable,
"error, the database query failed")
} else if exist {
return c.String(http.StatusForbidden,
"error, the pouet key is already in use")
}

key, err := model.InsertPouetFile(ctx, db, int64(id))
if err != nil || key == 0 {
logger.Error(err, id)
return c.String(http.StatusServiceUnavailable,
"error, the database insert failed")
}

html := fmt.Sprintf("Thanks for the submission of Pouet production: %d", id)
return c.HTML(http.StatusOK, html)
return submit(c, logger, "pouet")
}
2 changes: 1 addition & 1 deletion handler/htmx/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,6 @@ func Classification(c echo.Context, logger *zap.SugaredLogger) error {
return c.String(http.StatusServiceUnavailable,
"cannot count the classification")
}
s = fmt.Sprintf("%s, %d existing artefacts", s, count)
s = fmt.Sprintf("%s, %d existing artifacts", s, count)
return c.HTML(http.StatusOK, s)
}
Loading

0 comments on commit c2eff1c

Please sign in to comment.