This commit is contained in:
wataru 2022-09-14 07:19:02 +09:00
parent 98965b08ae
commit 07595fd060

View File

@ -98,55 +98,51 @@ def api():
print(traceback.format_exc())
return str(e)
@app.route('/api/voice/<string:title>/<string:prefix>/<int:index>', methods=['POST'])
def post_voice(title, prefix, index):
try:
filename = f"{prefix}{index:03}.zip"
data_dir = os.path.join(DATA_ROOT, title)
os.makedirs(data_dir,exist_ok=True)
fullpath = os.path.join(data_dir, filename)
data = base64.b64decode(request.json['data'])
f = open(fullpath, 'wb')
f.write(data)
f.close()
data = {
"message":"OK"
}
return jsonify(data)
except Exception as e:
print("REQUEST PROCESSING!!!! EXCEPTION!!!", e)
print(traceback.format_exc())
return str(e)
@app.route('/api/voice/<string:title>/<string:prefix>/<int:index>', methods=['GET'])
def get_voice(title, prefix, index):
filename = f"{prefix}{index:03}.zip"
data_dir = os.path.join(DATA_ROOT, title)
fullpath = os.path.join(data_dir, filename)
## !!!!!!!!!!! COLABのプロキシがRoot直下のパスしか通さない??? !!!!!!
## !!!!!!!!!!! Bodyで参照、設定コマンドを代替する。 !!!!!!
# @app.route('/api/voice/<string:title>/<string:prefix>/<int:index>', methods=['POST'])
# def post_voice(title, prefix, index):
# try:
# filename = f"{prefix}{index:03}.zip"
# data_dir = os.path.join(DATA_ROOT, title)
# os.makedirs(data_dir,exist_ok=True)
# fullpath = os.path.join(data_dir, filename)
# data = base64.b64decode(request.json['data'])
# f = open(fullpath, 'wb')
# f.write(data)
# f.close()
# data = {
# "message":"OK"
# }
# return jsonify(data)
# except Exception as e:
# print("REQUEST PROCESSING!!!! EXCEPTION!!!", e)
# print(traceback.format_exc())
# return str(e)
is_file = os.path.isfile(fullpath)
if is_file == False:
data = {
"message":"NOT_FOUND",
}
return jsonify(data)
# @app.route('/api/voice/<string:title>/<string:prefix>/<int:index>', methods=['GET'])
# def get_voice(title, prefix, index):
# filename = f"{prefix}{index:03}.zip"
# data_dir = os.path.join(DATA_ROOT, title)
# fullpath = os.path.join(data_dir, filename)
f = open(fullpath, 'rb')
data = f.read()
dataBase64 = base64.b64encode(data).decode('utf-8')
data = {
"message":"OK",
"data":dataBase64,
}
return jsonify(data)
# is_file = os.path.isfile(fullpath)
# if is_file == False:
# data = {
# "message":"NOT_FOUND",
# }
# return jsonify(data)
# f = open(fullpath, 'rb')
# data = f.read()
# dataBase64 = base64.b64encode(data).decode('utf-8')
# data = {
# "message":"OK",
# "data":dataBase64,
# }
# return jsonify(data)
# @app.after_request
# def after_request(response):
# # response.headers.add('Access-Control-Allow-Origin', '*')
# response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
# response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS')
# return response
if __name__ == '__main__':