@@ -0,0 +1,72 @@
|
||||
package vidmod
|
||||
|
||||
import (
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
type PaymentGuideVideo struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Cover string `json:"cover"`
|
||||
CoverThumb string `json:"coverThumb"`
|
||||
PlayTime uint `json:"playTime"`
|
||||
PlayCount int `json:"playCount"`
|
||||
FakePlayCount int `json:"-"`
|
||||
}
|
||||
|
||||
// LatestVIPContent returns the newest approved VIP videos for the
|
||||
// VIP-content-update guide. Free-area, paid-coin and non-recommendable videos
|
||||
// are not VIP content for this scene.
|
||||
func LatestVIPContent(limit int64, excludedModuleIDs []string) ([]PaymentGuideVideo, error) {
|
||||
if limit <= 0 {
|
||||
return []PaymentGuideVideo{}, nil
|
||||
}
|
||||
filter := latestVIPContentFilter(excludedModuleIDs)
|
||||
opts := options.Find().
|
||||
SetLimit(limit).
|
||||
SetSort(bson.D{{Key: "reviewAt", Value: -1}, {Key: "_id", Value: -1}}).
|
||||
SetProjection(bson.M{
|
||||
"_id": 1,
|
||||
"title": 1,
|
||||
"cover": 1,
|
||||
"coverThumb": 1,
|
||||
"playTime": 1,
|
||||
"playCount": 1,
|
||||
"fakePlayCount": 1,
|
||||
})
|
||||
var videos []VideoModel
|
||||
if err := coll(nil).Find(&videos, filter, opts); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := make([]PaymentGuideVideo, 0, len(videos))
|
||||
for _, video := range videos {
|
||||
if video.ID.IsZero() {
|
||||
continue
|
||||
}
|
||||
result = append(result, PaymentGuideVideo{
|
||||
ID: video.ID.Hex(),
|
||||
Title: video.Title,
|
||||
Cover: video.Cover,
|
||||
CoverThumb: video.CoverThumb,
|
||||
PlayTime: video.PlayTime,
|
||||
PlayCount: video.PlayCount,
|
||||
FakePlayCount: video.FakePlayCount,
|
||||
})
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func latestVIPContentFilter(excludedModuleIDs []string) bson.M {
|
||||
filter := bson.M{
|
||||
"status": CheckPass,
|
||||
"newsType": bson.M{"$in": []string{SP, SHORT}},
|
||||
"coins": 0,
|
||||
"freeArea": bson.M{"$ne": true},
|
||||
"recoWeight": bson.M{"$ne": -1},
|
||||
}
|
||||
if len(excludedModuleIDs) > 0 {
|
||||
filter["mId"] = bson.M{"$nin": excludedModuleIDs}
|
||||
}
|
||||
return filter
|
||||
}
|
||||
Reference in New Issue
Block a user