Add spider and workflow visualization module entries and related route configurations.
Showing
3 changed files
with
61 additions
and
16 deletions
| @@ -83,11 +83,12 @@ app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(hours=2) | @@ -83,11 +83,12 @@ app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(hours=2) | ||
| 83 | from views.page import page | 83 | from views.page import page |
| 84 | from views.user import user | 84 | from views.user import user |
| 85 | from views.spider_control import spider_bp | 85 | from views.spider_control import spider_bp |
| 86 | -from views.workflow_api import workflow_bp | 86 | +from views.workflow_api import workflow_bp, workflow_api_bp |
| 87 | app.register_blueprint(page.pb) | 87 | app.register_blueprint(page.pb) |
| 88 | app.register_blueprint(user.ub) | 88 | app.register_blueprint(user.ub) |
| 89 | app.register_blueprint(spider_bp) | 89 | app.register_blueprint(spider_bp) |
| 90 | app.register_blueprint(workflow_bp) # 注册工作流蓝图 | 90 | app.register_blueprint(workflow_bp) # 注册工作流蓝图 |
| 91 | +app.register_blueprint(workflow_api_bp) # 注册工作流API蓝图 | ||
| 91 | 92 | ||
| 92 | # 首页路由 | 93 | # 首页路由 |
| 93 | @app.route('/') | 94 | @app.route('/') |
| @@ -115,6 +115,26 @@ | @@ -115,6 +115,26 @@ | ||
| 115 | <span class="ml-2" data-i18n="yuqingpredict">舆情预测</span> | 115 | <span class="ml-2" data-i18n="yuqingpredict">舆情预测</span> |
| 116 | </a> | 116 | </a> |
| 117 | </li> | 117 | </li> |
| 118 | + <li class="sidebar-layout"> | ||
| 119 | + <a href="/spider/control" class="svg-icon"> | ||
| 120 | + <i class=""> | ||
| 121 | + <svg xmlns="http://www.w3.org/2000/svg" width="18" fill="none" viewbox="0 0 24 24" stroke="currentColor"> | ||
| 122 | + <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"></path> | ||
| 123 | + </svg> | ||
| 124 | + </i> | ||
| 125 | + <span class="ml-2" data-i18n="spiderControl">爬虫可视化控制</span> | ||
| 126 | + </a> | ||
| 127 | + </li> | ||
| 128 | + <li class="sidebar-layout"> | ||
| 129 | + <a href="/workflow/editor" class="svg-icon"> | ||
| 130 | + <i class=""> | ||
| 131 | + <svg xmlns="http://www.w3.org/2000/svg" width="18" fill="none" viewbox="0 0 24 24" stroke="currentColor"> | ||
| 132 | + <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"></path> | ||
| 133 | + </svg> | ||
| 134 | + </i> | ||
| 135 | + <span class="ml-2" data-i18n="workflowEditor">流程可视化编排</span> | ||
| 136 | + </a> | ||
| 137 | + </li> | ||
| 118 | <li class=" sidebar-layout"> | 138 | <li class=" sidebar-layout"> |
| 119 | <a href="/page/articleCloud" class="svg-icon"> | 139 | <a href="/page/articleCloud" class="svg-icon"> |
| 120 | <i class=""> | 140 | <i class=""> |
| @@ -4,18 +4,27 @@ import time | @@ -4,18 +4,27 @@ import time | ||
| 4 | import uuid | 4 | import uuid |
| 5 | import logging | 5 | import logging |
| 6 | from datetime import datetime, timedelta | 6 | from datetime import datetime, timedelta |
| 7 | -from flask import Blueprint, request, jsonify, current_app | 7 | +from flask import Blueprint, request, jsonify, current_app, render_template |
| 8 | from utils.db_manager import DatabaseManager | 8 | from utils.db_manager import DatabaseManager |
| 9 | from utils.sensitive_filter import filter_dict | 9 | from utils.sensitive_filter import filter_dict |
| 10 | from utils.cache_manager import CacheManager | 10 | from utils.cache_manager import CacheManager |
| 11 | 11 | ||
| 12 | -workflow_bp = Blueprint('workflow', __name__, url_prefix='/api/workflow') | 12 | +# 创建两个蓝图:一个用于页面渲染,一个用于API |
| 13 | +workflow_bp = Blueprint('workflow', __name__, url_prefix='/workflow') | ||
| 14 | +workflow_api_bp = Blueprint('workflow_api', __name__, url_prefix='/api/workflow') | ||
| 15 | + | ||
| 13 | logger = logging.getLogger('workflow_api') | 16 | logger = logging.getLogger('workflow_api') |
| 14 | logger.setLevel(logging.INFO) | 17 | logger.setLevel(logging.INFO) |
| 15 | 18 | ||
| 16 | # 缓存管理器 | 19 | # 缓存管理器 |
| 17 | workflow_cache = CacheManager(name="workflows", memory_capacity=100, cache_duration=1) | 20 | workflow_cache = CacheManager(name="workflows", memory_capacity=100, cache_duration=1) |
| 18 | 21 | ||
| 22 | +# 添加工作流编辑器页面路由 | ||
| 23 | +@workflow_bp.route('/editor', methods=['GET']) | ||
| 24 | +def workflow_editor(): | ||
| 25 | + """渲染工作流编辑器页面""" | ||
| 26 | + return render_template('workflow_editor.html') | ||
| 27 | + | ||
| 19 | # 默认爬虫配置模板 | 28 | # 默认爬虫配置模板 |
| 20 | DEFAULT_CRAWLER_TEMPLATES = [ | 29 | DEFAULT_CRAWLER_TEMPLATES = [ |
| 21 | { | 30 | { |
| @@ -363,7 +372,7 @@ AVAILABLE_COMPONENTS = { | @@ -363,7 +372,7 @@ AVAILABLE_COMPONENTS = { | ||
| 363 | ] | 372 | ] |
| 364 | } | 373 | } |
| 365 | 374 | ||
| 366 | -@workflow_bp.route('/crawler-templates', methods=['GET']) | 375 | +@workflow_api_bp.route('/crawler-templates', methods=['GET']) |
| 367 | def get_crawler_templates(): | 376 | def get_crawler_templates(): |
| 368 | """获取爬虫配置模板列表""" | 377 | """获取爬虫配置模板列表""" |
| 369 | # 从缓存获取 | 378 | # 从缓存获取 |
| @@ -392,7 +401,7 @@ def get_crawler_templates(): | @@ -392,7 +401,7 @@ def get_crawler_templates(): | ||
| 392 | 'data': filter_dict(templates) | 401 | 'data': filter_dict(templates) |
| 393 | }) | 402 | }) |
| 394 | 403 | ||
| 395 | -@workflow_bp.route('/crawler-templates/<template_id>', methods=['GET']) | 404 | +@workflow_api_bp.route('/crawler-templates/<template_id>', methods=['GET']) |
| 396 | def get_crawler_template(template_id): | 405 | def get_crawler_template(template_id): |
| 397 | """获取指定爬虫配置模板""" | 406 | """获取指定爬虫配置模板""" |
| 398 | # 查找默认模板 | 407 | # 查找默认模板 |
| @@ -425,7 +434,7 @@ def get_crawler_template(template_id): | @@ -425,7 +434,7 @@ def get_crawler_template(template_id): | ||
| 425 | 'data': filter_dict(template) | 434 | 'data': filter_dict(template) |
| 426 | }) | 435 | }) |
| 427 | 436 | ||
| 428 | -@workflow_bp.route('/crawler-templates', methods=['POST']) | 437 | +@workflow_api_bp.route('/crawler-templates', methods=['POST']) |
| 429 | def create_crawler_template(): | 438 | def create_crawler_template(): |
| 430 | """创建爬虫配置模板""" | 439 | """创建爬虫配置模板""" |
| 431 | data = request.json | 440 | data = request.json |
| @@ -491,7 +500,7 @@ def create_crawler_template(): | @@ -491,7 +500,7 @@ def create_crawler_template(): | ||
| 491 | finally: | 500 | finally: |
| 492 | cursor.close() | 501 | cursor.close() |
| 493 | 502 | ||
| 494 | -@workflow_bp.route('/crawler-templates/<template_id>', methods=['PUT']) | 503 | +@workflow_api_bp.route('/crawler-templates/<template_id>', methods=['PUT']) |
| 495 | def update_crawler_template(template_id): | 504 | def update_crawler_template(template_id): |
| 496 | """更新爬虫配置模板""" | 505 | """更新爬虫配置模板""" |
| 497 | data = request.json | 506 | data = request.json |
| @@ -552,7 +561,7 @@ def update_crawler_template(template_id): | @@ -552,7 +561,7 @@ def update_crawler_template(template_id): | ||
| 552 | finally: | 561 | finally: |
| 553 | cursor.close() | 562 | cursor.close() |
| 554 | 563 | ||
| 555 | -@workflow_bp.route('/crawler-templates/<template_id>', methods=['DELETE']) | 564 | +@workflow_api_bp.route('/crawler-templates/<template_id>', methods=['DELETE']) |
| 556 | def delete_crawler_template(template_id): | 565 | def delete_crawler_template(template_id): |
| 557 | """删除爬虫配置模板""" | 566 | """删除爬虫配置模板""" |
| 558 | # 验证模板是否存在 | 567 | # 验证模板是否存在 |
| @@ -597,7 +606,7 @@ def delete_crawler_template(template_id): | @@ -597,7 +606,7 @@ def delete_crawler_template(template_id): | ||
| 597 | finally: | 606 | finally: |
| 598 | cursor.close() | 607 | cursor.close() |
| 599 | 608 | ||
| 600 | -@workflow_bp.route('/analysis-templates', methods=['GET']) | 609 | +@workflow_api_bp.route('/analysis-templates', methods=['GET']) |
| 601 | def get_analysis_templates(): | 610 | def get_analysis_templates(): |
| 602 | """获取分析流程模板列表""" | 611 | """获取分析流程模板列表""" |
| 603 | # 从缓存获取 | 612 | # 从缓存获取 |
| @@ -626,7 +635,7 @@ def get_analysis_templates(): | @@ -626,7 +635,7 @@ def get_analysis_templates(): | ||
| 626 | 'data': filter_dict(templates) | 635 | 'data': filter_dict(templates) |
| 627 | }) | 636 | }) |
| 628 | 637 | ||
| 629 | -@workflow_bp.route('/analysis-templates/<template_id>', methods=['GET']) | 638 | +@workflow_api_bp.route('/analysis-templates/<template_id>', methods=['GET']) |
| 630 | def get_analysis_template(template_id): | 639 | def get_analysis_template(template_id): |
| 631 | """获取指定分析流程模板""" | 640 | """获取指定分析流程模板""" |
| 632 | # 查找默认模板 | 641 | # 查找默认模板 |
| @@ -659,7 +668,7 @@ def get_analysis_template(template_id): | @@ -659,7 +668,7 @@ def get_analysis_template(template_id): | ||
| 659 | 'data': filter_dict(template) | 668 | 'data': filter_dict(template) |
| 660 | }) | 669 | }) |
| 661 | 670 | ||
| 662 | -@workflow_bp.route('/analysis-templates', methods=['POST']) | 671 | +@workflow_api_bp.route('/analysis-templates', methods=['POST']) |
| 663 | def create_analysis_template(): | 672 | def create_analysis_template(): |
| 664 | """创建分析流程模板""" | 673 | """创建分析流程模板""" |
| 665 | data = request.json | 674 | data = request.json |
| @@ -727,7 +736,7 @@ def create_analysis_template(): | @@ -727,7 +736,7 @@ def create_analysis_template(): | ||
| 727 | finally: | 736 | finally: |
| 728 | cursor.close() | 737 | cursor.close() |
| 729 | 738 | ||
| 730 | -@workflow_bp.route('/analysis-templates/<template_id>', methods=['PUT']) | 739 | +@workflow_api_bp.route('/analysis-templates/<template_id>', methods=['PUT']) |
| 731 | def update_analysis_template(template_id): | 740 | def update_analysis_template(template_id): |
| 732 | """更新分析流程模板""" | 741 | """更新分析流程模板""" |
| 733 | data = request.json | 742 | data = request.json |
| @@ -790,7 +799,7 @@ def update_analysis_template(template_id): | @@ -790,7 +799,7 @@ def update_analysis_template(template_id): | ||
| 790 | finally: | 799 | finally: |
| 791 | cursor.close() | 800 | cursor.close() |
| 792 | 801 | ||
| 793 | -@workflow_bp.route('/analysis-templates/<template_id>', methods=['DELETE']) | 802 | +@workflow_api_bp.route('/analysis-templates/<template_id>', methods=['DELETE']) |
| 794 | def delete_analysis_template(template_id): | 803 | def delete_analysis_template(template_id): |
| 795 | """删除分析流程模板""" | 804 | """删除分析流程模板""" |
| 796 | # 验证模板是否存在 | 805 | # 验证模板是否存在 |
| @@ -835,7 +844,7 @@ def delete_analysis_template(template_id): | @@ -835,7 +844,7 @@ def delete_analysis_template(template_id): | ||
| 835 | finally: | 844 | finally: |
| 836 | cursor.close() | 845 | cursor.close() |
| 837 | 846 | ||
| 838 | -@workflow_bp.route('/components', methods=['GET']) | 847 | +@workflow_api_bp.route('/components', methods=['GET']) |
| 839 | def get_available_components(): | 848 | def get_available_components(): |
| 840 | """获取可用组件列表""" | 849 | """获取可用组件列表""" |
| 841 | return jsonify({ | 850 | return jsonify({ |
| @@ -843,7 +852,7 @@ def get_available_components(): | @@ -843,7 +852,7 @@ def get_available_components(): | ||
| 843 | 'data': filter_dict(AVAILABLE_COMPONENTS) | 852 | 'data': filter_dict(AVAILABLE_COMPONENTS) |
| 844 | }) | 853 | }) |
| 845 | 854 | ||
| 846 | -@workflow_bp.route('/run-workflow', methods=['POST']) | 855 | +@workflow_api_bp.route('/run-workflow', methods=['POST']) |
| 847 | def run_workflow(): | 856 | def run_workflow(): |
| 848 | """执行工作流""" | 857 | """执行工作流""" |
| 849 | data = request.json | 858 | data = request.json |
| @@ -874,7 +883,7 @@ def run_workflow(): | @@ -874,7 +883,7 @@ def run_workflow(): | ||
| 874 | } | 883 | } |
| 875 | }) | 884 | }) |
| 876 | 885 | ||
| 877 | -@workflow_bp.route('/task-status/<task_id>', methods=['GET']) | 886 | +@workflow_api_bp.route('/task-status/<task_id>', methods=['GET']) |
| 878 | def get_task_status(task_id): | 887 | def get_task_status(task_id): |
| 879 | """获取任务执行状态""" | 888 | """获取任务执行状态""" |
| 880 | # 这里是获取任务状态的占位符 | 889 | # 这里是获取任务状态的占位符 |
| @@ -894,3 +903,18 @@ def get_task_status(task_id): | @@ -894,3 +903,18 @@ def get_task_status(task_id): | ||
| 894 | 'success': True, | 903 | 'success': True, |
| 895 | 'data': status | 904 | 'data': status |
| 896 | }) | 905 | }) |
| 906 | + | ||
| 907 | +@workflow_api_bp.route('/save', methods=['POST']) | ||
| 908 | +def save_workflow(): | ||
| 909 | + """保存工作流""" | ||
| 910 | + # ... existing code ... | ||
| 911 | + | ||
| 912 | +@workflow_api_bp.route('/<workflow_id>', methods=['GET']) | ||
| 913 | +def get_workflow(workflow_id): | ||
| 914 | + """获取工作流""" | ||
| 915 | + # ... existing code ... | ||
| 916 | + | ||
| 917 | +@workflow_api_bp.route('/<workflow_id>', methods=['DELETE']) | ||
| 918 | +def delete_workflow(workflow_id): | ||
| 919 | + """删除工作流""" | ||
| 920 | + # ... existing code ... |
-
Please register or login to post a comment