From 3b186f23d3908881196ff85fcbe516d129ad215b Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 2 Sep 2018 19:43:09 +0200 Subject: [PATCH] Video support --- app.py | 29 ++++++++++++++++++++++++----- config.py | 4 ++++ sass/base_theme.scss | 3 +++ templates/lookup.html | 2 +- templates/utils.html | 15 ++++++++++++--- 5 files changed, 44 insertions(+), 9 deletions(-) diff --git a/app.py b/app.py index 76edaf1..212702e 100644 --- a/app.py +++ b/app.py @@ -224,6 +224,14 @@ def remove_mongo_id(dat): return dat +@app.template_filter() +def get_video_link(data): + for link in data: + if link.get("mimeType", "").startswith("video/"): + return link.get("href") + return None + + @app.template_filter() def get_actor_icon_url(url, size): return _get_file_url(url, size, Kind.ACTOR_ICON) @@ -281,6 +289,11 @@ def url_or_id(d): @app.template_filter() def get_url(u): + print(f'GET_URL({u!r})') + if isinstance(u, list): + for l in u: + if l.get('mimeType') == 'text/html': + u = l if isinstance(u, dict): return u["href"] elif isinstance(u, str): @@ -293,13 +306,17 @@ def get_url(u): def get_actor(url): if not url: return None + if isinstance(url, list): + url = url[0] + if isinstance(url, dict): + url = url.get("id") print(f"GET_ACTOR {url}") try: return get_backend().fetch_iri(url) except (ActivityNotFoundError, ActivityGoneError): return f"Deleted<{url}>" - except Exception: - return f"Error<{url}>" + except Exception as exc: + return f"Error<{url}/{exc!r}>" @app.template_filter() @@ -319,9 +336,10 @@ def format_timeago(val): @app.template_filter() -def has_type(doc, _type): - if _type in _to_list(doc["type"]): - return True +def has_type(doc, _types): + for _type in _to_list(_types): + if _type in _to_list(doc["type"]): + return True return False @@ -1326,6 +1344,7 @@ def admin_lookup(): actor=data.get_actor().to_dict(), ) + print(data) return render_template( "lookup.html", data=data, meta=meta, url=request.form.get("url") ) diff --git a/config.py b/config.py index a31aeca..a5940ce 100644 --- a/config.py +++ b/config.py @@ -105,6 +105,10 @@ MEDIA_CACHE = MediaCache(GRIDFS, USER_AGENT) def create_indexes(): DB.activities.create_index([("remote_id", pymongo.ASCENDING)]) DB.activities.create_index([("activity.object.id", pymongo.ASCENDING)]) + DB.activities.create_index([ + ("activity.object.id", pymongo.ASCENDING), + ("meta.deleted", pymongo.ASCENDING), + ]) # Index for the block query DB.activities.create_index( diff --git a/sass/base_theme.scss b/sass/base_theme.scss index cdc7665..17fa02c 100644 --- a/sass/base_theme.scss +++ b/sass/base_theme.scss @@ -324,3 +324,6 @@ input[type=submit] { color: $primary-color; text-transform: uppercase; } +.note-video { + margin: 30px 0 10px 0; +} diff --git a/templates/lookup.html b/templates/lookup.html index 31932c1..8a4173d 100644 --- a/templates/lookup.html +++ b/templates/lookup.html @@ -29,7 +29,7 @@ {{ utils.display_actor_inline(data, size=80) }} {% elif data | has_type('Create') %} {{ utils.display_note(data.object, ui=True) }} - {% elif data | has_type('Note') %} + {% elif data | has_type(['Note', 'Article', 'Video']) %} {{ utils.display_note(data, ui=True) }} {% elif data | has_type('Announce') %} {% set boost_actor = meta.actor %} diff --git a/templates/utils.html b/templates/utils.html index 6dc11e1..e54e394 100644 --- a/templates/utils.html +++ b/templates/utils.html @@ -36,7 +36,7 @@
{{ actor.name or actor.preferredUsername }} - @{% if not no_color and obj.id | is_from_outbox %}{{ actor.preferredUsername }}{% else %}{{ actor.preferredUsername }}{% endif %}@{% if not no_color and obj.id | is_from_outbox %}{{ actor | url_or_id | get_url | domain }}{% else %}{{ actor | url_or_id | get_url | domain }}{% endif %} +
  • @{% if not no_color and obj.id | is_from_outbox %}{{ actor.preferredUsername }}{% else %}{{ actor.preferredUsername }}{% endif %}@{% if not no_color and obj.id | is_from_outbox %}{{ actor | url_or_id | get_url | domain }}{% else %}{{ actor | url_or_id | get_url | domain }}{% endif %} {% if not perma %} @@ -46,7 +46,14 @@ {% endif %}
  • {% if obj.summary %}

    {{ obj.summary | clean }}

    {% endif %} + {% if obj | has_type('Video') %} +
    + +
    + {% endif %}
    + {% if obj | has_type('Article') %} {{ obj.name }} {{ obj | url_or_id | get_url }} {% else %} @@ -57,12 +64,14 @@ {% if obj.attachment and obj | has_type('Note') %}
    {% if obj.attachment | not_only_imgs %} -

    Attachment

    -