Skip to content

Commit

Permalink
limit livecomments
Browse files Browse the repository at this point in the history
  • Loading branch information
tukeJonny committed Nov 2, 2023
1 parent cdaa61b commit ef44f68
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 11 additions & 1 deletion webapp/go/livecomment_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"database/sql"
"encoding/json"
"errors"
"fmt"
"net/http"
"strconv"
"time"
Expand Down Expand Up @@ -83,8 +84,17 @@ func getLivecommentsHandler(c echo.Context) error {
}
defer tx.Rollback()

query := "SELECT * FROM livecomments WHERE livestream_id = ?"
if c.QueryParam("limit") != "" {
limit, err := strconv.Atoi(c.QueryParam("limit"))
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
}
query += fmt.Sprintf(" LIMIT %d", limit)
}

livecommentModels := []LivecommentModel{}
err = tx.SelectContext(ctx, &livecommentModels, "SELECT * FROM livecomments WHERE livestream_id = ?", livestreamID)
err = tx.SelectContext(ctx, &livecommentModels, query, livestreamID)
if errors.Is(err, sql.ErrNoRows) {
return echo.NewHTTPError(http.StatusNotFound, err.Error())
}
Expand Down
4 changes: 4 additions & 0 deletions webapp/go/user_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ func postIconHandler(c echo.Context) error {
}
defer tx.Rollback()

if _, err := tx.ExecContext(ctx, "DELETE FROM icons WHERE user_id = ?", userID); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}

rs, err := tx.ExecContext(ctx, "INSERT INTO icons (user_id, image) VALUES (?, ?)", userID, req.Image)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
Expand Down

0 comments on commit ef44f68

Please sign in to comment.