54 lines
1.8 KiB
Go
54 lines
1.8 KiB
Go
package searchapi
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"videoweb/app/api/proto"
|
|
"videoweb/app/service/configser"
|
|
"videoweb/app/service/searchser"
|
|
"videoweb/app/service/translationser"
|
|
"videoweb/pub/common"
|
|
"videoweb/pub/common/srvdef"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// SearchApi 搜索
|
|
// @Tags 搜索
|
|
// @Summary 搜索
|
|
// @Description 搜索视频和短剧,省略 type 查询全部,type 为 0 查询视频,为 6 查询短剧,sort 支持 default/hot/new
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param title query string false "搜索关键词"
|
|
// @Param page query int false "页码,默认1"
|
|
// @Param type query int false "媒体类型,不传=全部,0=视频,6=短剧"
|
|
// @Param sort query string false "排序方式 default/hot/new,默认default"
|
|
// @Success 200 {object} proto.SearchResp "成功"
|
|
// @Failure 400 {string} string "获取失败的返回结果"
|
|
// @Router /search [get]
|
|
func SearchApi(c *gin.Context) {
|
|
title := c.Query("title")
|
|
pageStr := c.DefaultQuery("page", "1")
|
|
sort := c.DefaultQuery("sort", string(proto.SearchSortTypeDefault))
|
|
mediaType := int64(-1)
|
|
if typeStr, ok := c.GetQuery("type"); ok {
|
|
var err error
|
|
mediaType, err = strconv.ParseInt(typeStr, 10, 64)
|
|
if err != nil || (mediaType != 0 && mediaType != 6) {
|
|
common.ServerJSON(c, srvdef.ErrParamError, "type 只支持 0 或 6")
|
|
return
|
|
}
|
|
}
|
|
page, err := strconv.ParseInt(pageStr, 10, 64)
|
|
if err != nil || page < 1 {
|
|
page = 1
|
|
}
|
|
data := searchser.Search(c, title, mediaType, page, sort)
|
|
data.Path = c.Request.URL.Path
|
|
data.CompletePath = fmt.Sprintf("/search")
|
|
data.Advitise = configser.GetAdvitise()
|
|
data.BottonTranslations = translationser.GetTranslationBottomList()
|
|
data.Translations = translationser.GetTranslationData()
|
|
common.JSONWriterCache(c, srvdef.Success, data)
|
|
}
|