113 lines
3.3 KiB
Go
113 lines
3.3 KiB
Go
package home
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"strconv"
|
|
"videoweb/app/api/proto"
|
|
"videoweb/app/service/configser"
|
|
"videoweb/app/service/translationser"
|
|
"videoweb/pub/common"
|
|
"videoweb/pub/common/log"
|
|
"videoweb/pub/common/srvdef"
|
|
"videoweb/pub/models/richtextcontentmod"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
)
|
|
|
|
// VideoTagApi 标签搜索
|
|
// @Tags 标签搜索
|
|
// @Summary 标签搜索
|
|
// @Description 标签搜索
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param param body string true "参数列表"
|
|
// @Success 200 {object} proto.HomeHtmlData "成功"
|
|
// @Failure 400 {string} string "获取失败的返回结果"
|
|
// @Security ApiKeyAuth
|
|
// @Router /richtext/:id [get]
|
|
func RichtextApi(c *gin.Context) {
|
|
data := proto.RichTextHtmlData{
|
|
Path: c.Request.URL.Path,
|
|
Translations: translationser.GetTranslationData(),
|
|
BottonTranslations: translationser.GetTranslationBottomList(),
|
|
Config: configser.GetConfigInfo(),
|
|
Advitise: configser.GetAdvitise(),
|
|
}
|
|
richtextStr := c.Param("id")
|
|
richtextId, err := strconv.ParseInt(richtextStr, 10, 64)
|
|
if err != nil || richtextId < 1 {
|
|
common.ServerJSON(c, srvdef.NotFound, "")
|
|
return
|
|
}
|
|
richtextDate, serr := richtextData(c, richtextId)
|
|
if serr != nil {
|
|
common.ServerJSON(c, serr.Code, "richtext param error")
|
|
return
|
|
}
|
|
data.CompletePath = fmt.Sprintf("/richtext/%d", richtextId)
|
|
data.RichTextInfo = richtextDate
|
|
|
|
common.JSONWriterCache(c, srvdef.Success, data)
|
|
}
|
|
|
|
// PageNotFound 404
|
|
// @Tags 404
|
|
// @Summary 404
|
|
// @Description 404
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param param body string true "参数列表"
|
|
// @Success 200 {string} string "成功"
|
|
// @Failure 400 {string} string "获取失败的返回结果"
|
|
// @Security ApiKeyAuth
|
|
func PageNotFound(c *gin.Context) {
|
|
data := proto.NotFoundHtmlData{
|
|
Path: c.Request.URL.Path,
|
|
Translations: translationser.GetTranslationData(),
|
|
BottonTranslations: translationser.GetTranslationBottomList(),
|
|
Config: configser.GetConfigInfo(),
|
|
Advitise: configser.GetAdvitise(),
|
|
}
|
|
data.CompletePath = c.Request.URL.Path
|
|
c.JSON(http.StatusOK, data)
|
|
//common.ServerJSON(c, srvdef.Success, data)
|
|
|
|
//c.HTML(404, "404", gin.H{
|
|
// "data": data,
|
|
//})
|
|
}
|
|
|
|
func UrlRedirect(c *gin.Context) {
|
|
data := proto.UrlRedirectData{
|
|
Path: c.Request.URL.Path,
|
|
CompletePath: c.Request.URL.Path,
|
|
Translations: translationser.GetTranslationData(),
|
|
BottonTranslations: translationser.GetTranslationBottomList(),
|
|
Config: configser.GetConfigInfo(),
|
|
Advitise: configser.GetAdvitise(),
|
|
}
|
|
url := c.Query("url")
|
|
data.UrlRedirect = url
|
|
common.ServerJSON(c, srvdef.Success, data)
|
|
}
|
|
|
|
func richtextData(ctx *gin.Context, richtextId int64) (proto.RichTextInfo, *srvdef.SrvErr) {
|
|
filter := bson.M{
|
|
richtextcontentmod.FN.RichTextContentModel.Id: richtextId,
|
|
}
|
|
richtextInfo, serr := richtextcontentmod.FindOneRichTextContentModelModel(ctx, filter)
|
|
if serr != nil {
|
|
log.Error("richtextData", log.Any("filter", filter), log.E(serr))
|
|
return proto.RichTextInfo{}, serr
|
|
}
|
|
return proto.RichTextInfo{
|
|
Id: richtextInfo.Id,
|
|
Title: richtextInfo.Title,
|
|
Content: richtextInfo.Content,
|
|
Desc: richtextInfo.Desc,
|
|
SeoInfo: richtextInfo.SeoInfo,
|
|
}, nil
|
|
}
|