import threading from flask import Blueprint, jsonify from model.Workflow import Workflow from worker.danmaku import do_workflow from model import db blueprint = Blueprint("api_workflow", __name__, url_prefix="/api/workflow") @blueprint.get("/") def get_workflow_list(): workflows = Workflow.query.all() return jsonify([d.to_dict() for d in workflows]) @blueprint.get("/") def get_workflow_info(workflow_id): workflow = Workflow.get(workflow_id) return jsonify(workflow) @blueprint.post("//edit") def start_editing(workflow_id): workflow = Workflow.get(workflow_id) if workflow is None: response = jsonify({ "message": "Not Found" }) response.status_code = 404 return response workflow.editing = True db.session.commit() return jsonify(workflow.to_dict()) @blueprint.delete("//edit") def done_editing(workflow_id): workflow = Workflow.get(workflow_id) if workflow is None: response = jsonify({ "message": "Not Found" }) response.status_code = 404 return response workflow.editing = False db.session.commit() return jsonify(workflow.to_dict()) @blueprint.post("//do") def do_workflow(workflow_id): workflow = Workflow.get(workflow_id) if workflow is None: response = jsonify({ "message": "Not Found" }) response.status_code = 404 return response if len(workflow.video_clips) > 0 and len(workflow.danmaku_clips) > 0: threading.Thread(target=do_workflow, args=( workflow.video_clips[0].full_path, workflow.danmaku_clips[0].full_path, *[clip.full_path for clip in workflow.danmaku_clips[1:]] )).start() return jsonify(workflow.to_dict())