Fix request mimetype for POST upload

This commit is contained in:
ABelliqueux 2022-12-05 13:19:43 +01:00
parent 3cbf858e6b
commit 670b183d04
1 changed files with 25 additions and 24 deletions

11
app.py
View File

@ -27,7 +27,7 @@ for location in config_locations:
if app.config.from_file(os.path.expanduser(location + "pilpil-client.toml"), load=toml.load, silent=True): if app.config.from_file(os.path.expanduser(location + "pilpil-client.toml"), load=toml.load, silent=True):
print(_("Found configuration file in {}").format(os.path.expanduser(location))) print(_("Found configuration file in {}").format(os.path.expanduser(location)))
upload_folder = os.path.expanduser(app.config['DEFAULT']['media_folder_local']) upload_folder = os.path.join(os.path.expanduser(app.config['DEFAULT']['media_folder_local']), "")
media_exts = app.config['DEFAULT']['media_exts'] media_exts = app.config['DEFAULT']['media_exts']
HTTP_secret = str(app.config['DEFAULT']['auth']) HTTP_secret = str(app.config['DEFAULT']['auth'])
debug = app.config['DEFAULT']['debug'] debug = app.config['DEFAULT']['debug']
@ -55,6 +55,7 @@ if debug:
upload_candidates = {} upload_candidates = {}
@auth.verify_password @auth.verify_password
def verify_password(username, password): def verify_password(username, password):
''' '''
@ -163,8 +164,6 @@ def list_media_files(folder):
# TODO : Return a dict list [{"filename":"foo", "size":-1}, {...}] # TODO : Return a dict list [{"filename":"foo", "size":-1}, {...}]
fd_size = os.stat(folder + fd).st_size fd_size = os.stat(folder + fd).st_size
file_dict = {"filename": fd, "size": fd_size} file_dict = {"filename": fd, "size": fd_size}
if debug:
print(str(file_dict))
medias.append(file_dict) medias.append(file_dict)
return medias return medias
else: else:
@ -221,14 +220,15 @@ def upload_file(over_write=1):
global upload_candidates global upload_candidates
media_files = list_media_files(upload_folder) media_files = list_media_files(upload_folder)
if debug: if debug:
print("Existing files : {}".format(str(list_media_files(upload_folder)))) print("Upload candidates : {}".format(str(list_media_files(upload_folder))))
if request.method == "GET": if request.method == "GET":
# Send candidates list # Send candidates list
if debug: if debug:
print("GET :" + str(upload_candidates)) print("GET :" + str(upload_candidates))
return upload_candidates return upload_candidates
if request.method == "POST": if request.method == "POST":
if request.get_json(): if request.is_json:
print("HERE")
# JSON received, parse it # JSON received, parse it
upload_candidates = request.get_json() upload_candidates = request.get_json()
# ~ upload_candidates = [candidate for candidate in upload_candidates if candidate not in media_files] # ~ upload_candidates = [candidate for candidate in upload_candidates if candidate not in media_files]
@ -246,6 +246,7 @@ def upload_file(over_write=1):
if debug: if debug:
print("POST :" + str(upload_candidates)) print("POST :" + str(upload_candidates))
return upload_candidates return upload_candidates
else:
# Check if the post request has the file part # Check if the post request has the file part
if "file" not in request.files: if "file" not in request.files:
return _("No file part: {}").format(str(request.files)) return _("No file part: {}").format(str(request.files))