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()) print(traceback.format_exc())
return str(e) 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']) ## !!!!!!!!!!! COLABのプロキシがRoot直下のパスしか通さない??? !!!!!!
def get_voice(title, prefix, index): ## !!!!!!!!!!! Bodyで参照、設定コマンドを代替する。 !!!!!!
filename = f"{prefix}{index:03}.zip" # @app.route('/api/voice/<string:title>/<string:prefix>/<int:index>', methods=['POST'])
data_dir = os.path.join(DATA_ROOT, title) # def post_voice(title, prefix, index):
fullpath = os.path.join(data_dir, filename) # 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) # @app.route('/api/voice/<string:title>/<string:prefix>/<int:index>', methods=['GET'])
if is_file == False: # def get_voice(title, prefix, index):
data = { # filename = f"{prefix}{index:03}.zip"
"message":"NOT_FOUND", # data_dir = os.path.join(DATA_ROOT, title)
} # fullpath = os.path.join(data_dir, filename)
return jsonify(data)
f = open(fullpath, 'rb') # is_file = os.path.isfile(fullpath)
data = f.read() # if is_file == False:
dataBase64 = base64.b64encode(data).decode('utf-8') # data = {
data = { # "message":"NOT_FOUND",
"message":"OK", # }
"data":dataBase64, # return jsonify(data)
}
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__': if __name__ == '__main__':