Browse Source

✨ feat: 增加解封功能

Pchen. 1 month ago
parent
commit
c2e22973ce
3 changed files with 38 additions and 0 deletions
  1. 24 0
      apis/QK/Admin/Admin.js
  2. 1 0
      lib/PermissionCatalog.js
  3. 13 0
      lib/QK/TaskScheduler.js

+ 24 - 0
apis/QK/Admin/Admin.js

@@ -52,6 +52,29 @@ class DeleteClient extends API {
     }
     }
 }
 }
 
 
+class EnableClient extends API {
+    constructor() {
+        super()
+        this.setPath('/Admin/QK/Client/Enable')
+        this.setMethod('POST')
+    }
+
+    async onRequest(req, res) {
+        try {
+            const { client_id } = req.body
+            if (!client_id) {
+                return res.json({ ...BaseStdResponse.MISSING_PARAMETER })
+            }
+            await scheduler.enableClient(client_id)
+            this.logger.info(`[QK][API][EnableClient] 已解禁客户端 clientId=${client_id}`)
+            return res.json({ ...BaseStdResponse.OK })
+        } catch (err) {
+            this.logger.error(`解禁抢课客户端失败:${err.stack || err}`)
+            return fail(res, err, '解禁抢课客户端失败')
+        }
+    }
+}
+
 class ListTask extends API {
 class ListTask extends API {
     constructor() {
     constructor() {
         super()
         super()
@@ -277,6 +300,7 @@ class SaveBatch extends API {
 module.exports = {
 module.exports = {
     ListClient,
     ListClient,
     DeleteClient,
     DeleteClient,
+    EnableClient,
     ListTask,
     ListTask,
     GetTask,
     GetTask,
     UpdateTask,
     UpdateTask,

+ 1 - 0
lib/PermissionCatalog.js

@@ -108,6 +108,7 @@ const DEFAULT_PERMISSION_RESOURCE_RULES = [
     { resource_type: 'api', resource_key: 'POST /QK/Task/Pause', api_method: 'POST', api_path: '/QK/Task/Pause', required_codes: QK_ASSISTANT_CONTROL_CODES },
     { resource_type: 'api', resource_key: 'POST /QK/Task/Pause', api_method: 'POST', api_path: '/QK/Task/Pause', required_codes: QK_ASSISTANT_CONTROL_CODES },
     { resource_type: 'api', resource_key: 'GET /Admin/QK/Client/List', api_method: 'GET', api_path: '/Admin/QK/Client/List', required_codes: ['page.admin.qk.client'] },
     { resource_type: 'api', resource_key: 'GET /Admin/QK/Client/List', api_method: 'GET', api_path: '/Admin/QK/Client/List', required_codes: ['page.admin.qk.client'] },
     { resource_type: 'api', resource_key: 'DELETE /Admin/QK/Client/Delete', api_method: 'DELETE', api_path: '/Admin/QK/Client/Delete', required_codes: ['action.qk.admin.clientManage'] },
     { resource_type: 'api', resource_key: 'DELETE /Admin/QK/Client/Delete', api_method: 'DELETE', api_path: '/Admin/QK/Client/Delete', required_codes: ['action.qk.admin.clientManage'] },
+    { resource_type: 'api', resource_key: 'POST /Admin/QK/Client/Enable', api_method: 'POST', api_path: '/Admin/QK/Client/Enable', required_codes: ['action.qk.admin.clientManage'] },
     { resource_type: 'api', resource_key: 'GET /Admin/QK/Task/List', api_method: 'GET', api_path: '/Admin/QK/Task/List', required_codes: ['page.admin.qk.task'] },
     { resource_type: 'api', resource_key: 'GET /Admin/QK/Task/List', api_method: 'GET', api_path: '/Admin/QK/Task/List', required_codes: ['page.admin.qk.task'] },
     { resource_type: 'api', resource_key: 'GET /Admin/QK/Task/Detail', api_method: 'GET', api_path: '/Admin/QK/Task/Detail', required_codes: ['page.admin.qk.task'] },
     { resource_type: 'api', resource_key: 'GET /Admin/QK/Task/Detail', api_method: 'GET', api_path: '/Admin/QK/Task/Detail', required_codes: ['page.admin.qk.task'] },
     { resource_type: 'api', resource_key: 'POST /Admin/QK/Task/Update', api_method: 'POST', api_path: '/Admin/QK/Task/Update', required_codes: ['action.qk.admin.taskManage'] },
     { resource_type: 'api', resource_key: 'POST /Admin/QK/Task/Update', api_method: 'POST', api_path: '/Admin/QK/Task/Update', required_codes: ['action.qk.admin.taskManage'] },

+ 13 - 0
lib/QK/TaskScheduler.js

@@ -1399,6 +1399,19 @@ class TaskScheduler {
         this.logInfo('deleteClient', '抢课客户端已禁用', { clientId })
         this.logInfo('deleteClient', '抢课客户端已禁用', { clientId })
     }
     }
 
 
+    async enableClient(clientId) {
+        const rows = await db.query('SELECT client_id, enabled FROM qk_client WHERE client_id = ?', [clientId])
+        if (!rows || rows.length === 0) {
+            throw new Error('客户端不存在')
+        }
+        if (Number(rows[0].enabled) === 1) {
+            throw new Error('客户端已处于启用状态')
+        }
+        const now = Date.now()
+        await db.query('UPDATE qk_client SET enabled = 1, update_time = ? WHERE client_id = ?', [now, clientId])
+        this.logInfo('enableClient', '抢课客户端已解禁', { clientId })
+    }
+
     async listAdminTasks(filters = {}) {
     async listAdminTasks(filters = {}) {
         const pagesize = Math.max(1, Math.min(100, Number(filters.pagesize || 20)))
         const pagesize = Math.max(1, Math.min(100, Number(filters.pagesize || 20)))
         const current = Math.max(1, Number(filters.current || 1))
         const current = Math.max(1, Number(filters.current || 1))