mirror of
https://github.com/ProudMuBai/GoFilm.git
synced 2026-02-15 06:54:41 +08:00
add BAM
This commit is contained in:
@@ -1,65 +1,135 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"server/config"
|
||||
"server/logic"
|
||||
"server/model/system"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// SpiderRe 数据清零重开
|
||||
func SpiderRe(c *gin.Context) {
|
||||
// 获取指令参数
|
||||
cip := c.Query("cipher")
|
||||
if cip != config.SpiderCipher {
|
||||
// CollectFilm 开启ID对应的资源站的采集任务
|
||||
func CollectFilm(c *gin.Context) {
|
||||
id := c.DefaultQuery("id", "")
|
||||
hourStr := c.DefaultQuery("h", "0")
|
||||
if id == "" || hourStr == "0" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "指令错误无法进行此操作",
|
||||
"message": "采集任务开启失败, 缺乏必要参数",
|
||||
})
|
||||
return
|
||||
}
|
||||
go logic.SL.ReZero()
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusOk,
|
||||
"message": "ReZero 任务执行已成功开启",
|
||||
})
|
||||
}
|
||||
|
||||
// FixFilmDetail 修复因网络异常造成的影片详情数据丢失
|
||||
func FixFilmDetail(c *gin.Context) {
|
||||
// 获取指令参数
|
||||
cip := c.Query("cipher")
|
||||
if cip != config.SpiderCipher {
|
||||
h, err := strconv.Atoi(hourStr)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "指令错误无法进行此操作",
|
||||
"message": "采集任务开启失败, hour(时长)参数不符合规范",
|
||||
})
|
||||
return
|
||||
}
|
||||
// 如果指令正确,则执行详情数据获取
|
||||
go logic.SL.FixDetail()
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusOk,
|
||||
"message": "FixDetail 任务执行已成功开启",
|
||||
})
|
||||
}
|
||||
|
||||
// RefreshSitePlay 清空附属站点影片数据并重新获取
|
||||
func RefreshSitePlay(c *gin.Context) {
|
||||
// 获取指令参数
|
||||
cip := c.Query("cipher")
|
||||
if cip != config.SpiderCipher {
|
||||
// 执行采集逻处理逻辑
|
||||
if err = logic.SL.StartCollect(id, h); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "指令错误无法进行此操作",
|
||||
"message": fmt.Sprint("采集任务开启失败: ", err.Error()),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 执行多站点播放数据重置
|
||||
go logic.SL.SpiderMtPlayRe()
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusOk,
|
||||
"message": "SpiderMtPlayRe 任务执行已成功开启",
|
||||
"message": "采集任务已成功开启!!!",
|
||||
})
|
||||
}
|
||||
|
||||
// StarSpider 开启并执行采集任务
|
||||
func StarSpider(c *gin.Context) {
|
||||
var cp system.CollectParams
|
||||
// 获取请求参数
|
||||
if err := c.ShouldBindJSON(&cp); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "请求参数异常",
|
||||
})
|
||||
return
|
||||
}
|
||||
if cp.Time == 0 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "采集开启失败,采集时长不能为0",
|
||||
})
|
||||
return
|
||||
}
|
||||
// 根据 Batch 执行对应的逻辑
|
||||
if cp.Batch {
|
||||
// 执行批量采集
|
||||
if cp.Ids == nil || len(cp.Ids) <= 0 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "批量采集开启失败, 关联的资源站信息为空",
|
||||
})
|
||||
return
|
||||
}
|
||||
// 执行批量采集
|
||||
logic.SL.BatchCollect(cp.Time, cp.Ids)
|
||||
} else {
|
||||
if len(cp.Id) <= 0 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "批量采集开启失败, 资源站Id获取失败",
|
||||
})
|
||||
return
|
||||
}
|
||||
if err := logic.SL.StartCollect(cp.Id, cp.Time); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": fmt.Sprint("采集任务开启失败: ", err.Error()),
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
// 返回成功执行的信息
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusOk,
|
||||
"message": "采集任务已成功开启!!!",
|
||||
})
|
||||
}
|
||||
|
||||
// SpiderReset 重置影视数据, 清空库存, 从零开始
|
||||
func SpiderReset(c *gin.Context) {
|
||||
var cp system.CollectParams
|
||||
// 获取请求参数
|
||||
if err := c.ShouldBindJSON(&cp); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "请求参数异常",
|
||||
})
|
||||
return
|
||||
}
|
||||
if cp.Time == 0 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "采集开启失败,采集时长不能为0",
|
||||
})
|
||||
return
|
||||
}
|
||||
// 后期加入一些前置验证
|
||||
if len(cp.Id) <= 0 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "SpiderReset Failed, 资源站Id获取失败",
|
||||
})
|
||||
return
|
||||
}
|
||||
logic.SL.ZeroCollect(cp.Time)
|
||||
}
|
||||
|
||||
// CoverFilmClass 重置覆盖影片分类信息
|
||||
func CoverFilmClass(c *gin.Context) {
|
||||
// 执行分类采集, 覆盖当前分类信息
|
||||
if err := logic.SL.FilmClassCollect(); err != nil {
|
||||
system.Failed(err.Error(), c)
|
||||
return
|
||||
}
|
||||
system.SuccessOnlyMsg("影视分类信息重置成功, 请稍等片刻后刷新页面", c)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user