mirror of
https://github.com/ProudMuBai/GoFilm.git
synced 2026-02-14 05:54:40 +08:00
format Server API
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"server/logic"
|
||||
"server/model/system"
|
||||
"server/plugin/spider"
|
||||
@@ -17,41 +16,25 @@ import (
|
||||
func FilmCronTaskList(c *gin.Context) {
|
||||
tl := logic.CL.GetFilmCrontab()
|
||||
if len(tl) <= 0 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "暂无任务定时任务信息",
|
||||
})
|
||||
system.Failed("暂无任务定时任务信息", c)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusOk,
|
||||
"data": tl,
|
||||
})
|
||||
system.Success(tl, "定时任务列表获取成功!!!", c)
|
||||
}
|
||||
|
||||
// GetFilmCronTask 通过Id获取对应的定时任务信息
|
||||
func GetFilmCronTask(c *gin.Context) {
|
||||
id := c.DefaultQuery("id", "")
|
||||
if id == "" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "定时任务信息获取失败,任务Id不能为空",
|
||||
})
|
||||
system.Failed("定时任务信息获取失败,任务Id不能为空", c)
|
||||
return
|
||||
}
|
||||
task, err := logic.CL.GetFilmCrontabById(id)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": fmt.Sprint("定时任务信息获取失败", err.Error()),
|
||||
})
|
||||
system.Failed(fmt.Sprint("定时任务信息获取失败", err.Error()), c)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusOk,
|
||||
"data": task,
|
||||
})
|
||||
system.Success(task, "定时任务详情获取成功!!!", c)
|
||||
}
|
||||
|
||||
// FilmCronAdd 添加定时任务
|
||||
@@ -59,35 +42,22 @@ func FilmCronAdd(c *gin.Context) {
|
||||
var vo = system.FilmCronVo{}
|
||||
// 获取请求参数
|
||||
if err := c.ShouldBindJSON(&vo); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "请求参数异常",
|
||||
})
|
||||
system.Failed("请求参数异常!!!", c)
|
||||
return
|
||||
}
|
||||
// 校验请求参数
|
||||
if err := validTaskAddVo(vo); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": err.Error(),
|
||||
})
|
||||
system.Failed(err.Error(), c)
|
||||
return
|
||||
}
|
||||
// 去除cron表达式左右空格
|
||||
vo.Spec = strings.TrimSpace(vo.Spec)
|
||||
// 执行 定时任务信息保存逻辑
|
||||
if err := logic.CL.AddFilmCrontab(vo); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": fmt.Sprint("定时任务添加失败: ", err.Error()),
|
||||
})
|
||||
system.Failed(fmt.Sprint("定时任务添加失败: ", err.Error()), c)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusOk,
|
||||
"message": "定时任务添加成功",
|
||||
})
|
||||
|
||||
system.SuccessOnlyMsg("定时任务添加成功", c)
|
||||
}
|
||||
|
||||
// FilmCronUpdate 更新定时任务信息
|
||||
@@ -95,40 +65,28 @@ func FilmCronUpdate(c *gin.Context) {
|
||||
var t = system.FilmCollectTask{}
|
||||
// 获取请求参数
|
||||
if err := c.ShouldBindJSON(&t); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "请求参数异常",
|
||||
})
|
||||
system.Failed("请求参数异常!!!", c)
|
||||
return
|
||||
}
|
||||
// 校验必要参数
|
||||
if err := validTaskInfo(t); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": err.Error(),
|
||||
})
|
||||
system.Failed(err.Error(), c)
|
||||
return
|
||||
}
|
||||
// 获取未更新的task信息
|
||||
task, err := logic.CL.GetFilmCrontabById(t.Id)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": fmt.Sprint("更新失败: ", err.Error()),
|
||||
})
|
||||
system.Failed(fmt.Sprint("更新失败: ", err.Error()), c)
|
||||
return
|
||||
}
|
||||
// 将task的可变更属性进行变更
|
||||
// 将task的可变更属性进行更新
|
||||
task.Ids = t.Ids
|
||||
task.Time = t.Time
|
||||
task.State = t.State
|
||||
task.Remark = t.Remark
|
||||
// 将变更后的task更新到系统中
|
||||
logic.CL.UpdateFilmCron(task)
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusOk,
|
||||
"message": fmt.Sprintf("定时任务[%s]更新成功", task.Id),
|
||||
})
|
||||
system.SuccessOnlyMsg(fmt.Sprintf("定时任务[%s]更新成功", task.Id), c)
|
||||
}
|
||||
|
||||
// ChangeTaskState 开启 | 关闭Id 对应的定时任务
|
||||
@@ -136,54 +94,35 @@ func ChangeTaskState(c *gin.Context) {
|
||||
var t = system.FilmCollectTask{}
|
||||
// 获取请求参数
|
||||
if err := c.ShouldBindJSON(&t); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "请求参数异常",
|
||||
})
|
||||
system.Failed("请求参数异常!!!", c)
|
||||
return
|
||||
}
|
||||
// 获取未更新的task信息
|
||||
task, err := logic.CL.GetFilmCrontabById(t.Id)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": fmt.Sprint("更新失败: ", err.Error()),
|
||||
})
|
||||
system.Failed(fmt.Sprint("更新失败: ", err.Error()), c)
|
||||
return
|
||||
}
|
||||
// 修改task的状态
|
||||
task.State = t.State
|
||||
// 将变更后的task更新到系统中
|
||||
logic.CL.UpdateFilmCron(task)
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusOk,
|
||||
"message": fmt.Sprintf("定时任务[%s]更新成功", task.Id),
|
||||
})
|
||||
system.SuccessOnlyMsg(fmt.Sprintf("定时任务[%s]更新成功", task.Id), c)
|
||||
}
|
||||
|
||||
// DelFilmCron 删除定时任务
|
||||
func DelFilmCron(c *gin.Context) {
|
||||
id := c.DefaultQuery("id", "")
|
||||
if id == "" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "删除失败,任务Id不能为空",
|
||||
})
|
||||
system.Failed("定时任务清除失败, 任务ID不能为空", c)
|
||||
return
|
||||
}
|
||||
// 如果Id不为空则执行删除逻辑
|
||||
if err := logic.CL.DelFilmCrontab(id); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": err.Error(),
|
||||
})
|
||||
system.Failed(err.Error(), c)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusOk,
|
||||
"message": fmt.Sprintf("定时任务[%s]已删除", id),
|
||||
})
|
||||
|
||||
system.SuccessOnlyMsg(fmt.Sprintf("定时任务[%s]已删除", id), c)
|
||||
}
|
||||
|
||||
// -------------------------------------------------- 参数校验 --------------------------------------------------
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"server/logic"
|
||||
"server/model/system"
|
||||
"server/plugin/SystemInit"
|
||||
@@ -13,10 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func ManageIndex(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusOk,
|
||||
"message": "hahah",
|
||||
})
|
||||
system.SuccessOnlyMsg("后台管理中心", c)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -24,10 +20,7 @@ func ManageIndex(c *gin.Context) {
|
||||
|
||||
// FilmSourceList 采集站点信息
|
||||
func FilmSourceList(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusOk,
|
||||
"data": logic.ML.GetFilmSourceList(),
|
||||
})
|
||||
system.Success(logic.ML.GetFilmSourceList(), "影视源站点信息获取成功", c)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -35,169 +28,111 @@ func FilmSourceList(c *gin.Context) {
|
||||
func FindFilmSource(c *gin.Context) {
|
||||
id := c.Query("id")
|
||||
if id == "" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "参数异常, 资源站标识不能为空",
|
||||
})
|
||||
system.Failed("参数异常, 资源站标识不能为空", c)
|
||||
return
|
||||
}
|
||||
fs := logic.ML.GetFilmSource(id)
|
||||
if fs == nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "数据异常,资源站信息不存在",
|
||||
})
|
||||
system.Failed("数据异常,资源站信息不存在", c)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusOk,
|
||||
"data": fs,
|
||||
})
|
||||
system.Success(fs, "原站点详情信息查找成功", c)
|
||||
}
|
||||
|
||||
// FilmSourceAdd 添加采集源
|
||||
func FilmSourceAdd(c *gin.Context) {
|
||||
var s = system.FilmSource{}
|
||||
// 获取请求参数
|
||||
if err := c.ShouldBindJSON(&s); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "请求参数异常",
|
||||
})
|
||||
system.Failed("请求参数异常", c)
|
||||
return
|
||||
}
|
||||
// 校验必要参数
|
||||
if err := validFilmSource(s); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": err.Error(),
|
||||
})
|
||||
system.Failed(err.Error(), c)
|
||||
return
|
||||
}
|
||||
// 如果采集站开启图片同步, 且采集站为附属站点则返回错误提示
|
||||
if s.SyncPictures && (s.Grade == system.SlaveCollect) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "附属站点无法开启图片同步功能",
|
||||
})
|
||||
system.Failed("附属站点无法开启图片同步功能", c)
|
||||
return
|
||||
}
|
||||
// 执行 spider
|
||||
if err := spider.CollectApiTest(s); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "资源接口测试失败, 请确认接口有效再添加",
|
||||
})
|
||||
system.Failed("资源接口测试失败, 请确认接口有效再添加", c)
|
||||
return
|
||||
}
|
||||
// 测试通过后将资源站信息添加到list
|
||||
if err := logic.ML.SaveFilmSource(s); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": fmt.Sprint("资源站添加失败: ", err.Error()),
|
||||
})
|
||||
system.Failed(fmt.Sprint("资源站添加失败: ", err.Error()), c)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusOk,
|
||||
"message": "添加成功",
|
||||
})
|
||||
system.SuccessOnlyMsg("添加成功", c)
|
||||
}
|
||||
|
||||
func FilmSourceUpdate(c *gin.Context) {
|
||||
var s = system.FilmSource{}
|
||||
// 获取请求参数
|
||||
if err := c.ShouldBindJSON(&s); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "请求参数异常",
|
||||
})
|
||||
system.Failed("请求参数异常", c)
|
||||
return
|
||||
}
|
||||
// 校验必要参数
|
||||
if err := validFilmSource(s); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": err.Error(),
|
||||
})
|
||||
system.Failed(err.Error(), c)
|
||||
return
|
||||
}
|
||||
// 如果采集站开启图片同步, 且采集站为附属站点则返回错误提示
|
||||
if s.SyncPictures && (s.Grade == system.SlaveCollect) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "附属站点无法开启图片同步功能",
|
||||
})
|
||||
system.Failed("附属站点无法开启图片同步功能", c)
|
||||
return
|
||||
}
|
||||
// 校验Id信息是否为空
|
||||
if s.Id == "" {
|
||||
c.JSON(http.StatusOK, gin.H{"status": StatusFailed, "message": "参数异常, 资源站标识不能为空"})
|
||||
system.Failed("参数异常, 资源站标识不能为空", c)
|
||||
return
|
||||
}
|
||||
fs := logic.ML.GetFilmSource(s.Id)
|
||||
if fs == nil {
|
||||
c.JSON(http.StatusOK, gin.H{"status": StatusFailed, "message": "数据异常,资源站信息不存在"})
|
||||
system.Failed("数据异常,资源站信息不存在", c)
|
||||
return
|
||||
}
|
||||
// 如果 uri发生变更则执行spider测试
|
||||
if fs.Uri != s.Uri {
|
||||
// 执行 spider
|
||||
if err := spider.CollectApiTest(s); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "资源接口测试失败, 请确认更新的数据接口是否有效",
|
||||
})
|
||||
system.Failed("资源接口测试失败, 请确认更新的数据接口是否有效", c)
|
||||
return
|
||||
}
|
||||
}
|
||||
// 更新资源站信息
|
||||
if err := logic.ML.UpdateFilmSource(s); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": fmt.Sprint("资源站更新失败: ", err.Error()),
|
||||
})
|
||||
system.Failed(fmt.Sprint("资源站更新失败: ", err.Error()), c)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusOk,
|
||||
"message": "更新成功",
|
||||
})
|
||||
|
||||
system.SuccessOnlyMsg("更新成功", c)
|
||||
}
|
||||
|
||||
func FilmSourceChange(c *gin.Context) {
|
||||
var s = system.FilmSource{}
|
||||
// 获取请求参数
|
||||
if err := c.ShouldBindJSON(&s); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "请求参数异常",
|
||||
})
|
||||
system.Failed("请求参数异常", c)
|
||||
return
|
||||
}
|
||||
if s.Id == "" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "参数异常, 资源站标识不能为空",
|
||||
})
|
||||
system.Failed("参数异常, 资源站标识不能为空", c)
|
||||
return
|
||||
}
|
||||
// 查找对应的资源站点信息
|
||||
fs := logic.ML.GetFilmSource(s.Id)
|
||||
if fs == nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "数据异常,资源站信息不存在",
|
||||
})
|
||||
system.Failed("数据异常,资源站信息不存在", c)
|
||||
return
|
||||
}
|
||||
// 如果采集站开启图片同步, 且采集站为附属站点则返回错误提示
|
||||
if s.SyncPictures && (fs.Grade == system.SlaveCollect) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "附属站点无法开启图片同步功能",
|
||||
})
|
||||
system.Failed("附属站点无法开启图片同步功能", c)
|
||||
return
|
||||
}
|
||||
if s.State != fs.State || s.SyncPictures != fs.SyncPictures {
|
||||
@@ -206,39 +141,24 @@ func FilmSourceChange(c *gin.Context) {
|
||||
Grade: fs.Grade, SyncPictures: s.SyncPictures, CollectType: fs.CollectType, State: s.State}
|
||||
// 更新资源站信息
|
||||
if err := logic.ML.UpdateFilmSource(s); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": fmt.Sprint("资源站更新失败: ", err.Error()),
|
||||
})
|
||||
system.Failed(fmt.Sprint("资源站更新失败: ", err.Error()), c)
|
||||
return
|
||||
}
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusOk,
|
||||
"message": "更新成功",
|
||||
})
|
||||
system.SuccessOnlyMsg("更新成功", c)
|
||||
}
|
||||
|
||||
func FilmSourceDel(c *gin.Context) {
|
||||
id := c.Query("id")
|
||||
if len(id) <= 0 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "资源站ID信息不能为空",
|
||||
})
|
||||
system.Failed("资源站ID信息不能为空", c)
|
||||
return
|
||||
}
|
||||
if err := logic.ML.DelFilmSource(id); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": fmt.Sprint("删除资源站失败: ", err.Error()),
|
||||
})
|
||||
system.Failed("删除资源站失败", c)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusOk,
|
||||
"message": "删除成功:",
|
||||
})
|
||||
system.SuccessOnlyMsg("删除成功", c)
|
||||
}
|
||||
|
||||
// FilmSourceTest 测试影视站点数据是否可用
|
||||
@@ -246,32 +166,20 @@ func FilmSourceTest(c *gin.Context) {
|
||||
var s = system.FilmSource{}
|
||||
// 获取请求参数
|
||||
if err := c.ShouldBindJSON(&s); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "请求参数异常",
|
||||
})
|
||||
system.Failed("请求参数异常", c)
|
||||
return
|
||||
}
|
||||
// 校验必要参数
|
||||
if err := validFilmSource(s); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": err.Error(),
|
||||
})
|
||||
system.Failed(err.Error(), c)
|
||||
return
|
||||
}
|
||||
// 执行 spider
|
||||
if err := spider.CollectApiTest(s); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": err.Error(),
|
||||
})
|
||||
system.Failed(err.Error(), c)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusOk,
|
||||
"message": "测试成功!!!",
|
||||
})
|
||||
system.SuccessOnlyMsg("测试成功!!!", c)
|
||||
}
|
||||
|
||||
// GetNormalFilmSource 获取状态为启用的采集站信息
|
||||
@@ -283,10 +191,7 @@ func GetNormalFilmSource(c *gin.Context) {
|
||||
l = append(l, system.FilmTaskOptions{Id: v.Id, Name: v.Name})
|
||||
}
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusOk,
|
||||
"data": l,
|
||||
})
|
||||
system.Success(l, "影视源信息获取成功", c)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------ 站点基本配置 ------------------------------------------------------
|
||||
@@ -303,47 +208,31 @@ func UpdateSiteBasic(c *gin.Context) {
|
||||
if err := c.ShouldBindJSON(&bc); err == nil {
|
||||
// 对参数进行校验
|
||||
if !util.ValidDomain(bc.Domain) && !util.ValidIPHost(bc.Domain) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "域名格式校验失败: ",
|
||||
})
|
||||
system.Failed("域名格式校验失败", c)
|
||||
return
|
||||
}
|
||||
if len(bc.SiteName) <= 0 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "网站名称不能为空: ",
|
||||
})
|
||||
system.Failed("网站名称不能为空", c)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"status": StatusOk, "message": fmt.Sprint("参数提交失败: ", err)})
|
||||
system.Failed(fmt.Sprint("请求参数异常: ", err), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 保存更新后的配置信息
|
||||
if err := logic.ML.UpdateSiteBasic(bc); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": fmt.Sprint("网站配置更新失败: ", err),
|
||||
})
|
||||
system.Failed(fmt.Sprint("网站配置更新失败: ", err), c)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusOk,
|
||||
"message": "更新成功: ",
|
||||
})
|
||||
return
|
||||
system.SuccessOnlyMsg("更新成功", c)
|
||||
}
|
||||
|
||||
// ResetSiteBasic 重置网站配置信息为初始化状态
|
||||
func ResetSiteBasic(c *gin.Context) {
|
||||
// 执行配置初始化方法直接覆盖当前基本配置信息
|
||||
SystemInit.BasicConfigInit()
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusOk,
|
||||
"message": "重置成功: ",
|
||||
})
|
||||
system.SuccessOnlyMsg("配置信息重置成功", c)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------ 参数校验 ------------------------------------------------------
|
||||
@@ -368,7 +257,3 @@ func validFilmSource(fs system.FilmSource) error {
|
||||
return errors.New("资源类型异常, 未知的资源类型")
|
||||
}
|
||||
}
|
||||
|
||||
func apiValidityCheck() {
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package controller
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"server/logic"
|
||||
"server/model/system"
|
||||
"strconv"
|
||||
@@ -14,32 +13,20 @@ 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": "采集任务开启失败, 缺乏必要参数",
|
||||
})
|
||||
system.Failed("采集任务开启失败, 缺乏必要参数", c)
|
||||
return
|
||||
}
|
||||
h, err := strconv.Atoi(hourStr)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "采集任务开启失败, hour(时长)参数不符合规范",
|
||||
})
|
||||
system.Failed("采集任务开启失败, 采集(时长)不符合规范", c)
|
||||
return
|
||||
}
|
||||
// 执行采集逻处理逻辑
|
||||
if err = logic.SL.StartCollect(id, h); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": fmt.Sprint("采集任务开启失败: ", err.Error()),
|
||||
})
|
||||
system.Failed(fmt.Sprint("采集任务开启失败: ", err.Error()), c)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusOk,
|
||||
"message": "采集任务已成功开启!!!",
|
||||
})
|
||||
system.SuccessOnlyMsg("采集任务已成功开启!!!", c)
|
||||
}
|
||||
|
||||
// StarSpider 开启并执行采集任务
|
||||
@@ -47,81 +34,48 @@ 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": "请求参数异常",
|
||||
})
|
||||
system.Failed("请求参数异常!!!", c)
|
||||
return
|
||||
}
|
||||
if cp.Time == 0 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "采集开启失败,采集时长不能为0",
|
||||
})
|
||||
system.Failed("采集开启失败,采集时长不能为0", c)
|
||||
return
|
||||
}
|
||||
// 根据 Batch 执行对应的逻辑
|
||||
if cp.Batch {
|
||||
// 执行批量采集
|
||||
if cp.Ids == nil || len(cp.Ids) <= 0 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "批量采集开启失败, 关联的资源站信息为空",
|
||||
})
|
||||
system.Failed("批量采集开启失败, 关联的资源站信息为空", c)
|
||||
return
|
||||
}
|
||||
// 执行批量采集
|
||||
logic.SL.BatchCollect(cp.Time, cp.Ids)
|
||||
} else {
|
||||
if len(cp.Id) <= 0 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "批量采集开启失败, 资源站Id获取失败",
|
||||
})
|
||||
system.Failed("批量采集开启失败, 资源站Id获取失败", c)
|
||||
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()),
|
||||
})
|
||||
system.Failed(fmt.Sprint("采集任务开启失败: ", err.Error()), c)
|
||||
return
|
||||
}
|
||||
}
|
||||
// 返回成功执行的信息
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusOk,
|
||||
"message": "采集任务已成功开启!!!",
|
||||
})
|
||||
system.SuccessOnlyMsg("采集任务已成功开启!!!", c)
|
||||
}
|
||||
|
||||
// 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": "请求参数异常",
|
||||
})
|
||||
// 清空采集数据进行重新采集前校验输入的密码是否正确
|
||||
key := c.DefaultQuery("accessKey", "")
|
||||
// 如密码错误则不执行后续操作
|
||||
if len(key) <= 0 || key != "Re0" {
|
||||
system.Failed("重置失败, 密钥校验失败!!!", c)
|
||||
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)
|
||||
// 前置校验通过则清空采集数据并对已启用站点进行 全量采集
|
||||
logic.SL.ZeroCollect(-1)
|
||||
system.SuccessOnlyMsg("影视数据已重置, 请耐心等待采集完成!!!", c)
|
||||
}
|
||||
|
||||
// CoverFilmClass 重置覆盖影片分类信息
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"log"
|
||||
"net/http"
|
||||
"server/config"
|
||||
"server/logic"
|
||||
"server/model/system"
|
||||
@@ -15,33 +14,20 @@ import (
|
||||
func Login(c *gin.Context) {
|
||||
var u system.User
|
||||
if err := c.ShouldBindJSON(&u); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "数据格式异常!!!",
|
||||
})
|
||||
system.Failed("登录信息异常!!!", c)
|
||||
return
|
||||
}
|
||||
if len(u.UserName) <= 0 || len(u.Password) <= 0 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "用户名和密码信息不能为空!!!",
|
||||
})
|
||||
system.Failed("用户名和密码信息不能为空", c)
|
||||
return
|
||||
}
|
||||
token, err := logic.UL.UserLogin(u.UserName, u.Password)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": err.Error(),
|
||||
})
|
||||
system.Failed(err.Error(), c)
|
||||
return
|
||||
}
|
||||
c.Header("new-token", token)
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusOk,
|
||||
"message": "登录成功!!!",
|
||||
})
|
||||
return
|
||||
system.SuccessOnlyMsg("登录成功!!!", c)
|
||||
}
|
||||
|
||||
// Logout 退出登录
|
||||
@@ -49,29 +35,20 @@ func Logout(c *gin.Context) {
|
||||
// 获取已登录的用户信息
|
||||
v, ok := c.Get(config.AuthUserClaims)
|
||||
if !ok {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "登录信息异常!!!",
|
||||
})
|
||||
system.Failed("请求失败,登录信息获取异常!!!", c)
|
||||
return
|
||||
}
|
||||
// 清除redis中存储的对应token
|
||||
uc, ok := v.(*system.UserClaims)
|
||||
if !ok {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "登录信息异常!!!",
|
||||
})
|
||||
system.Failed("注销失败, 身份信息格式化异常!!!", c)
|
||||
return
|
||||
}
|
||||
err := system.ClearUserToken(uc.UserID)
|
||||
if err != nil {
|
||||
log.Println("user logOut err: ", err)
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusOk,
|
||||
"message": "logout success!!!",
|
||||
})
|
||||
system.SuccessOnlyMsg("已退出登录!!!", c)
|
||||
}
|
||||
|
||||
// UserPasswordChange 修改用户密码
|
||||
@@ -79,51 +56,33 @@ func UserPasswordChange(c *gin.Context) {
|
||||
// 接收密码修改参数
|
||||
var params map[string]string
|
||||
if err := c.ShouldBindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "数据格式异常!!!",
|
||||
})
|
||||
system.Failed("参数校验失败!!!", c)
|
||||
return
|
||||
}
|
||||
// 校验参数是否存在空值
|
||||
if params["password"] == "" || params["newPassword"] == "" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "原密码和新密码不能为空!!!",
|
||||
})
|
||||
system.Failed("密码不能为空!!!", c)
|
||||
return
|
||||
}
|
||||
// 校验新密码是否符合规范
|
||||
if err := util.ValidPwd(params["newPassword"]); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": fmt.Sprint("密码格式校验失败: ", err.Error()),
|
||||
})
|
||||
system.Failed(fmt.Sprint("密码格式校验失败: ", err.Error()), c)
|
||||
return
|
||||
}
|
||||
// 获取已登录的用户信息
|
||||
v, ok := c.Get(config.AuthUserClaims)
|
||||
if !ok {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": "登录信息异常!!!",
|
||||
})
|
||||
system.Failed("操作失败,登录信息异常!!!", c)
|
||||
return
|
||||
}
|
||||
// 从context中获取用户的登录信息
|
||||
uc := v.(*system.UserClaims)
|
||||
if err := logic.UL.ChangePassword(uc.UserName, params["password"], params["newPassword"]); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusFailed,
|
||||
"message": fmt.Sprint("密码修改失败: ", err.Error()),
|
||||
})
|
||||
system.Failed(fmt.Sprint("密码修改失败: ", err.Error()), c)
|
||||
return
|
||||
}
|
||||
// 密码修改成功后不主动使token失效, 以免影响体验
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": StatusOk,
|
||||
"message": "密码修改成功",
|
||||
})
|
||||
system.SuccessOnlyMsg("密码修改成功", c)
|
||||
}
|
||||
|
||||
func UserInfo(c *gin.Context) {
|
||||
|
||||
Reference in New Issue
Block a user