add new features

This commit is contained in:
mubai
2024-10-29 22:30:01 +08:00
parent 7ceb125746
commit d1433e4b5b
23 changed files with 525 additions and 129 deletions

View File

@@ -9,6 +9,7 @@ import (
"server/plugin/SystemInit"
"server/plugin/common/util"
"server/plugin/spider"
"strconv"
)
func ManageIndex(c *gin.Context) {
@@ -235,6 +236,99 @@ func ResetSiteBasic(c *gin.Context) {
system.SuccessOnlyMsg("配置信息重置成功", c)
}
// ------------------------------------------------------ 轮播数据配置 ------------------------------------------------------
// BannerList 获取轮播图数据
func BannerList(c *gin.Context) {
bl := logic.ML.GetBanners()
system.Success(bl, "配置信息重置成功", c)
}
// BannerFind 返回ID对应的横幅信息
func BannerFind(c *gin.Context) {
idStr := c.Query("id")
if idStr == "" {
system.Failed("Banner信息获取失败, ID信息异常", c)
return
}
id, err := strconv.ParseInt(idStr, 10, 64)
if err != nil {
system.Failed("删除失败,参数类型异常", c)
return
}
bl := logic.ML.GetBanners()
for _, b := range bl {
if b.Id == id {
system.Success(b, "Banner信息获取成功", c)
return
}
}
system.Failed("Banner信息获取失败", c)
}
// BannerAdd 添加海报数据
func BannerAdd(c *gin.Context) {
var b system.Banner
if err := c.ShouldBindJSON(&b); err != nil {
system.Failed("Banner参数提交异常", c)
return
}
bl := logic.ML.GetBanners()
bl = append(bl, b)
if err := logic.ML.SaveBanners(bl); err != nil {
system.Failed(fmt.Sprintln("Banners信息添加失败,", err), c)
return
}
system.SuccessOnlyMsg("海报信息添加成功", c)
}
// BannerUpdate 更新海报数据
func BannerUpdate(c *gin.Context) {
var banner system.Banner
if err := c.ShouldBindJSON(&banner); err != nil {
system.Failed("Banner参数提交异常", c)
return
}
bl := logic.ML.GetBanners()
for i, b := range bl {
if b.Id == banner.Id {
bl[i] = banner
if err := logic.ML.SaveBanners(bl); err != nil {
system.Failed("海报信息更新失败", c)
} else {
system.SuccessOnlyMsg("海报信息更新成功", c)
return
}
}
}
system.Failed("海报信息更新失败, 未匹配对应Banner信息", c)
}
// BannerDel 删除海报数据
func BannerDel(c *gin.Context) {
idStr := c.Query("id")
if idStr == "" {
system.Failed("Banner信息获取失败, ID信息异常", c)
return
}
id, err := strconv.ParseInt(idStr, 10, 64)
if err != nil {
system.Failed("删除失败,参数类型异常", c)
return
}
bl := logic.ML.GetBanners()
for i, b := range bl {
if b.Id == id {
bl = append(bl[:i], bl[i+1:]...)
_ = logic.ML.SaveBanners(bl)
system.SuccessOnlyMsg("海报信息删除成功", c)
return
}
}
system.Failed("海报信息删除失败", c)
}
// ------------------------------------------------------ 参数校验 ------------------------------------------------------
func validFilmSource(fs system.FilmSource) error {
// 资源名称不能为空 且长度不能超过20

View File

@@ -3,6 +3,7 @@ package controller
import (
"fmt"
"github.com/gin-gonic/gin"
"server/config"
"server/logic"
"server/model/system"
"strconv"
@@ -64,13 +65,27 @@ func StarSpider(c *gin.Context) {
system.SuccessOnlyMsg("采集任务已成功开启!!!", c)
}
// ClearAllFilm 删除所有film信息
func ClearAllFilm(c *gin.Context) {
// 清空采集数据进行重新采集前校验输入的密码是否正确
pwd := c.DefaultQuery("password", "")
// 如密码错误则不执行后续操作
if !verifyPassword(c, pwd) {
system.Failed("重置失败, 密钥校验失败!!!", c)
return
}
// 删除已采集的所有影片信息
logic.SL.ClearFilms()
system.SuccessOnlyMsg("影视数据已删除!!!", c)
}
// SpiderReset 重置影视数据, 清空库存, 从零开始
func SpiderReset(c *gin.Context) {
// 清空采集数据进行重新采集前校验输入的密码是否正确
key := c.DefaultQuery("accessKey", "")
pwd := c.DefaultQuery("password", "")
// 如密码错误则不执行后续操作
if len(key) <= 0 || key != "Re0" {
system.Failed("重置失败, 密校验失败!!!", c)
if !verifyPassword(c, pwd) {
system.Failed("重置失败, 密校验失败!!!", c)
return
}
// 前置校验通过则清空采集数据并对已启用站点进行 全量采集
@@ -87,3 +102,17 @@ func CoverFilmClass(c *gin.Context) {
}
system.SuccessOnlyMsg("影视分类信息重置成功, 请稍等片刻后刷新页面", c)
}
// 校验密码有效性
func verifyPassword(c *gin.Context, password string) bool {
// 获取已登录的用户信息
v, ok := c.Get(config.AuthUserClaims)
if !ok {
system.Failed("操作失败,登录信息异常!!!", c)
return false
}
// 从context中获取用户的登录信息
uc := v.(*system.UserClaims)
// 校验密码
return logic.UL.VerifyUserPassword(uc.UserID, password)
}