@@ -0,0 +1,89 @@
|
||||
package dramatopic
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"91porn-server/models/cache/sysconfdata"
|
||||
"91porn-server/models/v/moduleconfmod"
|
||||
"91porn-server/models/v/sysconfmod"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
const (
|
||||
TypeSystem = "SYSTEM"
|
||||
TypeCustom = "CUSTOM"
|
||||
|
||||
IDHot = "hot_recommend"
|
||||
IDLatest = "latest"
|
||||
IDEveryone = "everyone_likes"
|
||||
|
||||
KeyHot = "HOT_RECOMMEND"
|
||||
KeyLatest = "LATEST"
|
||||
KeyEveryone = "EVERYONE_LIKES"
|
||||
)
|
||||
|
||||
type SystemTopic struct {
|
||||
ID string
|
||||
Name string
|
||||
SystemKey string
|
||||
Sort int
|
||||
VCode sysconfmod.VCode
|
||||
TieOrder int
|
||||
}
|
||||
|
||||
func SystemTopics() []SystemTopic {
|
||||
defaults := map[sysconfmod.VCode]int{
|
||||
sysconfmod.VCodeDramaTopicHotSort: 500,
|
||||
sysconfmod.VCodeDramaTopicLatestSort: 400,
|
||||
sysconfmod.VCodeDramaTopicEveryoneSort: 300,
|
||||
}
|
||||
values, err := sysconfdata.GetIntsFromSharedCache(defaults)
|
||||
if err != nil {
|
||||
values = defaults
|
||||
}
|
||||
topics := []SystemTopic{
|
||||
{ID: IDHot, Name: "热门推荐", SystemKey: KeyHot, Sort: values[sysconfmod.VCodeDramaTopicHotSort], VCode: sysconfmod.VCodeDramaTopicHotSort, TieOrder: 3},
|
||||
{ID: IDLatest, Name: "最新上架", SystemKey: KeyLatest, Sort: values[sysconfmod.VCodeDramaTopicLatestSort], VCode: sysconfmod.VCodeDramaTopicLatestSort, TieOrder: 2},
|
||||
{ID: IDEveryone, Name: "大家爱看", SystemKey: KeyEveryone, Sort: values[sysconfmod.VCodeDramaTopicEveryoneSort], VCode: sysconfmod.VCodeDramaTopicEveryoneSort, TieOrder: 1},
|
||||
}
|
||||
return topics
|
||||
}
|
||||
|
||||
func FindSystem(id string) (SystemTopic, bool) {
|
||||
for _, topic := range SystemTopics() {
|
||||
if topic.ID == id {
|
||||
return topic, true
|
||||
}
|
||||
}
|
||||
return SystemTopic{}, false
|
||||
}
|
||||
|
||||
// ModuleID returns the configured hot-drama module that owns custom topics.
|
||||
// It follows the same compatibility fallback as the short-drama channel.
|
||||
func ModuleID(now time.Time) (primitive.ObjectID, bool, error) {
|
||||
modules, err := moduleconfmod.GetModuleConfByType(moduleconfmod.Drama)
|
||||
if err != nil {
|
||||
return primitive.NilObjectID, false, err
|
||||
}
|
||||
active := make([]moduleconfmod.ModuleConf, 0, len(modules))
|
||||
for _, module := range modules {
|
||||
if module.IsActiveAt(now) {
|
||||
active = append(active, module)
|
||||
}
|
||||
}
|
||||
for _, module := range active {
|
||||
name := strings.ToLower(strings.TrimSpace(module.ModuleName + " " + module.SubModuleName))
|
||||
if strings.Contains(name, "热门") || strings.Contains(name, "hot") {
|
||||
return module.ID, true, nil
|
||||
}
|
||||
}
|
||||
if len(active) > 1 {
|
||||
return active[1].ID, true, nil
|
||||
}
|
||||
if len(active) == 1 {
|
||||
return active[0].ID, true, nil
|
||||
}
|
||||
return primitive.NilObjectID, false, nil
|
||||
}
|
||||
Reference in New Issue
Block a user