package searchctrl import ( "91porn-server/app/service/moduleser" "91porn-server/app/service/search" "91porn-server/app/service/searcher" "91porn-server/app/service/vidser" "91porn-server/common" "91porn-server/common/filter" "91porn-server/common/stderr" "91porn-server/models/commod" "91porn-server/models/l/searchlogmod" "fmt" "github.com/gin-gonic/gin" ) // List doc // @Summary 搜索模块 - 搜索keyWords和realm指定的相关资源 // @Description 获取FILE域 Token // @Tags Search // @Accept mpfd,json // @Produce json,html // @Param q body search.NewsKeywordSearchReq true "参数" // @Success 200 object search.NewsKeywordSearchRep "成功" // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /app/search/list [post] func List(c *gin.Context) { var req search.NewsKeywordSearchReq if err := c.ShouldBind(&req); err != nil { common.ServeJSON(c, stderr.ErrParamError, "search List arg error "+err.Error()) return } // 检查uid是否存在 uid, err := common.GetUID(c) if err != nil { common.ServeJSON(c, stderr.ErrAccessForbid, "search List Context USER_ID is not exist ") return } req.KeyWords, err = filterKeyWord(req.KeyWords) if err != nil { common.ServeJSON(c, stderr.TagAddTagNameInvalidErr, err) return } //录入搜索日志 common.Go(func() { _ = searchlogmod.InsertMany(uid, req.Realm, req.KeyWords) }) data, err := req.Search(uid) if err != nil { common.ServeJSON(c, stderr.ErrNetWorkBusy, err) return } common.ServeJSON(c, stderr.Success, data) //if arg.Realm == constant.Video { // if items, ok := result.Data().([]searcher.VideoRes); ok { // // 查询用户信息 // u, err := usermod.FindUserByUID(uid) // if err != nil { // common.ServeJSON(c, stderr.ErrNetWorkBusy, err) // return // } // if u.VipExpireDate.After(time.Now()) { // for k, item := range items { // if item.Coins != nil && *item.Coins < 10 { // var zero int64 = 0 // item.Coins = &zero // } // items[k] = item // } // } // common.ServeJSON(c, stderr.Success, gin.H{ // "list": items, // "hasNext": result.HasNext(), // }) // return // } //} // //if req.Realm == constant.SearchSP || req.Realm == constant.SearchShort { // // 额外获取TAG相关信息 // tagId, err := tagmod.GetTagIDByName(req.KeyWords[0]) // if tagId.IsZero() || err != nil { // common.ServeJSON(c, stderr.Success, gin.H{ // "list": result.Data(), // "tagID": "", // "tagVidList": nil, // "hasNext": result.HasNext(), // }) // return // } // // 6-最多收藏 // vmodList, err := vidser.GetVideosByTagID(tagId, req.Realm, 6, 0, 4) // if err != nil { // common.ServeJSON(c, stderr.Success, gin.H{ // "list": result.Data(), // "tagID": "", // "tagVidList": nil, // "hasNext": result.HasNext(), // }) // return // } // oids := make([]primitive.ObjectID, len(vmodList)) // for i, v := range vmodList { // oids[i] = v.ID // } // if len(oids) > int(req.PageSize) { // oids = oids[:req.PageSize] // } // vidList := vidhelpser.GetVideosByIDs(0, oids) // common.ServeJSON(c, stderr.Success, gin.H{ // "list": result.Data(), // "tagID": tagId.Hex(), // "tagVidList": vidList, // "hasNext": result.HasNext(), // }) // return //} //common.ServeJSON(c, stderr.Success, gin.H{ // "list": result.Data(), // "hasNext": result.HasNext(), //}) } // 如返回为空数组 则表示所输入关键字 全为违规词汇 func filterKeyWord(KeyWords []string) ([]string, error) { //过滤掉违规词汇 pureKw := make([]string, 0, len(KeyWords)) for _, v := range KeyWords { s, e := filter.TagFilter.Filter(v) if len(s) == 0 && e == nil { pureKw = append(pureKw, v) } } if len(pureKw) == 0 { return pureKw, fmt.Errorf("Invalid tag name: %v", KeyWords) } return pureKw, nil } // IndexList doc // @Summary 搜索 - 搜索首页 // @Description 获取搜索首页列表 // @Tags Search // @Accept mpfd,json // @Produce json,html // @Success 200 {string} json "{"msg": "操作成功" "data":{ "hotTagList":[] "hotVidList":[] "themeList":[] }" // @Failure 400 {string} json "{"msg": "操作失败" "data":{}}" // @Router /search/index [get] func IndexList(c *gin.Context) { uid, err := common.GetUID(c) if err != nil { common.ServeJSON(c, stderr.ErrNoToken, "") return } //热点视屏Opting hVidOpt := (&searcher.Option{}).SetLimit(6) //今日最热视屏Opting hsVidopt := (&searcher.Option{}).SetLimit(20) //前端希望给20个 文东确认 home := search.GetHome(uid, hVidOpt, hsVidopt) common.ServeJSON(c, stderr.Success, home) } // WonderTagList doc // @Summary 搜索 - 搜索首页 // @Description 获取发现精彩标签列表 // @Tags Search // @Accept mpfd,json // @Produce json,html // @Param pageNumber query integer true "页码" // @Param pageSize query integer true "每页条数" // @Success 200 {string} json "{"msg": "操作成功", "data":[]}" // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /search/wonder/list [get] func WonderTagList(c *gin.Context) { var arg struct { commod.Page } if err := c.ShouldBind(&arg); err != nil { common.ServeJSON(c, stderr.ErrParamError, "searchCtrl WonderTagList arg error "+err.Error()) return } skip := int64((arg.PageNumber - 1) * arg.PageSize) limit := int64(arg.PageSize) tags, hasNext, err := search.GetWonderTagList(skip, limit) if err != nil { common.ServeJSON(c, stderr.ErrNetWorkBusy, "searchCtrl WonderTags error: "+err.Error()) return } common.ServeJSON(c, stderr.Success, gin.H{ "list": tags, "hasNext": hasNext, }) } // HotTagSearch doc // @Summary 搜索 // @Description 猜你想要 // @Tags Search // @Accept mpfd,json // @Produce json,html // @Success 200 {object} proto.Tag // @Failure 400 {string} json "{"msg": "操作失败" "data":{}}" // @Router /search/hotTag [get] func HotTagSearch(c *gin.Context) { data, err := search.GetHotTag() if err != nil { common.ServeJSON(c, stderr.ErrNetWorkBusy, err.Error()) return } common.ServeJSON(c, stderr.Success, gin.H{ "list": data, }) } // HotVid doc // @Summary 热门视频列表 // @Description 热门视频列表 // @Tags Search // @Accept mpfd,json // @Produce json,html // @Param pageNumber query int true "当前页" // @Param pageSize query int true "每页条数" // @Param type query int true "0最新热播 1本月最热 2上月最热" // @Success 200 {object} vidmod.VideoModel "{"msg": "操作成功"}" // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /app/search/hotVid/list [get] func HotVid(c *gin.Context) { var arg struct { commod.Page T int `json:"type" form:"type"` // 0 最新热播 1本月最热 2上月最热 } if err := c.ShouldBind(&arg); err != nil { common.ServeJSON(c, stderr.ErrParamError, "searchCtrl WonderTagList arg error "+err.Error()) return } res, err := vidser.GetHotVideo(int64(arg.PageNumber), int64(arg.PageSize), arg.T) if err != nil { common.ServeJSON(c, stderr.Failure, err) return } common.ServeJSON(c, stderr.Success, res) } // HotPublisher doc // @Summary 热门博主 // @Description 热门博主 // @Tags Search // @Accept mpfd,json // @Produce json,html // @Param pageNumber query int true "当前页" // @Param pageSize query int true "每页条数" // @Success 200 {object} proto.HotPublisher "{"msg": "操作成功"}" // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /search/hotPublisher/list [get] func HotPublisher(c *gin.Context) { // 检查uid是否存在 uid, err := common.GetUID(c) if err != nil { common.ServeJSON(c, stderr.ErrAccessForbid, "search HotPublisher Context USER_ID is not exist ") return } list, err := vidser.GetHotPublisher(uid) if err != nil { common.ServeJSON(c, stderr.Failure, err) return } common.ServeJSON(c, stderr.Success, gin.H{ "list": list, }) } // PublisherList doc // @Summary 热门板块 // @Description 热门板块 // @Tags 发布 // @Accept mpfd,json // @Produce json,html // @Success 200 {object} tagmod.TagInfoRes "{"msg": "操作成功"}" // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /app/search/publisher/list [get] func PublisherList(c *gin.Context) { // 检查uid是否存在 uid, err := common.GetUID(c) if err != nil { common.ServeJSON(c, stderr.ErrAccessForbid, "search HotPublisher Context USER_ID is not exist ") return } list, err := moduleser.GetPublishTag(uid) if err != nil { common.ServeJSON(c, stderr.Failure, err) return } common.ServeJSON(c, stderr.Success, list) }