From a9dd6bf1e76305ec55d93cbd1ba8a90411aecf8c Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Tue, 11 Oct 2022 19:26:38 +0200 Subject: [PATCH] add a media check --- files/helpers/media.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/files/helpers/media.py b/files/helpers/media.py index 434731202..d078489e9 100644 --- a/files/helpers/media.py +++ b/files/helpers/media.py @@ -47,6 +47,9 @@ def process_audio(file): os.remove(name) abort(413) + media = g.db.query(Media).filter_by(filename=name, kind='audio').one_or_none() + if media: g.db.delete(media) + media = Media( kind='audio', filename=name, @@ -67,6 +70,10 @@ def webm_to_mp4(old, new, vid): data=f'{{"files": ["{SITE_FULL}{new}"]}}', timeout=5) db = db_session() + + media = db.query(Media).filter_by(filename=name, kind='video').one_or_none() + if media: db.delete(media) + media = Media( kind='video', filename=new, @@ -100,6 +107,9 @@ def process_video(file): subprocess.run(["ffmpeg", "-y", "-loglevel", "warning", "-nostats", "-i", old, "-map_metadata", "-1", "-c:v", "copy", "-c:a", "copy", new], check=True) os.remove(old) + media = g.db.query(Media).filter_by(filename=name, kind='video').one_or_none() + if media: g.db.delete(media) + media = Media( kind='video', filename=new, @@ -174,13 +184,17 @@ def process_image(filename=None, resize=0, trim=False, uploader=None, patron=Fal os.remove(filename) abort(417) + db = db or g.db + + media = db.query(Media).filter_by(filename=name, kind='image').one_or_none() + if media: db.delete(media) + media = Media( kind='image', filename=filename, user_id=uploader or g.v.id, size=os.stat(filename).st_size ) - db = db or g.db db.add(media) return filename