summaryrefslogtreecommitdiff
path: root/internal/router/api-v1-like.go
diff options
from:
to:
context:
space:
mode:
Diffstat (limited to 'internal/router/api-v1-like.go')
-rw-r--r--internal/router/api-v1-like.go15
1 files changed, 10 insertions, 5 deletions
diff --git a/internal/router/api-v1-like.go b/internal/router/api-v1-like.go
index 1732c77..327dafa 100644
--- a/internal/router/api-v1-like.go
+++ b/internal/router/api-v1-like.go
@@ -8,6 +8,7 @@ import (
"strings"
"github.com/SayaAndy/saya-today-web/internal/b2"
+ "github.com/SayaAndy/saya-today-web/locale"
"github.com/gofiber/fiber/v2"
)
@@ -15,7 +16,7 @@ func init() {
tm.Add("blog-page-like-button", "views/partials/blog-page-like-button.html")
}
-func Api_V1_Like_Put(b2 *b2.B2Client) func(c *fiber.Ctx) error {
+func Api_V1_Like_Put(l map[string]*locale.LocaleConfig, b2 *b2.B2Client) func(c *fiber.Ctx) error {
return func(c *fiber.Ctx) error {
c.Set(fiber.HeaderContentType, fiber.MIMETextPlainCharsetUTF8)
@@ -41,12 +42,12 @@ func Api_V1_Like_Put(b2 *b2.B2Client) func(c *fiber.Ctx) error {
return c.Status(fiber.ErrNotFound.Code).SendString(fmt.Sprintf("server did not find '%s' article", pageLink))
}
- ip := c.IP()
newLikeStatus, err := strconv.ParseBool(c.FormValue("like", "true"))
if err != nil {
return c.Status(fiber.ErrBadRequest.Code).SendString("invalid 'like' value")
}
+ ip := c.IP()
if newLikeStatus {
CCache.LikeOn(ip, page)
} else {
@@ -56,7 +57,9 @@ func Api_V1_Like_Put(b2 *b2.B2Client) func(c *fiber.Ctx) error {
slog.Debug("someone pressed the like button!", slog.String("ip", ip), slog.String("page", page), slog.String("new_like_status", fmt.Sprint(newLikeStatus)))
if c.Get("HX-Request", "false") == "true" {
content, err := tm.Render("blog-page-like-button", fiber.Map{
- "Liked": newLikeStatus,
+ "L": l[lang],
+ "Liked": newLikeStatus,
+ "LikedCount": CCache.GetLikeCount(page),
})
if err != nil {
slog.Warn("failed to generate div", slog.String("path", path), slog.String("error", err.Error()))
@@ -70,7 +73,7 @@ func Api_V1_Like_Put(b2 *b2.B2Client) func(c *fiber.Ctx) error {
}
}
-func Api_V1_Like_Get(b2 *b2.B2Client) func(c *fiber.Ctx) error {
+func Api_V1_Like_Get(l map[string]*locale.LocaleConfig, b2 *b2.B2Client) func(c *fiber.Ctx) error {
return func(c *fiber.Ctx) error {
c.Set(fiber.HeaderContentType, fiber.MIMETextPlainCharsetUTF8)
@@ -102,7 +105,9 @@ func Api_V1_Like_Get(b2 *b2.B2Client) func(c *fiber.Ctx) error {
slog.Debug("someone requested the like status!", slog.String("ip", ip), slog.String("page", page), slog.Bool("like_status", likeStatus))
if c.Get("HX-Request", "false") == "true" {
content, err := tm.Render("blog-page-like-button", fiber.Map{
- "Liked": likeStatus,
+ "L": l[lang],
+ "Liked": likeStatus,
+ "LikedCount": CCache.GetLikeCount(page),
})
if err != nil {
slog.Warn("failed to generate div", slog.String("path", path), slog.String("error", err.Error()))