mirror of
https://github.com/ProudMuBai/GoFilm.git
synced 2026-04-09 07:40:52 +08:00
format Server API
This commit is contained in:
@@ -118,15 +118,15 @@ const rules = reactive({
|
||||
// 修改密码
|
||||
const changePassword = ()=>{
|
||||
ApiPost(`/changePassword`, {password: form.changePwd.password, newPassword: form.changePwd.newPassword}).then((resp: any) => {
|
||||
if (resp.status === 'ok') {
|
||||
if (resp.code === 0) {
|
||||
// 退出登录成功则删除本地的token信息并返回到 登录 /login 界面
|
||||
// clearAuthToken()
|
||||
// router.push(`/login`)
|
||||
form.changePwd = {password: '', newPassword: '', confirmPassword: ''}
|
||||
dialogV.changePwd = false
|
||||
ElMessage.success({message: resp.message})
|
||||
ElMessage.success({message: resp.msg})
|
||||
} else {
|
||||
ElMessage.error({message: resp.message})
|
||||
ElMessage.error({message: resp.msg})
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -140,12 +140,12 @@ const cancelDialog = () => {
|
||||
const logout = () => {
|
||||
// 发送请求使当前的token信息失效
|
||||
ApiGet(`/logout`).then((resp: any) => {
|
||||
if (resp.status === 'ok') {
|
||||
if (resp.code === 0 ) {
|
||||
// 退出登录成功则删除本地的token信息并返回到 登录 /login 界面
|
||||
clearAuthToken()
|
||||
router.push(`/login`)
|
||||
} else {
|
||||
ElMessage.error({message: resp.message})
|
||||
ElMessage.error({message: resp.msg})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ const getSiteInfo = ()=>{
|
||||
if (resp.code == 0) {
|
||||
data.site = resp.data
|
||||
} else {
|
||||
ElMessage.error({message: resp.data.msg})
|
||||
ElMessage.error({message: resp.msg})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ const http = (options: any) => {
|
||||
loadingCount == 0 && load.close()
|
||||
if (error.response.status == 401) {
|
||||
router.replace('/login')
|
||||
ElMessage.error(error.response.data.message)
|
||||
ElMessage.error(error.response.data.msg)
|
||||
// ElMessage.error(`未获取授权信息, 请先登录!!!`)
|
||||
} else if (error.response.status == 403) {
|
||||
ElMessage.error(`无访问权限!!!`)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="container">
|
||||
<video class="container-bg" src="../assets/image/bg.mp4"
|
||||
<video v-if="false" class="container-bg" src=""
|
||||
autoplay="autoplay" loop="loop" muted="muted"></video>
|
||||
<div class="container-form" >
|
||||
<form class="cus-form">
|
||||
@@ -37,10 +37,10 @@ const data = reactive({
|
||||
const router = useRouter()
|
||||
const login = ()=>{
|
||||
ApiPost('/login', {userName: data.userName, password: data.password}).then((resp:any)=>{
|
||||
if (resp.status == 'ok') {
|
||||
if (resp.code == 0) {
|
||||
router.push('/manage/index')
|
||||
} else {
|
||||
ElMessage.error({message: resp.message})
|
||||
ElMessage.error({message: resp.msg})
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -55,6 +55,7 @@ const login = ()=>{
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
color: #343333;
|
||||
background: url("../assets/image/managebg.png");
|
||||
}
|
||||
.container-bg {
|
||||
background-color: #b07ada;
|
||||
|
||||
@@ -143,7 +143,7 @@ onBeforeMount(() => {
|
||||
if (resp.code == 0) {
|
||||
data.info = resp.data
|
||||
} else {
|
||||
ElMessage.error({message: resp.message})
|
||||
ElMessage.error({message: resp.msg})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -8,9 +8,16 @@
|
||||
|
||||
import {onMounted} from "vue";
|
||||
import {ApiGet} from "../../utils/request";
|
||||
import {ElMessage} from "element-plus";
|
||||
|
||||
onMounted(()=>{
|
||||
ApiGet('/manage/index')
|
||||
ApiGet('/manage/index').then((resp:any)=>{
|
||||
if (resp.code == 0) {
|
||||
ElMessage.success({message: resp.msg})
|
||||
} else {
|
||||
ElMessage.error({message: resp.msg})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
@@ -31,7 +31,6 @@ const collapse = ref(false)
|
||||
|
||||
// 改变侧边栏菜单的 展开|收起 状态
|
||||
const changeCollapse = () => {
|
||||
console.log(collapse.value)
|
||||
collapse.value = !collapse.value
|
||||
}
|
||||
// 传递给子组件使用
|
||||
|
||||
@@ -239,22 +239,22 @@ const form = reactive({
|
||||
const openBatchCollect = ()=>{
|
||||
dialogV.batchV = true
|
||||
ApiGet(`/manage/collect/options`, ).then((resp: any) => {
|
||||
if (resp.status === "ok") {
|
||||
if (resp.code === 0) {
|
||||
form.options = resp.data
|
||||
} else {
|
||||
ElMessage.error({message: resp.message})
|
||||
ElMessage.error({message: resp.msg})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const startBatchCollect = ()=>{
|
||||
ApiPost(`/manage/spider/start`, {ids: form.batch.ids, time: form.batch.time, batch: true}).then((resp:any)=>{
|
||||
if (resp.status ==='ok') {
|
||||
ElMessage.success({message: resp.message})
|
||||
if (resp.code === 0) {
|
||||
ElMessage.success({message: resp.msg})
|
||||
cancelDialog()
|
||||
getCollectList()
|
||||
} else {
|
||||
ElMessage.error({message: resp.message})
|
||||
ElMessage.error({message: resp.msg})
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -262,11 +262,11 @@ const startBatchCollect = ()=>{
|
||||
// 开启采集
|
||||
const startTask = (row:any)=>{
|
||||
ApiPost(`/manage/spider/start`, {id:row.id, time: row.cd, batch: false}).then((resp:any)=>{
|
||||
if (resp.status ==='ok') {
|
||||
ElMessage.success({message: resp.message})
|
||||
if (resp.code === 0) {
|
||||
ElMessage.success({message: resp.msg})
|
||||
getCollectList()
|
||||
} else {
|
||||
ElMessage.error({message: resp.message})
|
||||
ElMessage.error({message: resp.msg})
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -294,22 +294,22 @@ const restrict = (t:number)=>{
|
||||
// 添加采集资源站
|
||||
const addSite = ()=>{
|
||||
ApiPost(`/manage/collect/add`, form.add).then((resp:any)=>{
|
||||
if (resp.status ==='ok') {
|
||||
ElMessage.success({message: resp.message})
|
||||
if (resp.code === 0) {
|
||||
ElMessage.success({message: resp.msg})
|
||||
cancelDialog()
|
||||
getCollectList()
|
||||
} else {
|
||||
ElMessage.error({message: resp.message})
|
||||
ElMessage.error({message: resp.msg})
|
||||
}
|
||||
})
|
||||
}
|
||||
// 测试添加的采集接口是否可用
|
||||
const apiTest = (params:any)=>{
|
||||
ApiPost(`/manage/collect/test`, params).then((resp:any)=>{
|
||||
if (resp.status ==='ok') {
|
||||
ElMessage.success({message: resp.message})
|
||||
if (resp.code === 0) {
|
||||
ElMessage.success({message: resp.msg})
|
||||
} else {
|
||||
ElMessage.error({message: resp.message})
|
||||
ElMessage.error({message: resp.msg})
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -318,10 +318,10 @@ const apiTest = (params:any)=>{
|
||||
const openEditDialog = (id:string)=>{
|
||||
// 从后台获取采集站信息
|
||||
ApiGet(`/manage/collect/find`, {id:id}).then((resp: any) => {
|
||||
if (resp.status === "ok") {
|
||||
if (resp.code === 0 ) {
|
||||
form.edit = resp.data
|
||||
} else {
|
||||
ElMessage.error({message: resp.message})
|
||||
ElMessage.error({message: resp.msg})
|
||||
}
|
||||
})
|
||||
dialogV.editV = true
|
||||
@@ -331,11 +331,11 @@ const openEditDialog = (id:string)=>{
|
||||
// switch 开关
|
||||
const changeSourceState = (s:any)=>{
|
||||
ApiPost(`/manage/collect/change`, {id:s.id, state: s.state, syncPictures: s.syncPictures}).then((resp: any) => {
|
||||
if (resp.status === "ok") {
|
||||
ElMessage.success({message: resp.message})
|
||||
if (resp.code === 0) {
|
||||
ElMessage.success({message: resp.msg})
|
||||
getCollectList()
|
||||
} else {
|
||||
ElMessage.error({message: resp.message})
|
||||
ElMessage.error({message: resp.msg})
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -343,12 +343,12 @@ const changeSourceState = (s:any)=>{
|
||||
//更新资源站点信息
|
||||
const updateSite = (params:FilmSource)=>{
|
||||
ApiPost(`/manage/collect/update`, params).then((resp: any) => {
|
||||
if (resp.status === "ok") {
|
||||
ElMessage.success({message: resp.message})
|
||||
if (resp.code === 0) {
|
||||
ElMessage.success({message: resp.msg})
|
||||
dialogV.editV = false
|
||||
getCollectList()
|
||||
} else {
|
||||
ElMessage.error({message: resp.message})
|
||||
ElMessage.error({message: resp.msg})
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -356,11 +356,11 @@ const updateSite = (params:FilmSource)=>{
|
||||
// 删除采集资源站
|
||||
const delSourceSite = (id:string) =>{
|
||||
ApiGet(`/manage/collect/del`, {id:id}).then((resp:any)=>{
|
||||
if (resp.status ==='ok') {
|
||||
ElMessage.success({message: resp.message})
|
||||
if (resp.code === 0) {
|
||||
ElMessage.success({message: resp.msg})
|
||||
getCollectList()
|
||||
} else {
|
||||
ElMessage.error({message: resp.message})
|
||||
ElMessage.error({message: resp.msg})
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -375,7 +375,7 @@ const cancelDialog = ()=>{
|
||||
|
||||
const getCollectList = ()=>{
|
||||
ApiGet(`/manage/collect/list`).then((resp: any) => {
|
||||
if (resp.status === "ok") {
|
||||
if (resp.code === 0) {
|
||||
data.siteList = resp.data.map((item: any) => {
|
||||
switch (item.collectType) {
|
||||
case 0:
|
||||
@@ -398,7 +398,7 @@ const getCollectList = ()=>{
|
||||
return item
|
||||
})
|
||||
} else {
|
||||
ElMessage.error({message: resp.message})
|
||||
ElMessage.error({message: resp.msg})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -144,12 +144,12 @@ const form = reactive({
|
||||
|
||||
const addTask = ()=>{
|
||||
ApiPost(`/manage/cron/add`, form.add).then((resp:any)=>{
|
||||
if (resp.status ==='ok') {
|
||||
ElMessage.success({message: resp.message})
|
||||
if (resp.code === 0) {
|
||||
ElMessage.success({message: resp.msg})
|
||||
cancelDialog()
|
||||
getTaskList()
|
||||
} else {
|
||||
ElMessage.error({message: resp.message})
|
||||
ElMessage.error({message: resp.msg})
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -157,12 +157,12 @@ const addTask = ()=>{
|
||||
const updateTask = ()=>{
|
||||
console.log(form.edit)
|
||||
ApiPost(`/manage/cron/update`, {id: form.edit.id, ids: form.edit.ids, time: form.edit.time, state: form.edit.state, remark: form.edit.remark}).then((resp:any)=>{
|
||||
if (resp.status ==='ok') {
|
||||
ElMessage.success({message: resp.message})
|
||||
if (resp.code === 0) {
|
||||
ElMessage.success({message: resp.msg})
|
||||
cancelDialog()
|
||||
getTaskList()
|
||||
} else {
|
||||
ElMessage.error({message: resp.message})
|
||||
ElMessage.error({message: resp.msg})
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -185,22 +185,22 @@ const openAddDialog = ()=>{
|
||||
// 删除定时任务
|
||||
const delTask = (id:string)=>{
|
||||
ApiGet(`/manage/cron/del`, {id:id}).then((resp:any)=>{
|
||||
if (resp.status ==='ok') {
|
||||
ElMessage.success({message: resp.message})
|
||||
if (resp.code === 0) {
|
||||
ElMessage.success({message: resp.msg})
|
||||
getTaskList()
|
||||
} else {
|
||||
ElMessage.error({message: resp.message})
|
||||
ElMessage.error({message: resp.msg})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const changeTaskState = (id:string,state:boolean)=>{
|
||||
ApiPost(`/manage/cron/change`, {id:id,state:state}).then((resp:any)=>{
|
||||
if (resp.status ==='ok') {
|
||||
ElMessage.success({message: resp.message})
|
||||
if (resp.code === 0) {
|
||||
ElMessage.success({message: resp.msg})
|
||||
getTaskList()
|
||||
} else {
|
||||
ElMessage.error({message: resp.message})
|
||||
ElMessage.error({message: resp.msg})
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -209,30 +209,30 @@ const openEditDialog = (id:string)=>{
|
||||
dialogV.editV = true
|
||||
getOptions()
|
||||
ApiGet(`/manage/cron/find`,{id:id}).then((resp: any) => {
|
||||
if (resp.status === "ok") {
|
||||
if (resp.code === 0) {
|
||||
form.edit = resp.data
|
||||
} else {
|
||||
ElMessage.error({message: resp.message})
|
||||
ElMessage.error({message: resp.msg})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const getOptions = ()=>{
|
||||
ApiGet(`/manage/collect/options`).then((resp: any) => {
|
||||
if (resp.status === "ok") {
|
||||
if (resp.code === 0) {
|
||||
form.options = resp.data
|
||||
} else {
|
||||
ElMessage.error({message: resp.message})
|
||||
ElMessage.error({message: resp.msg})
|
||||
}
|
||||
})
|
||||
}
|
||||
const getTaskList = ()=>{
|
||||
ApiGet(`/manage/cron/list`).then((resp: any) => {
|
||||
if (resp.status === "ok") {
|
||||
if (resp.code === 0) {
|
||||
data.taskList = resp.data
|
||||
} else {
|
||||
data.taskList = []
|
||||
ElMessage.warning({message: resp.message})
|
||||
ElMessage.warning({message: resp.msg})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -54,12 +54,12 @@ const c = reactive({
|
||||
|
||||
const updateBasicConfig = ()=>{
|
||||
ApiPost(`/manage/config/basic/update`, c.site).then((resp: any) => {
|
||||
if (resp.status === 'ok') {
|
||||
if (resp.code === 0) {
|
||||
// console.log(window.location.hostname)
|
||||
ElMessage.success({message: resp.message})
|
||||
ElMessage.success({message: resp.msg})
|
||||
getBasicInfo()
|
||||
} else {
|
||||
ElMessage.error({message: resp.message})
|
||||
ElMessage.error({message: resp.msg})
|
||||
}
|
||||
})
|
||||
// 更新后重新从后端获取最新数据
|
||||
@@ -70,7 +70,7 @@ const getBasicInfo = ()=>{
|
||||
// console.log(window.location.hostname)
|
||||
c.site = resp.data
|
||||
} else {
|
||||
ElMessage.error({message: resp.data.msg})
|
||||
ElMessage.error({message: resp.msg})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -71,10 +71,10 @@ sudo systemctl start docker
|
||||
- 等待后端程序初始化工作和数据爬取, 大概3~8分钟左右
|
||||
- 停止服务 `docker compose down`
|
||||
- 查看服务容器运行状态 `docker ps`
|
||||
- 在浏览器中访问管理后台: http://xxx.xxx.xxx:3600/manage,
|
||||
- 在浏览器中访问管理后台: http://xxx.xxx.xxx/manage,
|
||||
- 登录 默认 用户名 密码: `admin admin`
|
||||
- 使用后台功能中的采集管理功能进行影视数据采集 (采集任务开启后需等待一段时间)
|
||||
- 浏览器中访问前台地址查看效果, 例: [http://xxx.xxx.xxx:3600](http://xxx.xxx.xxx:3600) (点击管理后台的logo菜单可直接跳转到前台页面)
|
||||
- 浏览器中访问前台地址查看效果, 例: [http://xxx.xxx.xxx/index](http://xxx.xxx.xxx/index) (点击管理后台的logo菜单可直接跳转到前台页面)
|
||||
|
||||
### 3.服务配置信息修改
|
||||
|
||||
@@ -130,7 +130,7 @@ mysql:
|
||||
|
||||
### 5. 管理后台基本使用说明
|
||||
|
||||
- 访问 http://xxx.xxx.xxx:3600/manage 进行登录, 用户名 密码: `admin admin` , 登录成功后自行修改
|
||||
- 访问 http://xxx.xxx.xxx/manage 进行登录, 用户名 密码: `admin admin` , 登录成功后自行修改
|
||||
- 使用 `采集管理 -> 影视采集` 功能进行采集站信息的添加和更新, 系统初始化时有预留站点信息, 自行斟酌选择
|
||||
- 首先选择一个站点为主站点, 然后选择 采集一周, 一天, 或 全部, 进行主站点的数据采集, (前台数据全来自于主站点, 因此主站点只需要存在一个, 否则会冲突)
|
||||
- 主站点信息采集完成后则可在 影片管理 -> 影视分类 中进行主页分类展示信息的设置, 选择需要展示的分类信息, 以及分类的名称管理 (自行摸索如何使用)
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -21,7 +21,7 @@ func FilmSourceInit() {
|
||||
return
|
||||
}
|
||||
var l []system.FilmSource = []system.FilmSource{
|
||||
{Id: util.GenerateSalt(), Name: "HD(lzBk)", Uri: `https://cj.lziapi.com/api.php/provide/vod/`, ResultModel: system.JsonResult, Grade: system.SlaveCollect, SyncPictures: false, CollectType: system.CollectVideo, State: true},
|
||||
{Id: util.GenerateSalt(), Name: "HD(lz)", Uri: `https://cj.lziapi.com/api.php/provide/vod/`, ResultModel: system.JsonResult, Grade: system.SlaveCollect, SyncPictures: false, CollectType: system.CollectVideo, State: true},
|
||||
{Id: util.GenerateSalt(), Name: "HD(sn)", Uri: `https://suoniapi.com/api.php/provide/vod/from/snm3u8/`, ResultModel: system.JsonResult, Grade: system.SlaveCollect, SyncPictures: false, CollectType: system.CollectVideo, State: true, Interval: 2000},
|
||||
{Id: util.GenerateSalt(), Name: "HD(bf)", Uri: `https://bfzyapi.com/api.php/provide/vod/`, ResultModel: system.JsonResult, Grade: system.SlaveCollect, SyncPictures: false, CollectType: system.CollectVideo, State: true, Interval: 2500},
|
||||
{Id: util.GenerateSalt(), Name: "HD(ff)", Uri: `http://cj.ffzyapi.com/api.php/provide/vod/`, ResultModel: system.JsonResult, Grade: system.SlaveCollect, SyncPictures: false, CollectType: system.CollectVideo, State: true},
|
||||
|
||||
@@ -20,7 +20,7 @@ func AuthToken() gin.HandlerFunc {
|
||||
authToken := c.Request.Header.Get("auth-token")
|
||||
// 如果没有登录信息则直接清退
|
||||
if authToken == "" {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"status": "ok", "message": "用户未授权,请先登录."})
|
||||
system.CustomResult(http.StatusUnauthorized, system.SUCCESS, nil, "用户未授权,请先登录", c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
@@ -30,20 +30,14 @@ func AuthToken() gin.HandlerFunc {
|
||||
t := system.GetUserTokenById(uc.UserID)
|
||||
// 如果 redis中获取的token为空则登录已过期需重新登录
|
||||
if len(t) <= 0 {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"status": "ok",
|
||||
"message": "身份验证信息已过期,请重新登录!!!",
|
||||
})
|
||||
system.CustomResult(http.StatusUnauthorized, system.SUCCESS, nil, "身份验证信息已失效,请重新登录!!!", c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
// 如果redis中存在对应token, 校验authToken是否与redis中的一致
|
||||
if t != authToken {
|
||||
// 如果不一致则证明authToken已经失效或在其他地方登录, 则需要重新登录
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"status": "ok",
|
||||
"message": "账号在其它设备登录,身份验证信息失效,请重新登录!!!",
|
||||
})
|
||||
system.CustomResult(http.StatusUnauthorized, system.SUCCESS, nil, "账号在其它设备登录,身份验证信息失效,请重新登录!!!", c)
|
||||
c.Abort()
|
||||
return
|
||||
} else if err != nil && errors.Is(err, jwt.ErrTokenExpired) {
|
||||
@@ -56,7 +50,6 @@ func AuthToken() gin.HandlerFunc {
|
||||
uc, _ = system.ParseToken(newToken)
|
||||
c.Header("new-token", newToken)
|
||||
}
|
||||
|
||||
// 将UserClaims存放到context中
|
||||
c.Set(config.AuthUserClaims, uc)
|
||||
c.Next()
|
||||
|
||||
Reference in New Issue
Block a user