From 140318e946829aed6d718c254a92f835712a02d5 Mon Sep 17 00:00:00 2001
From: Aevann
Date: Sun, 7 Apr 2024 07:29:19 +0200
Subject: [PATCH] stop inline video posters from becoming unused when editing
comment/post
---
files/classes/media.py | 3 ++-
files/helpers/media.py | 5 ++---
files/helpers/regex.py | 9 ++++++---
...07-stop-posters-from-getting-removed-when-editing.sql | 3 +++
4 files changed, 13 insertions(+), 7 deletions(-)
create mode 100644 migrations/20240407-stop-posters-from-getting-removed-when-editing.sql
diff --git a/files/classes/media.py b/files/classes/media.py
index 574c0a3c4..fb274ee89 100644
--- a/files/classes/media.py
+++ b/files/classes/media.py
@@ -6,11 +6,12 @@ from files.classes import Base
class Media(Base):
__tablename__ = "media"
- kind = Column(String, primary_key=True)
filename = Column(String, primary_key=True)
+ kind = Column(String)
user_id = Column(Integer, ForeignKey("users.id"))
created_utc = Column(Integer)
size = Column(Integer)
+ posterurl = Column(String)
def __init__(self, *args, **kwargs):
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())
diff --git a/files/helpers/media.py b/files/helpers/media.py
index c160b9888..0d862adfa 100644
--- a/files/helpers/media.py
+++ b/files/helpers/media.py
@@ -48,7 +48,6 @@ def media_ratelimit(v):
def process_files(files, v, body, is_dm=False, dm_user=None, is_badge_thread=False, comment_body=None):
if g.is_tor or not files.get("file"): return body
- g.posterurls = {}
files = files.getlist('file')[:20]
@@ -67,8 +66,7 @@ def process_files(files, v, body, is_dm=False, dm_user=None, is_badge_thread=Fal
if is_badge_thread:
process_badge_entry(name, v, comment_body)
elif file.content_type.startswith('video/'):
- url, posterurl, name = process_video(file, v)
- g.posterurls[url] = posterurl
+ url, _, _ = process_video(file, v)
elif file.content_type.startswith('audio/'):
url = f'{SITE_FULL}{process_audio(file, v)}'
elif has_request_context():
@@ -218,6 +216,7 @@ def process_video(file, v):
name = f'/images/{time.time()}'.replace('.','') + '.webp'
ffmpeg.input(new).output(name, loglevel="quiet", map_metadata=-1, **{"vf":"scale='iw':-2", 'q:v':3, 'frames:v':1}).run()
posterurl = SITE_FULL_IMAGES + name
+ media.posterurl = posterurl
if SITE == 'watchpeopledie.tv' and not is_reencoding:
gevent.spawn(rclone_copy, new)
diff --git a/files/helpers/regex.py b/files/helpers/regex.py
index 2f47926e0..d9602c361 100644
--- a/files/helpers/regex.py
+++ b/files/helpers/regex.py
@@ -2,6 +2,7 @@ import random
import re
from flask import g
+from files.classes.media import Media
from .config.const import *
NOT_IN_CODE_OR_LINKS = '(?!([^<]*<\/(code|pre|a)>|[^`\n]*`))'
@@ -107,10 +108,12 @@ video_sub_regex = re.compile(f'(?
'
+ return f''
return f''
audio_regex_extensions = '|'.join(AUDIO_FORMATS)
diff --git a/migrations/20240407-stop-posters-from-getting-removed-when-editing.sql b/migrations/20240407-stop-posters-from-getting-removed-when-editing.sql
new file mode 100644
index 000000000..7603dae69
--- /dev/null
+++ b/migrations/20240407-stop-posters-from-getting-removed-when-editing.sql
@@ -0,0 +1,3 @@
+alter table media add column posterurl varchar(65);
+alter table media drop constraint media_pkey;
+alter table media add primary key (filename);