Fixed browser profile bug, line breaks and exceptions in news_check

This commit is contained in:
2022-09-26 15:25:55 +02:00
parent db161e50c8
commit 9349b046d2
12 changed files with 150 additions and 319 deletions

View File

@@ -53,11 +53,14 @@ def get_article_next(id):
@app.route("/api/article/<int:id>/set", methods=['POST'])
def set_article(id):
try:
action = request.json.get('action', None)
except Exception as e:
print(f"Exception in set_article {e}")
json = request.get_json(silent=True) # do not raise 400 if there is no json!
# no json usually means a file was uploaded
if json is None:
print("Detected likely file upload.")
action = None
else:
action = request.json.get('action', None) # action inside the json might still be empty
with db:
article = models.ArticleDownload.get_by_id(id)
if action:
@@ -66,7 +69,7 @@ def set_article(id):
elif action == "b":
article.verified = -1
else: # implicitly action == "r":
print(request.files)
# request.files is an immutable dict
file = request.files.get("file", None)
if file is None: # upload tends to crash
return "No file uploaded", 400
@@ -74,7 +77,7 @@ def set_article(id):
artname, _ = os.path.splitext(article.file_name)
fname = f"{artname} -- related_{article.related.count() + 1}.{file.filename.split('.')[-1]}"
fpath = os.path.join(article.save_path, fname)
print(fpath)
print(f"Saving file to {fpath}")
file.save(fpath)
article.set_related([fname])
return {"file_path": fpath}