summaryrefslogtreecommitdiff
path: root/fbin/fbin.py
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2020-10-29 19:45:05 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2020-10-29 19:45:05 +0100
commit2498f142782e26681c542dfca4b3f9fc4ff64808 (patch)
tree24d63a549fd0a4d4ab039d3b0924f8c611d439c2 /fbin/fbin.py
parentb1ed551c3125278d14a69750fea2bfe39cf68530 (diff)
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.
Diffstat (limited to 'fbin/fbin.py')
-rwxr-xr-xfbin/fbin.py42
1 files changed, 4 insertions, 38 deletions
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 <strong>hash={}</strong>.'.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)