@@ -0,0 +1,135 @@
|
||||
package modulectrl
|
||||
|
||||
import (
|
||||
"91porn-server/app/appg"
|
||||
"91porn-server/app/service/moduleser"
|
||||
"91porn-server/common"
|
||||
"91porn-server/common/constant/redisconst"
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/common/stderr"
|
||||
"91porn-server/models/v/moduleconfmod"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/vmihailenco/msgpack/v5"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// List ...
|
||||
// @Summary 获取系统的所有后台配置模块
|
||||
// @Description 获取系统的所有后台配置模块
|
||||
// @Tags 模块配置
|
||||
// @Accept mpfd,json
|
||||
// @Produce json,html
|
||||
// @Success 200 {array} []moduleconfmod.AppModuleConf
|
||||
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
||||
// @Router /api/app/modules/list [get]
|
||||
func List(c *gin.Context) {
|
||||
ip := c.ClientIP()
|
||||
str, err := appg.Redis.Get(redisconst.ModulesCache)
|
||||
if err != nil {
|
||||
log.Warn(fmt.Sprintf("IP:%s;缓存获取广告列表信息异常:%v", ip, err))
|
||||
}
|
||||
var modules []moduleconfmod.ModuleConf
|
||||
if str != nil {
|
||||
if err = msgpack.Unmarshal([]byte(*str), &modules); err != nil {
|
||||
log.Warn(fmt.Sprintf("IP:%s;解析缓存数据异常:%v", ip, err))
|
||||
modules = nil
|
||||
}
|
||||
}
|
||||
if modules == nil {
|
||||
modules, err = moduleconfmod.GetAllModule()
|
||||
if err != nil {
|
||||
common.ServeJSON(c, stderr.ErrDbQueryError, err)
|
||||
return
|
||||
}
|
||||
common.Go(func() {
|
||||
bytes, _ := msgpack.Marshal(modules)
|
||||
if setErr := appg.Redis.Set(redisconst.ModulesCache, bytes, 600*time.Second); setErr != nil {
|
||||
log.Warn(fmt.Sprintf("IP:%s;保存缓存数据异常:%v", ip, setErr))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
var data moduleconfmod.AppModuleConf
|
||||
if len(modules) <= 0 {
|
||||
common.ServeJSON(c, stderr.Success, data)
|
||||
return
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
for _, m := range modules {
|
||||
if !m.IsActiveAt(now) {
|
||||
continue
|
||||
}
|
||||
m.HaiJiaoStyle.EnsureSortRules()
|
||||
for k, v := range m.HaiJiaoStyle.SortRules {
|
||||
v.Name = v.Val.Name()
|
||||
m.HaiJiaoStyle.SortRules[k] = v
|
||||
}
|
||||
|
||||
subConf := moduleconfmod.APPModuleConf{
|
||||
ID: m.ID,
|
||||
ModuleName: m.ModuleName,
|
||||
Cover: m.Cover,
|
||||
Type: m.Type,
|
||||
ShowType: m.ShowType,
|
||||
ShowJG: m.ShowJG,
|
||||
HaiJiaoStyle: m.HaiJiaoStyle,
|
||||
AiPlazaStyle: m.AiPlazaStyle,
|
||||
PureVersion: m.PureVersion,
|
||||
OnlineAt: m.OnlineAt,
|
||||
OfflineAt: m.OfflineAt,
|
||||
ExcludeLatest: m.ExcludeLatest,
|
||||
ExcludeRecommend: m.ExcludeRecommend,
|
||||
ExcludeSearch: m.ExcludeSearch,
|
||||
SearchOnlyWhenInactive: m.SearchOnlyWhenInactive,
|
||||
}
|
||||
if !m.DefaultTagId.IsZero() {
|
||||
subConf.DefaultTagId = m.DefaultTagId.Hex()
|
||||
}
|
||||
switch m.Type {
|
||||
case moduleconfmod.HomePage, moduleconfmod.Cartoon, moduleconfmod.Comics:
|
||||
data.HomePage = append(data.HomePage, subConf)
|
||||
case moduleconfmod.Pics:
|
||||
data.Pics = append(data.Pics, subConf)
|
||||
case moduleconfmod.Novel:
|
||||
data.Novel = append(data.Novel, subConf)
|
||||
case moduleconfmod.Community:
|
||||
data.Community = append(data.Community, subConf)
|
||||
//case moduleconfmod.PrivateCircle:
|
||||
//data.PrivateCircle = append(data.PrivateCircle, subConf)
|
||||
case moduleconfmod.DeepWeb:
|
||||
data.DeepWeb = append(data.DeepWeb, subConf)
|
||||
case moduleconfmod.ShortPage:
|
||||
data.ShortPage = append(data.ShortPage, subConf)
|
||||
case moduleconfmod.Drama:
|
||||
// 短剧模块仅下发给独立短剧频道,避免混入首页顶部模块。
|
||||
data.DramaPage = append(data.DramaPage, subConf)
|
||||
|
||||
//case moduleconfmod.AiPlaza:
|
||||
// data.AiPlaza = append(data.AiPlaza, subConf)
|
||||
}
|
||||
}
|
||||
|
||||
common.ServeJSON(c, stderr.Success, data)
|
||||
}
|
||||
|
||||
// Announcements ...
|
||||
// @Summary 获取跑马灯
|
||||
// @Description 获取跑马灯
|
||||
// @Tags 模块配置
|
||||
// @Accept mpfd,json
|
||||
// @Produce json,html
|
||||
// @Success 200 {object} moduleser.AnnouncementResp
|
||||
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
||||
// @Router /api/app/modules/announce [get]
|
||||
func Announcements(c *gin.Context) {
|
||||
resp, err := moduleser.GetModuleAnnouncements()
|
||||
if err != nil {
|
||||
common.ServeJSON(c, stderr.ErrDbQueryError, err)
|
||||
return
|
||||
}
|
||||
common.ServeJSON(c, stderr.Success, resp)
|
||||
}
|
||||
Reference in New Issue
Block a user