From d579a10ba169d6e95e8ea8a9d7f2821fe89bca1f Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 17 Jul 2020 18:03:08 +0200 Subject: media form tweaks. copy a media item to avoid typing in properties. --- .../cli/app/controllers/upload_controller.py | 26 +++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'animism-align/cli/app/controllers/upload_controller.py') diff --git a/animism-align/cli/app/controllers/upload_controller.py b/animism-align/cli/app/controllers/upload_controller.py index 1a324cb..e910f28 100644 --- a/animism-align/cli/app/controllers/upload_controller.py +++ b/animism-align/cli/app/controllers/upload_controller.py @@ -86,10 +86,18 @@ class UploadView(FlaskView): # except: # return jsonify({ 'status': 'error', 'error': 'Image parse error' }) + uploaded_im_fn = secure_filename(file.filename) + uploaded_im_abspath = os.path.join(app_cfg.DIR_UPLOADS, tag) + uploaded_im_fullpath = os.path.join(uploaded_im_abspath, uploaded_im_fn) + session = Session() upload = session.query(Upload).filter_by(sha256=sha256).first() if upload is not None: print("Already uploaded image") + if not os.path.exists(uploaded_im_fullpath): + # if we got in some weird state where the record wasnt deleted.... + os.makedirs(uploaded_im_abspath, exist_ok=True) + file.save(uploaded_im_fullpath) response = { 'status': 'ok', 'notes': 'Image already uploaded', @@ -98,16 +106,10 @@ class UploadView(FlaskView): session.close() return jsonify(response) - uploaded_im_fn = secure_filename(file.filename) - uploaded_im_abspath = os.path.join(app_cfg.DIR_UPLOADS, tag) - uploaded_im_fullpath = os.path.join(uploaded_im_abspath, uploaded_im_fn) - uploaded_im_stored_fn = uploaded_im_fn - os.makedirs(uploaded_im_abspath, exist_ok=True) - # nparr.tofile(uploaded_im_fullpath) file.save(uploaded_im_fullpath) - upload = Upload(username=username, tag=tag, fn=uploaded_im_stored_fn, sha256=sha256, ext=ext) + upload = Upload(username=username, tag=tag, fn=uploaded_im_fn, sha256=sha256, ext=ext) session.add(upload) session.commit() response = { @@ -135,11 +137,13 @@ class UploadView(FlaskView): tag = upload.tag # uploaded_im_fn = secure_filename(fn) - uploaded_im_abspath = os.path.join(app_cfg.DIR_UPLOADS, tag, fn) + uploaded_im_abspath = os.path.join(app_cfg.DIR_UPLOADS, tag) + uploaded_im_fullpath = os.path.join(uploaded_im_abspath, fn) + # uploaded_im_fullpath = os.path.join(uploaded_im_abspath, fn) - if os.path.exists(uploaded_im_abspath): - print("Removing " + uploaded_im_abspath) - os.remove(uploaded_im_abspath) + if os.path.exists(uploaded_im_fullpath): + print("Removing " + uploaded_im_fullpath) + os.remove(uploaded_im_fullpath) session.delete(upload) session.commit() -- cgit v1.2.3-70-g09d2