From f0e6814384415d212ca1754d5bca975c3fa77ad0 Mon Sep 17 00:00:00 2001 From: Aevann Date: Wed, 16 Aug 2023 23:13:24 +0300 Subject: [PATCH] add file orgies --- files/assets/css/orgy.css | 40 ++++++++++++----- files/assets/js/orgy_file.js | 22 +++++++++ files/classes/orgy.py | 51 ++++----------------- files/routes/admin.py | 40 ++++++++++++++--- files/templates/admin/orgy_control.html | 2 +- files/templates/orgy.html | 60 ++++++++++++------------- migrations/20230816-add-file-orgies.sql | 7 +++ 7 files changed, 131 insertions(+), 91 deletions(-) create mode 100644 files/assets/js/orgy_file.js create mode 100644 migrations/20230816-add-file-orgies.sql diff --git a/files/assets/css/orgy.css b/files/assets/css/orgy.css index 20d53958c..135b2eae2 100644 --- a/files/assets/css/orgy.css +++ b/files/assets/css/orgy.css @@ -7,31 +7,49 @@ .orgy-top-container { flex-flow: column wrap; } - .orgy-info-window-item { - max-height: 20% !important; - height: 20% !important; - } .orgy-chat-window-item { max-height: 80% !important; height: 80% !important; } } @media all and (min-width: 900px) { - .orgy-top-container { - flex-flow: row nowrap; + .orgy-chat-window-item { + max-width: max(30vw, calc(100vw - 1080px)); } } .orgy-chat-window-item { flex-grow: 2; - width: fit-content; -} -.orgy-info-window-item { - max-width: 550px; - width: 550px; } + .rumble-player { aspect-ratio: 16/9; max-width: min(70vw,500px) !important; width: 500px; } + +#orgy-file-container { + position: relative; + width: -webkit-fill-available; + max-width: 1080px !important; + z-index: 1000000004; +} +@media all and (max-width: 900px) { + #orgy-file-container { + width: 100% !important; + } +} + +#orgy-file-container > video { + max-height: initial !important; +} + +#cursormarsey, #cursormarsey-heart { + display: none; +} + +body > .container { + padding: 0 !important; + margin: 0 !important; + margin-right: 0 !important; +} diff --git a/files/assets/js/orgy_file.js b/files/assets/js/orgy_file.js new file mode 100644 index 000000000..1261b5a02 --- /dev/null +++ b/files/assets/js/orgy_file.js @@ -0,0 +1,22 @@ +const orgy_file = document.getElementById('orgy-file'); + +addEventListener("load", () => { + orgy_file.play() +}); +document.addEventListener('click', () => { + if (orgy_file.paused) orgy_file.play(); +}, {once : true}); + +function add_playing_listener() { + orgy_file.addEventListener('playing', () => { + const now = Date.now() / 1000; + const created_utc = orgy_file.dataset.created_utc + orgy_file.currentTime = now - created_utc + }, {once : true}); +} + +add_playing_listener() + +orgy_file.addEventListener('pause', () => { + add_playing_listener() +}) diff --git a/files/classes/orgy.py b/files/classes/orgy.py index 8307be00c..c4308296f 100644 --- a/files/classes/orgy.py +++ b/files/classes/orgy.py @@ -1,60 +1,25 @@ import time -from flask import g +from flask import g, abort from sqlalchemy import Column from sqlalchemy.sql.sqltypes import * from files.classes import Base -from files.helpers.config.const import * -from files.helpers.regex import * -from files.helpers.sanitize import normalize_url, get_youtube_id_and_t class Orgy(Base): __tablename__ = "orgies" - id = Column(Integer, primary_key = True) - type = Column(Integer, primary_key = True) + type = Column(String, primary_key=True) data = Column(String) title = Column(String) + created_utc = Column(Integer) - def __init__(self, **kwargs): - super().__init__(**kwargs) - - def is_youtube(self): - return self.type == OrgyTypes.YOUTUBE - def is_rumble(self): - return self.type == OrgyTypes.RUMBLE - def is_twitch(self): - return self.type == OrgyTypes.TWITCH + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) def __repr__(self): - return f"<{self.__class__.__name__}(id={self.id}, type={self.type}, data={self.data} title={self.title})>" - + return f"<{self.__class__.__name__}(type={self.type}, data={self.data} title={self.title})>" def get_orgy(): - orgy = g.db.query(Orgy).one_or_none() - return orgy - -def create_orgy(link, title): - assert not get_orgy() - normalized_link = normalize_url(link) - data = None - orgy_type = -1 - if re.match(bare_youtube_regex, normalized_link): - orgy_type = OrgyTypes.YOUTUBE - data, _ = get_youtube_id_and_t(normalized_link) - elif re.match(rumble_regex, normalized_link): - orgy_type = OrgyTypes.RUMBLE - data = normalized_link - elif re.match(twitch_regex, normalized_link): - orgy_type = OrgyTypes.TWITCH - data = re.search(twitch_regex, normalized_link).group(3) - else: - assert False - - orgy = Orgy(title=title, id=0, type = orgy_type, data = data) - g.db.add(orgy) - -def end_orgy(): - assert get_orgy() - g.db.query(Orgy).delete() + return g.db.query(Orgy).one_or_none() diff --git a/files/routes/admin.py b/files/routes/admin.py index 4bbead621..066a7d5f5 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -1948,18 +1948,46 @@ def orgy_control(v): @app.post("/admin/start_orgy") @admin_level_required(PERMS['ORGIES']) def start_orgy(v): - link = request.values.get("link") - title = request.values.get("title") + link = request.values.get("link", "").strip() + title = request.values.get("title", "").strip() - assert link - assert title + if not link: + abort(400, "A link is required!") - create_orgy(link, title) + if not title: + abort(400, "A title is required!") + + if get_orgy(): + abort(400, "An orgy is already in progress") + + normalized_link = normalize_url(link) + + if re.match(bare_youtube_regex, normalized_link): + orgy_type = 'youtube' + data, _ = get_youtube_id_and_t(normalized_link) + elif re.match(rumble_regex, normalized_link): + orgy_type = 'rumble' + data = normalized_link + elif re.match(twitch_regex, normalized_link): + orgy_type = 'twitch' + data = re.search(twitch_regex, normalized_link).group(3) + elif normalized_link.endswith('.mp4'): + orgy_type = 'file' + data = normalized_link + else: + abort(400) + + orgy = Orgy( + title=title, + type=orgy_type, + data=data + ) + g.db.add(orgy) return {"message": "Orgy started successfully!"} @app.post("/admin/stop_orgy") @admin_level_required(PERMS['ORGIES']) def stop_orgy(v): - end_orgy() + g.db.query(Orgy).delete() return {"message": "Orgy stopped successfully!"} diff --git a/files/templates/admin/orgy_control.html b/files/templates/admin/orgy_control.html index a80a9b8c3..a4daaf921 100644 --- a/files/templates/admin/orgy_control.html +++ b/files/templates/admin/orgy_control.html @@ -24,7 +24,7 @@
- +
diff --git a/files/templates/orgy.html b/files/templates/orgy.html index 4cd55935d..42960f2e6 100644 --- a/files/templates/orgy.html +++ b/files/templates/orgy.html @@ -8,41 +8,41 @@ {% include "modals/emoji.html" %} {% include "util/macros.html" %} {% set vlink = '' %} -
+
+
+

{{orgy.title}}

+
+ {% if orgy.type == 'youtube' %} + + {% elif orgy.type == 'rumble' %} + + {% elif orgy.type == 'twitch' %} + + {% elif orgy.type == 'file' %} +

+ +

+ + {% endif %} +
+ {{macros.chat_users_list()}} +
-
-
-

{{orgy.title}}

-
- {% if orgy.is_youtube() %} - - {% elif orgy.is_rumble() %} - - {% elif orgy.is_twitch() %} - - {%endif%} +
+
+ {{macros.chat_group_template()}}
-
Old Chat - {{macros.chat_users_list()}}
-
-
- {{macros.chat_group_template()}} -
-
- -
- {{macros.chat_line_template()}} -
- {{macros.chat_users_online()}} - {{macros.chat_window(vlink)}} +
+ {{macros.chat_line_template()}}
- + {{macros.chat_users_online()}} + {{macros.chat_window(vlink)}}
diff --git a/migrations/20230816-add-file-orgies.sql b/migrations/20230816-add-file-orgies.sql new file mode 100644 index 000000000..70cf0bbe1 --- /dev/null +++ b/migrations/20230816-add-file-orgies.sql @@ -0,0 +1,7 @@ +drop table public.orgies; +CREATE TABLE public.orgies ( + type character varying(8) primary key, + data character varying(200) NOT NULL, + title character varying(1000) NOT NULL, + created_utc int not null +);