diff --git a/assets/css/base.css b/assets/css/base.css index 0acc8ba..bceffe7 100644 --- a/assets/css/base.css +++ b/assets/css/base.css @@ -243,6 +243,7 @@ li.control-bar-action:hover { transform: translateX(-50%); overflow: hidden; width: fit-content; + z-index: 1; } .control-bar-dropdown-menu li { diff --git a/requirements.txt b/requirements.txt index 01ff451..36a6e59 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,7 +15,7 @@ idna==3.4 Jinja2==3.1.2 MarkupSafe==2.1.3 multidict==6.0.4 -npf-renderer==0.11.1 +npf-renderer==0.12.0 orjson==3.8.0 PyYAML==6.0.1 sanic==23.3.0 diff --git a/src/helpers/helpers.py b/src/helpers/helpers.py index 1e8df63..8964237 100644 --- a/src/helpers/helpers.py +++ b/src/helpers/helpers.py @@ -23,6 +23,8 @@ def url_handler(raw_url): return f"/tblr/media/44{url.path}" elif hostname.endswith("static.tumblr.com"): return f"/tblr/static/{url.path}" + elif hostname.startswith("va.media"): + return f"/tblr/media/va/{url.path}" else: # Check for subdomain blog sub_domains = hostname.split(".") diff --git a/src/routes/media.py b/src/routes/media.py index d9a89e4..acad813 100644 --- a/src/routes/media.py +++ b/src/routes/media.py @@ -3,8 +3,8 @@ media = sanic.Blueprint("TumblrMedia", url_prefix="/tblr") -async def get_media(request, client, path_to_request): - async with client.stream("GET", path_to_request) as tumblr_response: +async def get_media(request, client, path_to_request, additional_headers = None): + async with client.stream("GET", path_to_request, headers=additional_headers) as tumblr_response: # Sanitize the headers given by Tumblr priviblur_response_headers = {} for header_key, header_value in tumblr_response.headers.items(): @@ -26,6 +26,8 @@ async def get_media(request, client, path_to_request): async for chunk in tumblr_response.aiter_raw(): await priviblur_response.send(chunk) + await priviblur_response.eof() + @media.get(r"/media/64/") async def _64_media(request: sanic.Request, path: str): @@ -45,6 +47,16 @@ async def _44_media(request: sanic.Request, path: str): return await get_media(request, request.app.ctx.Media44Client, path) +@media.get(r"/media/va/") +async def _va_media(request: sanic.Request, path: str): + """Proxies the requested media from va.media.tumblr.com""" + additional_headers={ + "accept": "video/webm,video/ogg,video/*;q=0.9," \ + "application/ogg;q=0.7,audio/*;q=0.6,*/*;q=0.5" + } + return await get_media(request, request.app.ctx.MediaVaClient, path, additional_headers=additional_headers) + + @media.get(r"/assets/") async def _tb_assets(request: sanic.Request, path: str): """Proxies the requested media from assets.tumblr.com""" diff --git a/src/server.py b/src/server.py index 99f4ea7..6f2d843 100644 --- a/src/server.py +++ b/src/server.py @@ -77,7 +77,7 @@ async def initialize(app): def create_image_client(url, timeout): media_headers = copy.copy(media_request_headers) media_headers["host"] = url - return httpx.AsyncClient(base_url=url, headers=media_request_headers, http2=True, timeout=timeout) + return httpx.AsyncClient(base_url=url, headers=media_request_headers, http1=True, timeout=timeout) app.ctx.Media64Client = create_image_client( "https://64.media.tumblr.com", priviblur_backend.image_response_timeout @@ -91,6 +91,10 @@ def create_image_client(url, timeout): "https://44.media.tumblr.com", priviblur_backend.image_response_timeout ) + app.ctx.MediaVaClient = create_image_client( + "https://va.media.tumblr.com", priviblur_backend.image_response_timeout + ) + app.ctx.TumblrAssetClient = create_image_client( "https://assets.tumblr.com", priviblur_backend.image_response_timeout ) diff --git a/src/templates/components/post.jinja b/src/templates/components/post.jinja index 6ac77e7..1118219 100644 --- a/src/templates/components/post.jinja +++ b/src/templates/components/post.jinja @@ -1,7 +1,7 @@ {% from 'macros/post_header.jinja' import create_post_header %}
{%- if element.content -%} - {% set contains_errors, content_tag = format_npf(element.content, element.layout, url_handler=url_handler, skip_cropped_images=True) -%} + {% set contains_errors, content_tag = format_npf(element.content, element.layout, url_handler=url_handler, skip_cropped_images=True, reserve_space_for_images=True, forbid_external_iframes=True) -%} {%- endif -%} {{ create_post_header(element) }} @@ -15,7 +15,7 @@ {% for element in element.trail %}
{{create_post_header(element)}} - {% set trail_contains_errors, trail_content_tag = format_npf(element.content, element.layout, url_handler=url_handler, skip_cropped_images=True) -%} + {% set trail_contains_errors, trail_content_tag = format_npf(element.content, element.layout, url_handler=url_handler, skip_cropped_images=True, reserve_space_for_images=True, forbid_external_iframes=True) -%} {{- trail_content_tag -}}
@@ -28,7 +28,6 @@ {% if element.trail and element.content %}
{{create_post_header(element, skip_reblog=True)}} - {% set trail_contains_errors, trail_content_tag = format_npf(element.content, element.layout, url_handler=url_handler, skip_cropped_images=True) -%} {{- content_tag -}}
{% else %}