230 lines
6.9 KiB
Go
230 lines
6.9 KiB
Go
package laosijiser
|
|
|
|
import (
|
|
"91porn-server/common"
|
|
"91porn-server/common/laosiji"
|
|
"91porn-server/common/log"
|
|
"91porn-server/models/v/usermod"
|
|
"91porn-server/models/v/vidmod"
|
|
"91porn-server/web/service/vidser"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"math/rand"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
)
|
|
|
|
func PostSearch(ctx context.Context, param laosiji.PostSearchListReq) (resp laosiji.PostSearchListResp, err error) {
|
|
postResp, err := laosiji.PostSearch(ctx, param)
|
|
if err != nil {
|
|
log.Error("MovieSearch", log.E(err))
|
|
return
|
|
}
|
|
resp = laosiji.PostSearchListResp{
|
|
Data: make([]laosiji.PostSearchInfo, 0),
|
|
Total: postResp.Total,
|
|
Current_page: postResp.Current_page,
|
|
Page_size: postResp.Page_size,
|
|
Last_page: postResp.Last_page,
|
|
}
|
|
|
|
//是否导入
|
|
taskIds := make([]string, 0)
|
|
for _, v := range postResp.Data {
|
|
taskIds = append(taskIds, v.Id)
|
|
}
|
|
postList, _ := vidmod.GetList(bson.M{"sourceID": bson.M{"$in": taskIds}})
|
|
|
|
// 处理域名
|
|
for _, postInfo := range postResp.Data {
|
|
//postInfo.Img = common.JoinUrlPath(laosiji.IMAGEYUAN, postInfo.Img)
|
|
postInfo.Img = common.JoinUrlPath("laosiji", postInfo.Img)
|
|
|
|
for _, postIn := range postList {
|
|
if postIn.SourceID == postInfo.Id {
|
|
postInfo.IsAdd = true
|
|
continue
|
|
}
|
|
}
|
|
|
|
resp.Data = append(resp.Data, postInfo)
|
|
}
|
|
return resp, nil
|
|
}
|
|
func PostDetail(ctx context.Context, param laosiji.PostDetailReq) (resp laosiji.PostDetailResp, err error) {
|
|
resp, err = laosiji.PostDetail(ctx, param)
|
|
if err != nil {
|
|
log.Error("MovieSearch", log.E(err))
|
|
return
|
|
}
|
|
|
|
// 处理域名
|
|
//resp.Img = common.JoinUrlPath(laosiji.IMAGEYUAN, resp.Img)
|
|
resp.Img = common.JoinUrlPath("laosiji", resp.Img)
|
|
if resp.Files != nil && len(resp.Files) > 0 {
|
|
for i, file := range resp.Files {
|
|
if len(file.Image) > 0 {
|
|
//resp.Files[i].Image = common.JoinUrlPath(laosiji.IMAGEYUAN, file.Image)
|
|
resp.Files[i].Image = common.JoinUrlPath("laosiji", file.Image)
|
|
}
|
|
if len(file.Video_link) > 0 {
|
|
resp.Files[i].Video_link = common.JoinUrlPath(laosiji.APIUrl+"/m3m", file.Video_link)
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func PostAddList(ctx context.Context, param laosiji.PostAddListReq, manager string) (hits []vidser.SensitiveHit, err error) {
|
|
if param.Ids == nil || len(param.Ids) <= 0 {
|
|
return
|
|
}
|
|
// 批量查询所有详情
|
|
postDetails := make([]laosiji.PostDetailResp, 0)
|
|
for _, id := range param.Ids {
|
|
var postDetail laosiji.PostDetailResp
|
|
req := laosiji.PostDetailReq{
|
|
Id: id,
|
|
}
|
|
postDetail, err = laosiji.PostDetail(ctx, req)
|
|
if err != nil {
|
|
log.Warn("PostAddList laosiji.PostDetail failed", log.Any("id", id), log.E(err))
|
|
continue
|
|
}
|
|
//postDetail.Img = common.JoinUrlPath(laosiji.IMAGEYUAN, postDetail.Img)
|
|
postDetail.Img = common.JoinUrlPath("laosiji", postDetail.Img)
|
|
if postDetail.Files != nil && len(postDetail.Files) > 0 {
|
|
for i, file := range postDetail.Files {
|
|
if len(file.Image) > 0 {
|
|
postDetail.Files[i].Image = common.JoinUrlPath("laosiji", file.Image)
|
|
}
|
|
if len(file.Video_link) > 0 {
|
|
postDetail.Files[i].Video_link = common.JoinUrlPath("laosiji/m3m/", file.Video_link)
|
|
}
|
|
}
|
|
}
|
|
postDetails = append(postDetails, postDetail)
|
|
}
|
|
if len(postDetails) <= 0 {
|
|
log.Warn("PostAddList laosiji.PostDetailResp len is 0")
|
|
err = errors.New("laosiji.PostDetailResp len is 0")
|
|
return
|
|
}
|
|
|
|
users, err := usermod.FindMany(bson.M{"uid": bson.M{"$gt": 300000}}, &options.FindOptions{}, 0, 300)
|
|
if err != nil {
|
|
log.Warn("PostAddList FindManyUser failed", log.E(err))
|
|
return
|
|
}
|
|
terms := vidser.LoadEnabledSensitiveTerms()
|
|
hits = make([]vidser.SensitiveHit, 0)
|
|
failedIds := make([]string, 0)
|
|
for _, postDetail := range postDetails {
|
|
hit, oneErr := addOnePost(postDetail, nil, users, manager, terms)
|
|
if oneErr != nil {
|
|
log.Warn("PostAddList addOnePost failed", log.Any("id", postDetail.Id), log.E(oneErr))
|
|
failedIds = append(failedIds, postDetail.Id)
|
|
continue
|
|
}
|
|
if hit != nil {
|
|
hits = append(hits, *hit)
|
|
}
|
|
}
|
|
if len(failedIds) > 0 {
|
|
err = errors.New(fmt.Sprintf("需要同步%d个帖子,失败%d,失败Id[%s]", len(param.Ids), len(failedIds), strings.Join(failedIds, ",")))
|
|
}
|
|
return
|
|
}
|
|
|
|
func addOnePost(postDetail laosiji.PostDetailResp, tagMaps map[string]primitive.ObjectID, upUsers []*usermod.User, manager string, terms []string) (*vidser.SensitiveHit, error) {
|
|
//
|
|
// 有的帖子是图文节点 前端格式不支持 这里屏蔽
|
|
//
|
|
if len(postDetail.Files) == 0 {
|
|
return nil, nil
|
|
}
|
|
|
|
now := time.Now()
|
|
postList, err := vidmod.GetList(bson.M{"sourceID": bson.M{"$in": []string{postDetail.Id}}})
|
|
if err != nil {
|
|
log.Warn("addOnePost GetList failed", log.Any("id", postDetail.Id), log.E(err))
|
|
return nil, err
|
|
}
|
|
if postList != nil && len(postList) > 0 {
|
|
return nil, nil
|
|
}
|
|
postInfo := vidmod.VideoModel{
|
|
ID: primitive.NewObjectID(),
|
|
NewsType: vidmod.COVER,
|
|
Title: postDetail.Title,
|
|
Content: postDetail.Content,
|
|
Tags: make([]primitive.ObjectID, 0),
|
|
MimeType: "video/mp4",
|
|
Cover: postDetail.Img,
|
|
CoverThumb: postDetail.Img,
|
|
SeriesCover: make([]string, 0),
|
|
Via: "laosiji",
|
|
Status: vidmod.CheckPass,
|
|
Location: primitive.ObjectID{},
|
|
NewUpdatedAt: "laosiji",
|
|
ReviewAt: now,
|
|
CreatedAt: now,
|
|
UpdatedAt: now,
|
|
ReviewAccount: manager,
|
|
SourceID: postDetail.Id,
|
|
VerticalCover: postDetail.Img,
|
|
}
|
|
postInfo.SeriesNum, _ = strconv.Atoi(postDetail.Img_count)
|
|
postInfo.Coins, _ = strconv.ParseInt(postDetail.Money, 10, 64)
|
|
uIndex := rand.Intn(len(upUsers))
|
|
u := upUsers[uIndex]
|
|
postInfo.PublisherID = u.UID
|
|
//if postInfo.Coins > 0 {
|
|
// postInfo.Permission = 1
|
|
//} else {
|
|
// postInfo.Permission = 2
|
|
// postInfo.FreeArea = true
|
|
// postInfo.FreeAreaDate = now
|
|
//}
|
|
//节点 处理
|
|
if postDetail.Files != nil && len(postDetail.Files) > 0 {
|
|
for _, file := range postDetail.Files {
|
|
if file.Type == "image" {
|
|
if len(file.Image) > 0 {
|
|
postInfo.SeriesCover = append(postInfo.SeriesCover, file.Image)
|
|
}
|
|
}
|
|
if file.Type == "video" {
|
|
postInfo.SourceURL = file.Video_link
|
|
postInfo.PlayTime = 1
|
|
postInfo.Filename = file.Tips
|
|
postInfo.SourceID = postDetail.Id
|
|
}
|
|
}
|
|
}
|
|
if postDetail.Rich_content != nil && len(postDetail.Rich_content) > 0 {
|
|
for _, file := range postDetail.Rich_content {
|
|
postInfo.RichText += fmt.Sprintf("%s\n", file)
|
|
}
|
|
}
|
|
// 敏感词命中 → 强制为待审核(WaitingCheck=0),写库后由后台逐条告警
|
|
hit := vidser.CheckTextHits(terms, postDetail.Id, postInfo.Title, postInfo.Content, postInfo.RichText)
|
|
if hit != nil {
|
|
postInfo.Status = vidmod.WaitingCheck
|
|
log.Warn("addOnePost sensitive hit, forced offline",
|
|
log.Any("sourceId", hit.SourceID),
|
|
log.Any("title", hit.Title),
|
|
log.Any("detail", hit.Detail))
|
|
}
|
|
if _, err = vidmod.InsertBase(postInfo); err != nil {
|
|
return nil, err
|
|
}
|
|
return hit, nil
|
|
}
|