|
@@ -1,8 +1,8 @@
|
|
-const express = require('express');
|
|
|
|
|
|
+const express = require("express");
|
|
const router = express.Router();
|
|
const router = express.Router();
|
|
-const { executeQuery } = require('../config/database');
|
|
|
|
|
|
+const { executeQuery } = require("../config/database");
|
|
|
|
|
|
-router.get('/', async (req, res) => {
|
|
|
|
|
|
+router.get("/", async (req, res) => {
|
|
try {
|
|
try {
|
|
const { page = 1, pageSize = 10, search, status } = req.query;
|
|
const { page = 1, pageSize = 10, search, status } = req.query;
|
|
const offset = (page - 1) * pageSize;
|
|
const offset = (page - 1) * pageSize;
|
|
@@ -13,22 +13,22 @@ router.get('/', async (req, res) => {
|
|
|
|
|
|
// 添加搜索条件
|
|
// 添加搜索条件
|
|
if (search) {
|
|
if (search) {
|
|
- whereConditions.push('tools_name LIKE ?');
|
|
|
|
|
|
+ whereConditions.push("tools_name LIKE ?");
|
|
queryParams.push(`%${search}%`);
|
|
queryParams.push(`%${search}%`);
|
|
}
|
|
}
|
|
|
|
|
|
// 添加状态过滤条件
|
|
// 添加状态过滤条件
|
|
- if (status !== undefined && status !== '') {
|
|
|
|
- whereConditions.push('status = ?');
|
|
|
|
|
|
+ if (status !== undefined && status !== "") {
|
|
|
|
+ whereConditions.push("status = ?");
|
|
queryParams.push(parseInt(status));
|
|
queryParams.push(parseInt(status));
|
|
}
|
|
}
|
|
|
|
|
|
// 构建WHERE子句
|
|
// 构建WHERE子句
|
|
- const whereClause = whereConditions.length > 0 ? `WHERE ${whereConditions.join(' AND ')}` : '';
|
|
|
|
|
|
+ const whereClause = whereConditions.length > 0 ? `WHERE ${whereConditions.join(" AND ")}` : "";
|
|
|
|
|
|
const sql = `
|
|
const sql = `
|
|
SELECT access_task_id, search_task_id, tools_name, tools_function_name,
|
|
SELECT access_task_id, search_task_id, tools_name, tools_function_name,
|
|
- access_type, tools_function_desc, api_doc, api_class_name,
|
|
|
|
|
|
+ access_type, tools_function_desc, api_doc, api_class_name, api_provider,
|
|
operate_path_data, origin_content_link, status, fail_reason,
|
|
operate_path_data, origin_content_link, status, fail_reason,
|
|
create_time, update_time
|
|
create_time, update_time
|
|
FROM tools_auto_access_task
|
|
FROM tools_auto_access_task
|
|
@@ -43,30 +43,27 @@ router.get('/', async (req, res) => {
|
|
const sqlParams = [...queryParams, parseInt(pageSize), offset];
|
|
const sqlParams = [...queryParams, parseInt(pageSize), offset];
|
|
const countParams = [...queryParams];
|
|
const countParams = [...queryParams];
|
|
|
|
|
|
- const [data, countResult] = await Promise.all([
|
|
|
|
- executeQuery(sql, sqlParams),
|
|
|
|
- executeQuery(countSql, countParams)
|
|
|
|
- ]);
|
|
|
|
|
|
+ const [data, countResult] = await Promise.all([executeQuery(sql, sqlParams), executeQuery(countSql, countParams)]);
|
|
|
|
|
|
res.json({
|
|
res.json({
|
|
data,
|
|
data,
|
|
total: countResult[0].total,
|
|
total: countResult[0].total,
|
|
page: parseInt(page),
|
|
page: parseInt(page),
|
|
- pageSize: parseInt(pageSize)
|
|
|
|
|
|
+ pageSize: parseInt(pageSize),
|
|
});
|
|
});
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- console.error('Error fetching auto access tasks:', error);
|
|
|
|
- res.status(500).json({ error: 'Internal server error' });
|
|
|
|
|
|
+ console.error("Error fetching auto access tasks:", error);
|
|
|
|
+ res.status(500).json({ error: "Internal server error" });
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
-router.get('/:id', async (req, res) => {
|
|
|
|
|
|
+router.get("/:id", async (req, res) => {
|
|
try {
|
|
try {
|
|
const { id } = req.params;
|
|
const { id } = req.params;
|
|
|
|
|
|
const sql = `
|
|
const sql = `
|
|
SELECT access_task_id, search_task_id, tools_name, tools_function_name,
|
|
SELECT access_task_id, search_task_id, tools_name, tools_function_name,
|
|
- access_type, tools_function_desc, api_doc, api_class_name,
|
|
|
|
|
|
+ access_type, tools_function_desc, api_doc, api_class_name, api_provider,
|
|
operate_path_data, origin_content_link, status, fail_reason,
|
|
operate_path_data, origin_content_link, status, fail_reason,
|
|
create_time, update_time
|
|
create_time, update_time
|
|
FROM tools_auto_access_task
|
|
FROM tools_auto_access_task
|
|
@@ -76,45 +73,126 @@ router.get('/:id', async (req, res) => {
|
|
const data = await executeQuery(sql, [id]);
|
|
const data = await executeQuery(sql, [id]);
|
|
|
|
|
|
if (data.length === 0) {
|
|
if (data.length === 0) {
|
|
- return res.status(404).json({ error: 'Task not found' });
|
|
|
|
|
|
+ return res.status(404).json({ error: "Task not found" });
|
|
}
|
|
}
|
|
|
|
|
|
res.json(data[0]);
|
|
res.json(data[0]);
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- console.error('Error fetching auto access task detail:', error);
|
|
|
|
- res.status(500).json({ error: 'Internal server error' });
|
|
|
|
|
|
+ console.error("Error fetching auto access task detail:", error);
|
|
|
|
+ res.status(500).json({ error: "Internal server error" });
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
-router.put('/:id', async (req, res) => {
|
|
|
|
|
|
+router.put("/:id", async (req, res) => {
|
|
try {
|
|
try {
|
|
const { id } = req.params;
|
|
const { id } = req.params;
|
|
const {
|
|
const {
|
|
- search_task_id, tools_name, tools_function_name, access_type,
|
|
|
|
- tools_function_desc, api_doc, api_class_name, operate_path_data,
|
|
|
|
- origin_content_link, status, fail_reason
|
|
|
|
|
|
+ search_task_id,
|
|
|
|
+ tools_name,
|
|
|
|
+ tools_function_name,
|
|
|
|
+ access_type,
|
|
|
|
+ tools_function_desc,
|
|
|
|
+ api_doc,
|
|
|
|
+ api_class_name,
|
|
|
|
+ api_provider,
|
|
|
|
+ operate_path_data,
|
|
|
|
+ origin_content_link,
|
|
|
|
+ status,
|
|
|
|
+ fail_reason,
|
|
} = req.body;
|
|
} = req.body;
|
|
|
|
|
|
const sql = `
|
|
const sql = `
|
|
UPDATE tools_auto_access_task
|
|
UPDATE tools_auto_access_task
|
|
SET search_task_id = ?, tools_name = ?, tools_function_name = ?,
|
|
SET search_task_id = ?, tools_name = ?, tools_function_name = ?,
|
|
access_type = ?, tools_function_desc = ?, api_doc = ?,
|
|
access_type = ?, tools_function_desc = ?, api_doc = ?,
|
|
- api_class_name = ?, operate_path_data = ?, origin_content_link = ?,
|
|
|
|
|
|
+ api_class_name = ?, api_provider = ?, operate_path_data = ?, origin_content_link = ?,
|
|
status = ?, fail_reason = ?, update_time = NOW()
|
|
status = ?, fail_reason = ?, update_time = NOW()
|
|
WHERE access_task_id = ?
|
|
WHERE access_task_id = ?
|
|
`;
|
|
`;
|
|
|
|
|
|
await executeQuery(sql, [
|
|
await executeQuery(sql, [
|
|
- search_task_id, tools_name, tools_function_name, access_type,
|
|
|
|
- tools_function_desc, api_doc, api_class_name, operate_path_data,
|
|
|
|
- origin_content_link, status, fail_reason, id
|
|
|
|
|
|
+ search_task_id ?? null,
|
|
|
|
+ tools_name ?? null,
|
|
|
|
+ tools_function_name ?? null,
|
|
|
|
+ access_type ?? null,
|
|
|
|
+ tools_function_desc ?? null,
|
|
|
|
+ api_doc ?? null,
|
|
|
|
+ api_class_name ?? null,
|
|
|
|
+ api_provider ?? null,
|
|
|
|
+ operate_path_data ?? null,
|
|
|
|
+ origin_content_link ?? null,
|
|
|
|
+ status ?? null,
|
|
|
|
+ fail_reason ?? null,
|
|
|
|
+ id,
|
|
|
|
+ ]);
|
|
|
|
+
|
|
|
|
+ res.json({ message: "Task updated successfully" });
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.error("Error updating auto access task:", error);
|
|
|
|
+ res.status(500).json({ error: "Internal server error" });
|
|
|
|
+ }
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+router.post("/", async (req, res) => {
|
|
|
|
+ try {
|
|
|
|
+ const {
|
|
|
|
+ access_task_id,
|
|
|
|
+ tools_name,
|
|
|
|
+ tools_function_name,
|
|
|
|
+ tools_function_desc,
|
|
|
|
+ access_type,
|
|
|
|
+ api_provider,
|
|
|
|
+ api_doc,
|
|
|
|
+ operate_path_data,
|
|
|
|
+ status = 0,
|
|
|
|
+ } = req.body;
|
|
|
|
+
|
|
|
|
+ // 验证必填字段
|
|
|
|
+ if (!access_task_id || !tools_name || access_type === undefined) {
|
|
|
|
+ return res.status(400).json({ error: "Missing required fields" });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 根据接入方式验证条件必填字段
|
|
|
|
+ if (access_type === "api_no_crack" || access_type === "api_crack") {
|
|
|
|
+ // API接入方式
|
|
|
|
+ if (!api_provider || !api_doc) {
|
|
|
|
+ return res.status(400).json({ error: "API provider and API doc are required for API access type" });
|
|
|
|
+ }
|
|
|
|
+ } else if (access_type === "browser_auto_operate") {
|
|
|
|
+ // 浏览器自动操作接入方式
|
|
|
|
+ if (!operate_path_data) {
|
|
|
|
+ return res.status(400).json({ error: "Operation path data is required for browser automation access type" });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const sql = `
|
|
|
|
+ INSERT INTO tools_auto_access_task (
|
|
|
|
+ access_task_id, tools_name, tools_function_name, tools_function_desc,
|
|
|
|
+ access_type, api_provider, api_doc, operate_path_data, status,
|
|
|
|
+ create_time, update_time
|
|
|
|
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW())
|
|
|
|
+ `;
|
|
|
|
+
|
|
|
|
+ await executeQuery(sql, [
|
|
|
|
+ access_task_id,
|
|
|
|
+ tools_name,
|
|
|
|
+ tools_function_name || null,
|
|
|
|
+ tools_function_desc || null,
|
|
|
|
+ access_type,
|
|
|
|
+ api_provider || null,
|
|
|
|
+ api_doc || null,
|
|
|
|
+ operate_path_data || null,
|
|
|
|
+ status,
|
|
]);
|
|
]);
|
|
|
|
|
|
- res.json({ message: 'Task updated successfully' });
|
|
|
|
|
|
+ res.status(201).json({
|
|
|
|
+ message: "Auto access task created successfully",
|
|
|
|
+ access_task_id
|
|
|
|
+ });
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- console.error('Error updating auto access task:', error);
|
|
|
|
- res.status(500).json({ error: 'Internal server error' });
|
|
|
|
|
|
+ console.error("Error creating auto access task:", error);
|
|
|
|
+ res.status(500).json({ error: "Internal server error" });
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
-module.exports = router;
|
|
|
|
|
|
+module.exports = router;
|