diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2020-07-17 18:03:08 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2020-07-17 18:03:08 +0200 |
| commit | d579a10ba169d6e95e8ea8a9d7f2821fe89bca1f (patch) | |
| tree | 324467ca4045bc09a0e8ad84d229a55ee5da60cc /animism-align/cli/app/controllers/upload_controller.py | |
| parent | 3b8ca4ae366ad8925ded787f87350862ef18e0ca (diff) | |
media form tweaks. copy a media item to avoid typing in properties.
Diffstat (limited to 'animism-align/cli/app/controllers/upload_controller.py')
| -rw-r--r-- | animism-align/cli/app/controllers/upload_controller.py | 26 |
1 files changed, 15 insertions, 11 deletions
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() |
