mirror of
https://github.com/ctwj/urldb.git
synced 2025-11-25 11:29:37 +08:00
update: 更新开启关闭自动处理UI
This commit is contained in:
@@ -192,3 +192,54 @@ func GetPublicSystemConfig(c *gin.Context) {
|
|||||||
configResponse := converter.SystemConfigToPublicResponse(config)
|
configResponse := converter.SystemConfigToPublicResponse(config)
|
||||||
SuccessResponse(c, configResponse)
|
SuccessResponse(c, configResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 新增:切换自动处理配置
|
||||||
|
func ToggleAutoProcess(c *gin.Context) {
|
||||||
|
var req struct {
|
||||||
|
AutoProcessReadyResources bool `json:"auto_process_ready_resources"`
|
||||||
|
}
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
ErrorResponse(c, "请求参数错误", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取当前配置
|
||||||
|
config, err := repoManager.SystemConfigRepository.GetOrCreateDefault()
|
||||||
|
if err != nil {
|
||||||
|
ErrorResponse(c, "获取系统配置失败", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 只更新自动处理配置
|
||||||
|
config.AutoProcessReadyResources = req.AutoProcessReadyResources
|
||||||
|
|
||||||
|
// 保存配置
|
||||||
|
err = repoManager.SystemConfigRepository.Upsert(config)
|
||||||
|
if err != nil {
|
||||||
|
ErrorResponse(c, "保存系统配置失败", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新定时任务状态
|
||||||
|
scheduler := utils.GetGlobalScheduler(
|
||||||
|
repoManager.HotDramaRepository,
|
||||||
|
repoManager.ReadyResourceRepository,
|
||||||
|
repoManager.ResourceRepository,
|
||||||
|
repoManager.SystemConfigRepository,
|
||||||
|
repoManager.PanRepository,
|
||||||
|
repoManager.CksRepository,
|
||||||
|
repoManager.TagRepository,
|
||||||
|
repoManager.CategoryRepository,
|
||||||
|
)
|
||||||
|
if scheduler != nil {
|
||||||
|
scheduler.UpdateSchedulerStatusWithAutoTransfer(
|
||||||
|
config.AutoFetchHotDramaEnabled,
|
||||||
|
config.AutoProcessReadyResources,
|
||||||
|
config.AutoTransferEnabled,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回更新后的配置
|
||||||
|
configResponse := converter.SystemConfigToResponse(config)
|
||||||
|
SuccessResponse(c, configResponse)
|
||||||
|
}
|
||||||
|
|||||||
1
main.go
1
main.go
@@ -193,6 +193,7 @@ func main() {
|
|||||||
// 系统配置路由
|
// 系统配置路由
|
||||||
api.GET("/system/config", middleware.AuthMiddleware(), middleware.AdminMiddleware(), handlers.GetSystemConfig)
|
api.GET("/system/config", middleware.AuthMiddleware(), middleware.AdminMiddleware(), handlers.GetSystemConfig)
|
||||||
api.POST("/system/config", middleware.AuthMiddleware(), middleware.AdminMiddleware(), handlers.UpdateSystemConfig)
|
api.POST("/system/config", middleware.AuthMiddleware(), middleware.AdminMiddleware(), handlers.UpdateSystemConfig)
|
||||||
|
api.POST("/system/config/toggle-auto-process", middleware.AuthMiddleware(), middleware.AdminMiddleware(), handlers.ToggleAutoProcess)
|
||||||
api.GET("/public/system-config", handlers.GetPublicSystemConfig)
|
api.GET("/public/system-config", handlers.GetPublicSystemConfig)
|
||||||
|
|
||||||
// 热播剧管理路由(查询接口无需认证)
|
// 热播剧管理路由(查询接口无需认证)
|
||||||
|
|||||||
@@ -125,7 +125,8 @@ export const useStatsApi = () => {
|
|||||||
export const useSystemConfigApi = () => {
|
export const useSystemConfigApi = () => {
|
||||||
const getSystemConfig = () => useApiFetch('/system/config').then(parseApiResponse)
|
const getSystemConfig = () => useApiFetch('/system/config').then(parseApiResponse)
|
||||||
const updateSystemConfig = (data: any) => useApiFetch('/system/config', { method: 'POST', body: data }).then(parseApiResponse)
|
const updateSystemConfig = (data: any) => useApiFetch('/system/config', { method: 'POST', body: data }).then(parseApiResponse)
|
||||||
return { getSystemConfig, updateSystemConfig }
|
const toggleAutoProcess = (enabled: boolean) => useApiFetch('/system/config/toggle-auto-process', { method: 'POST', body: { auto_process_ready_resources: enabled } }).then(parseApiResponse)
|
||||||
|
return { getSystemConfig, updateSystemConfig, toggleAutoProcess }
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useHotDramaApi = () => {
|
export const useHotDramaApi = () => {
|
||||||
|
|||||||
@@ -51,8 +51,10 @@ export default defineNuxtConfig({
|
|||||||
},
|
},
|
||||||
runtimeConfig: {
|
runtimeConfig: {
|
||||||
public: {
|
public: {
|
||||||
apiBase: process.env.NUXT_PUBLIC_API_CLIENT || '/api',
|
// 开发环境:直接访问后端,生产环境:通过 Nginx 反代
|
||||||
apiServer: process.env.NUXT_PUBLIC_API_SERVER || 'http://localhost:8080/api'
|
apiBase: process.env.NODE_ENV === 'production' ? '/api' : 'http://localhost:8080/api',
|
||||||
|
// 服务端:开发环境直接访问,生产环境容器内访问
|
||||||
|
apiServer: process.env.NODE_ENV === 'production' ? 'http://backend:8080/api' : 'http://localhost:8080/api'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
build: {
|
build: {
|
||||||
|
|||||||
@@ -336,8 +336,10 @@ const totalPages = ref(0)
|
|||||||
|
|
||||||
// 获取待处理资源API
|
// 获取待处理资源API
|
||||||
import { useReadyResourceApi, useSystemConfigApi } from '~/composables/useApi'
|
import { useReadyResourceApi, useSystemConfigApi } from '~/composables/useApi'
|
||||||
|
import { useSystemConfigStore } from '~/stores/systemConfig'
|
||||||
const readyResourceApi = useReadyResourceApi()
|
const readyResourceApi = useReadyResourceApi()
|
||||||
const systemConfigApi = useSystemConfigApi()
|
const systemConfigApi = useSystemConfigApi()
|
||||||
|
const systemConfigStore = useSystemConfigStore()
|
||||||
|
|
||||||
// 获取系统配置
|
// 获取系统配置
|
||||||
const systemConfig = ref<any>(null)
|
const systemConfig = ref<any>(null)
|
||||||
@@ -346,6 +348,8 @@ const fetchSystemConfig = async () => {
|
|||||||
try {
|
try {
|
||||||
const response = await systemConfigApi.getSystemConfig()
|
const response = await systemConfigApi.getSystemConfig()
|
||||||
systemConfig.value = response
|
systemConfig.value = response
|
||||||
|
// 同时更新 Pinia store
|
||||||
|
systemConfigStore.setConfig(response)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取系统配置失败:', error)
|
console.error('获取系统配置失败:', error)
|
||||||
}
|
}
|
||||||
@@ -544,32 +548,18 @@ const toggleAutoProcess = async () => {
|
|||||||
updatingConfig.value = true
|
updatingConfig.value = true
|
||||||
try {
|
try {
|
||||||
const newValue = !systemConfig.value?.auto_process_ready_resources
|
const newValue = !systemConfig.value?.auto_process_ready_resources
|
||||||
console.log('当前配置:', systemConfig.value)
|
console.log('切换自动处理配置:', newValue)
|
||||||
console.log('新值:', newValue)
|
|
||||||
|
|
||||||
// 先获取当前配置,然后只更新需要的字段
|
// 使用专门的切换API
|
||||||
const currentConfig = await systemConfigApi.getSystemConfig() as any
|
const response = await systemConfigApi.toggleAutoProcess(newValue)
|
||||||
console.log('获取到的当前配置:', currentConfig)
|
console.log('切换响应:', response)
|
||||||
|
|
||||||
const updateData = {
|
|
||||||
site_title: currentConfig.site_title || '',
|
|
||||||
site_description: currentConfig.site_description || '',
|
|
||||||
keywords: currentConfig.keywords || '',
|
|
||||||
author: currentConfig.author || '',
|
|
||||||
copyright: currentConfig.copyright || '',
|
|
||||||
auto_process_ready_resources: newValue,
|
|
||||||
auto_process_interval: currentConfig.auto_process_interval || 30,
|
|
||||||
auto_transfer_enabled: currentConfig.auto_transfer_enabled || false,
|
|
||||||
auto_fetch_hot_drama_enabled: currentConfig.auto_fetch_hot_drama_enabled || false,
|
|
||||||
page_size: currentConfig.page_size || 100,
|
|
||||||
maintenance_mode: currentConfig.maintenance_mode || false
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('更新数据:', updateData)
|
|
||||||
const response = await systemConfigApi.updateSystemConfig(updateData)
|
|
||||||
console.log('更新响应:', response)
|
|
||||||
|
|
||||||
|
// 更新本地配置状态
|
||||||
systemConfig.value = response
|
systemConfig.value = response
|
||||||
|
|
||||||
|
// 同时更新 Pinia store 中的系统配置
|
||||||
|
systemConfigStore.setConfig(response)
|
||||||
|
|
||||||
alert(`自动处理配置已${newValue ? '开启' : '关闭'}`)
|
alert(`自动处理配置已${newValue ? '开启' : '关闭'}`)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('切换自动处理配置失败:', error)
|
console.error('切换自动处理配置失败:', error)
|
||||||
|
|||||||
Reference in New Issue
Block a user