yuripeyamashita's picture
Update app.py
7b910fd verified
raw
history blame
1.31 kB
from flask import Flask, request
from uuid import uuid4
import os, json
import requests
app = Flask(__name__)
secret = os.environ.get("auth")
headers = {'Authorization': os.environ.get("auth")}
res_dict = {}
@app.route('/queue', methods=['POST'])
def queue():
if request.json.get('secret') != secret:
return {}, 400
uuid = str(uuid4())
res_dict[uuid] = request.json
return { 'uuid': uuid }, 200
@app.route('/asr', methods=['GET'])
def asr():
uuid = request.args.get('uuid')
data = res_dict.get(uuid)
if not data:
return {}, 400
URL = data.get('URL')
body = data.get('body')
res = requests.post(URL, json=body, headers=headers)
if res.status_code == 200:
callbackURL = data.get('callbackURL')
requests.get(callbackURL)
return res.json()
return {'error': '請求失敗'}, 500
# @app.route('/client', methods=['POST'])
# def client():
# token = request.json.get('token')
# data = reqList.get(token)
# if not data:
# return {}, 400
# print(data)
# URL = data.get('URL')
# postData = data.get('postData')
# response = requests.post(URL, json=postData)
# return response.json()
if __name__ == "__main__":
app.run(host="0.0.0.0", port=7860)