danmakuClip删查改接口,videoClip删除接口
This commit is contained in:
parent
6a1fa26ba5
commit
aa08acaa2d
2
app.py
2
app.py
@ -6,6 +6,7 @@ from controller.api.collector_blueprint import blueprint as api_collector_bluepr
|
|||||||
from controller.api.bilirecorder_blueprint import blueprint as api_bilirecorder_blueprint
|
from controller.api.bilirecorder_blueprint import blueprint as api_bilirecorder_blueprint
|
||||||
from controller.api.workflow_blueprint import blueprint as api_workflow_blueprint
|
from controller.api.workflow_blueprint import blueprint as api_workflow_blueprint
|
||||||
from controller.api.video_clip_blueprint import blueprint as api_video_clip_blueprint
|
from controller.api.video_clip_blueprint import blueprint as api_video_clip_blueprint
|
||||||
|
from controller.api.danmaku_clip_blueprint import blueprint as api_danmaku_clip_blueprint
|
||||||
from model import db
|
from model import db
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
@ -23,6 +24,7 @@ app.register_blueprint(api_collector_blueprint)
|
|||||||
app.register_blueprint(api_bilirecorder_blueprint)
|
app.register_blueprint(api_bilirecorder_blueprint)
|
||||||
app.register_blueprint(api_workflow_blueprint)
|
app.register_blueprint(api_workflow_blueprint)
|
||||||
app.register_blueprint(api_video_clip_blueprint)
|
app.register_blueprint(api_video_clip_blueprint)
|
||||||
|
app.register_blueprint(api_danmaku_clip_blueprint)
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
# db.drop_all(app=app)
|
# db.drop_all(app=app)
|
||||||
db.create_all(app=app)
|
db.create_all(app=app)
|
||||||
|
56
controller/api/danmaku_clip_blueprint.py
Normal file
56
controller/api/danmaku_clip_blueprint.py
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from flask import Blueprint, jsonify, request
|
||||||
|
|
||||||
|
from model.DanmakuClip import DanmakuClip
|
||||||
|
from util.flask import not_found_json_response, error_json_response
|
||||||
|
from model import db
|
||||||
|
|
||||||
|
blueprint = Blueprint("api_danmaku_clip", __name__, url_prefix="/api/danmaku_clip")
|
||||||
|
|
||||||
|
|
||||||
|
@blueprint.get("/<int:danmaku_clip_id>")
|
||||||
|
def get_danmaku_clip_info(danmaku_clip_id):
|
||||||
|
danmaku_clip = DanmakuClip.query.get(danmaku_clip_id)
|
||||||
|
if danmaku_clip is None:
|
||||||
|
return not_found_json_response(id=danmaku_clip_id)
|
||||||
|
return jsonify(danmaku_clip.to_json())
|
||||||
|
|
||||||
|
|
||||||
|
@blueprint.put("/<int:danmaku_clip_id>")
|
||||||
|
def modify_danmaku_clip_info(danmaku_clip_id):
|
||||||
|
danmaku_clip = DanmakuClip.query.get(danmaku_clip_id)
|
||||||
|
if danmaku_clip is None:
|
||||||
|
return not_found_json_response(id=danmaku_clip_id)
|
||||||
|
payload = request.json
|
||||||
|
if "workflow_id" in payload:
|
||||||
|
try:
|
||||||
|
workflow_id = int(payload["workflow_id"])
|
||||||
|
danmaku_clip.workflow_id = workflow_id
|
||||||
|
except ValueError:
|
||||||
|
return error_json_response("workflow_id is not a int", workflow_id=payload["workflow_id"])
|
||||||
|
if "base_path" in payload:
|
||||||
|
if not os.path.isdir(payload["base_path"]):
|
||||||
|
return error_json_response("base_path is not a dir", base_path=payload["base_path"])
|
||||||
|
danmaku_clip.base_path = payload["base_path"]
|
||||||
|
if "file" in payload:
|
||||||
|
if os.path.isabs(payload["file"]):
|
||||||
|
danmaku_clip.base_path = ""
|
||||||
|
danmaku_clip.file = payload["file"]
|
||||||
|
# file exist check
|
||||||
|
if not os.path.isfile(danmaku_clip.full_path):
|
||||||
|
return error_json_response("file not exist", full_path=danmaku_clip.full_path)
|
||||||
|
db.session.commit()
|
||||||
|
return jsonify(danmaku_clip.to_json())
|
||||||
|
|
||||||
|
|
||||||
|
@blueprint.delete("/<int:danmaku_clip_id>")
|
||||||
|
def delete_video_clip(danmaku_clip_id):
|
||||||
|
danmaku_clip = DanmakuClip.query.get(danmaku_clip_id)
|
||||||
|
if danmaku_clip is not None:
|
||||||
|
db.session.delete(danmaku_clip)
|
||||||
|
db.session.commit()
|
||||||
|
return jsonify({
|
||||||
|
"id": danmaku_clip_id,
|
||||||
|
"old_data": danmaku_clip
|
||||||
|
})
|
@ -45,4 +45,16 @@ def modify_video_clip(video_clip_id):
|
|||||||
duration = duration_str_to_float(get_video_real_duration(video_clip.full_path))
|
duration = duration_str_to_float(get_video_real_duration(video_clip.full_path))
|
||||||
video_clip.duration = duration
|
video_clip.duration = duration
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return jsonify(video_clip.to_json())
|
return jsonify(video_clip.to_json())
|
||||||
|
|
||||||
|
|
||||||
|
@blueprint.delete("/<int:video_clip_id>")
|
||||||
|
def delete_video_clip(video_clip_id):
|
||||||
|
video_clip = VideoClip.query.get(video_clip_id)
|
||||||
|
if video_clip is not None:
|
||||||
|
db.session.delete(video_clip)
|
||||||
|
db.session.commit()
|
||||||
|
return jsonify({
|
||||||
|
"id": video_clip_id,
|
||||||
|
"old_data": video_clip
|
||||||
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user