🎨新增每日一言
This commit is contained in:
parent
c1d696ac19
commit
8f28f790e0
@ -7,6 +7,7 @@ import (
|
|||||||
"wireguard-ui/http/response"
|
"wireguard-ui/http/response"
|
||||||
"wireguard-ui/http/vo"
|
"wireguard-ui/http/vo"
|
||||||
"wireguard-ui/service"
|
"wireguard-ui/service"
|
||||||
|
"wireguard-ui/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DashboardApi struct{}
|
type DashboardApi struct{}
|
||||||
@ -38,3 +39,16 @@ func (DashboardApi) List(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
response.R(c).Paginate(data, total, p.Current, p.Size)
|
response.R(c).Paginate(data, total, p.Current, p.Size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DailyPoetry
|
||||||
|
// @description: 每日诗词
|
||||||
|
// @receiver DashboardApi
|
||||||
|
// @param c
|
||||||
|
func (DashboardApi) DailyPoetry(c *gin.Context) {
|
||||||
|
data, err := utils.DailyPoetry().HitokotoPoetry()
|
||||||
|
if err != nil {
|
||||||
|
response.R(c).FailedWithError("获取失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.R(c).OkWithData(data)
|
||||||
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"wireguard-ui/component"
|
"wireguard-ui/component"
|
||||||
@ -40,7 +41,7 @@ func Authorization() gin.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 如果token的颁发者与请求的站点不一致那么就给它抬出去
|
// 如果token的颁发者与请求的站点不一致那么就给它抬出去
|
||||||
if userClaims.Issuer != utils.WebSite().GetHost(c.Request.Header.Get("Referer")) {
|
if !slices.Contains(strings.Split(userClaims.Issuer, ","), utils.WebSite().GetHost(c.Request.Header.Get("Referer"))) {
|
||||||
response.R(c).AuthorizationFailed("未登陆")
|
response.R(c).AuthorizationFailed("未登陆")
|
||||||
c.Abort()
|
c.Abort()
|
||||||
return
|
return
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
func DashboardApi(r *gin.RouterGroup) {
|
func DashboardApi(r *gin.RouterGroup) {
|
||||||
dashboard := r.Group("dashboard", middleware.Authorization(), middleware.RequestLog())
|
dashboard := r.Group("dashboard", middleware.Authorization(), middleware.RequestLog())
|
||||||
{
|
{
|
||||||
dashboard.GET("/request/list", api.Dashboard().List) // 请求日志
|
dashboard.GET("/request/list", api.Dashboard().List) // 请求日志
|
||||||
|
dashboard.GET("/daily-poetry", api.Dashboard().DailyPoetry) // 每日诗词
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
6
http/vo/daily_poetry.go
Normal file
6
http/vo/daily_poetry.go
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package vo
|
||||||
|
|
||||||
|
type Poetry struct {
|
||||||
|
Content string `json:"content"`
|
||||||
|
Author string `json:"author"`
|
||||||
|
}
|
44
utils/daily_poetry.go
Normal file
44
utils/daily_poetry.go
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
"wireguard-ui/global/client"
|
||||||
|
"wireguard-ui/http/vo"
|
||||||
|
)
|
||||||
|
|
||||||
|
type dailyPoetry struct{}
|
||||||
|
|
||||||
|
func DailyPoetry() dailyPoetry {
|
||||||
|
return dailyPoetry{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HitokotoPoetry
|
||||||
|
// @description: 获取每日一句【一言】
|
||||||
|
// @receiver dailyPoetry
|
||||||
|
// @return data
|
||||||
|
// @return err
|
||||||
|
func (dailyPoetry) HitokotoPoetry() (data *vo.Poetry, err error) {
|
||||||
|
req := client.HttpClient.R()
|
||||||
|
req.SetQueryParam("c", "h")
|
||||||
|
req.SetQueryParam("c", "i")
|
||||||
|
req.SetQueryParam("c", "k")
|
||||||
|
req.SetQueryParam("encode", "json")
|
||||||
|
req.SetQueryParam("charset", "utf-8")
|
||||||
|
|
||||||
|
response, err := req.Get("https://hitokoto.mrxqq.top")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
author := jsoniter.Get(response.Body(), "from_who").ToString()
|
||||||
|
if author == "" {
|
||||||
|
author = "佚名"
|
||||||
|
}
|
||||||
|
|
||||||
|
data = &vo.Poetry{
|
||||||
|
Content: jsoniter.Get(response.Body(), "hitokoto").ToString(),
|
||||||
|
Author: author,
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user