Files
artalkjs/server/handler/pv.go
T
qwqcode 9a680f0ef8 docs: add open api (#360)
* chore(api): add comment for open api

Signed-off-by: qwqcode <qwqcode@gmail.com>

* docs: add open api generation support

Signed-off-by: qwqcode <qwqcode@gmail.com>

---------

Signed-off-by: qwqcode <qwqcode@gmail.com>
2023-01-29 00:13:19 +08:00

54 lines
1.3 KiB
Go

package handler
import (
"github.com/ArtalkJS/Artalk/internal/query"
"github.com/ArtalkJS/Artalk/server/common"
"github.com/gofiber/fiber/v2"
)
type ParamsPV struct {
PageKey string `form:"page_key" validate:"required"`
PageTitle string `form:"page_title"`
SiteName string
SiteID uint
SiteAll bool
}
type ResponsePV struct {
PV int `json:"pv"`
}
// @Summary Page View
// @Description Log and get the number of page views
// @Tags PV
// @Param page_key formData string true "the page key"
// @Param page_title formData string false "the page title"
// @Param site_name formData string false "the site name of your content scope"
// @Success 200 {object} common.JSONResult{data=ResponsePV}
// @Router /pv [post]
func PV(router fiber.Router) {
router.Post("/pv", func(c *fiber.Ctx) error {
var p ParamsPV
if isOK, resp := common.ParamsDecode(c, &p); !isOK {
return resp
}
// use site
common.UseSite(c, &p.SiteName, &p.SiteID, &p.SiteAll)
// find page
page := query.FindCreatePage(p.PageKey, p.PageTitle, p.SiteName)
// ip := c.RealIP()
// ua := c.Request().UserAgent()
page.PV++
query.UpdatePage(&page)
return common.RespData(c, ResponsePV{
PV: page.PV,
})
})
}