From 2498f142782e26681c542dfca4b3f9fc4ff64808 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Thu, 29 Oct 2020 19:45:05 +0100 Subject: Clean up leftover file path references This change removes and direct references to the filesystem from the pyfbin code other that file_storage.filesystem. This should hopyfully be the last changes needed for pyfbin to be successfully run using the file_storage.s3 module without any issues. --- fbin/fbin.py | 42 ++++-------------------------------------- 1 file changed, 4 insertions(+), 38 deletions(-) (limited to 'fbin/fbin.py') diff --git a/fbin/fbin.py b/fbin/fbin.py index ac4569e..04857d9 100755 --- a/fbin/fbin.py +++ b/fbin/fbin.py @@ -36,14 +36,6 @@ base62_alphabet = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXY if not os.path.isdir(current_app.config['THUMB_DIRECTORY']): os.mkdir(current_app.config['THUMB_DIRECTORY']) -try: - # Throws OSError if mogrify doesn't exist. - subprocess.call(['mogrify', '-quiet']) -except OSError: - has_mogrify = False -else: - has_mogrify = True - def get_or_create_user(username, jab_id): try: return db.session.query(User).filter(User.jab_id == jab_id).one() @@ -84,11 +76,7 @@ def get_files(user): def delete_file(file): db.session.delete(file) db.session.commit() - filename = file.get_path() storage.delete_file(file) - thumbfile = file.get_thumb_path() - if os.path.exists(thumbfile): - os.unlink(thumbfile) app = Blueprint('fbin', __name__) @@ -138,14 +126,6 @@ def upload(api=False, user=None): except StorageError as e: return error(str(e)) - mime = new_file.get_mime_type() - # TODO: Apparently TIFF also supports EXIF, test this. - if has_mogrify and mime == 'image/jpeg': - # NOTE: PIL doesn't support lossless rotation, so we call mogrify to do this. - # NOTE: This changes the file, so the file_hash applies to the ORIGINAL file contents only. - # NOTE: The file hash is only used to detect duplicates when uploading, so this should not be a problem. - subprocess.call(['mogrify', '-auto-orient', new_file.get_path()]) - if api: return jsonify({ 'status': True, @@ -196,7 +176,7 @@ def _file(hash, ext=None, filename=None): return path if not path or not os.path.exists(path): abort(404) - return send_file(path) + return send_file(path, attachment_filename=f.filename) @app.route('/l') @app.route('/login') @@ -287,7 +267,7 @@ def files(): context = { 'title': 'Files', 'files': files, - 'total_size': File.pretty_size(sum(size for size in (f.get_size() for f in files) if size is not None)), + 'total_size': File.pretty_size(sum(size for size in (f.size for f in files) if size is not None)), } return render_template('files.html', **context) @@ -300,22 +280,8 @@ def file_edit(): flash('File not found.', 'error') return redirect(url_for('.files')) if 'filename' in request.form: - old_path = f.get_path() filename = request.form.get('filename', f.filename) f.filename = filename - new_path = f.get_path() - # If extension changed, the local filename also changes. We could just store the file without the extension, - # but that would break the existing files, requiring a manual rename. - if old_path != new_path: - try: - if os.path.exists(new_path): - # This shouldn't happen unless we have two files with the same hash, which should be impossible. - raise RuntimeError() - else: - os.rename(old_path, new_path) - except: - flash(Markup('Internal rename failed; file may have become unreachable. ' - 'Please contact an admin and specify hash={}.'.format(f.hash)), 'error') db.session.add(f) flash('Filename changed to "{}".'.format(f.filename), 'success') elif 'delete' in request.form: @@ -338,7 +304,7 @@ def images(): 'title': 'Images', 'fullwidth': True, 'files': files, - 'total_size': File.pretty_size(sum(size for size in (f.get_size() for f in files) if size is not None)), + 'total_size': File.pretty_size(sum(size for size in (f.size for f in files) if size is not None)), } return render_template('images.html', **context) @@ -351,7 +317,7 @@ def videos(): 'title': 'Videos', 'fullwidth': True, 'files': files, - 'total_size': File.pretty_size(sum(size for size in (f.get_size() for f in files) if size is not None)), + 'total_size': File.pretty_size(sum(size for size in (f.size for f in files) if size is not None)), } return render_template('images.html', **context) -- cgit v1.2.3