sphinx-web/src/api/api_document.py

37 lines
997 B
Python

from flask import Blueprint, request
from web_utils.get_arg import get_arg
from web_utils.business_exception import BusinessException
import os
from data.document import Document
bp = Blueprint('api_document', __name__, url_prefix='/api/doc')
@bp.route('/build')
def build():
origin = get_arg('origin')
doc_name = get_arg('doc_name')
branch = get_arg('branch', 'master')
apikey = get_arg('apikey')
doc = Document(origin, doc_name, branch)
if doc.get_api_key() != apikey:
raise BusinessException("Invalid API key")
build_task = doc.build()
build_task.join()
return build_task.get_output_str().replace('\n', '<br/>')
@bp.route('/clone')
def clone():
repo = get_arg('repo')
doc_name = get_arg('doc_name', os.path.splitext(os.path.basename(repo))[0])
branch = get_arg('branch', 'master')
source_dir = get_arg('source', 'source')
clone_task = Document.clone(repo, branch, doc_name, source_dir)
clone_task.join()
return clone_task.get_output_str().replace('\n', '<br/>')