mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 07:39:16 +02:00
Set up initial configuration for installing
Set up player config for mobile control
This commit is contained in:
parent
551fb6d164
commit
2302dc0581
16 changed files with 1012 additions and 26 deletions
|
@ -1,5 +1,7 @@
|
|||
import html
|
||||
import io
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
import xml.sax.saxutils
|
||||
|
||||
|
@ -9,6 +11,8 @@ from django.core.cache import caches
|
|||
from django import urls
|
||||
from rest_framework import views
|
||||
|
||||
from funkwhale_api.federation import utils as federation_utils
|
||||
|
||||
from . import preferences
|
||||
from . import session
|
||||
from . import throttling
|
||||
|
@ -26,6 +30,13 @@ def should_fallback_to_spa(path):
|
|||
def serve_spa(request):
|
||||
html = get_spa_html(settings.FUNKWHALE_SPA_HTML_ROOT)
|
||||
head, tail = html.split("</head>", 1)
|
||||
if settings.FUNKWHALE_SPA_REWRITE_MANIFEST:
|
||||
new_url = (
|
||||
settings.FUNKWHALE_SPA_REWRITE_MANIFEST_URL
|
||||
or federation_utils.full_url(urls.reverse("api:v1:instance:spa-manifest"))
|
||||
)
|
||||
head = replace_manifest_url(head, new_url)
|
||||
|
||||
if not preferences.get("common__api_authentication_required"):
|
||||
try:
|
||||
request_tags = get_request_head_tags(request) or []
|
||||
|
@ -66,17 +77,34 @@ def serve_spa(request):
|
|||
return http.HttpResponse(head + tail)
|
||||
|
||||
|
||||
MANIFEST_LINK_REGEX = re.compile(r"<link .*rel=(?:'|\")?manifest(?:'|\")?.*>")
|
||||
|
||||
|
||||
def replace_manifest_url(head, new_url):
|
||||
replacement = '<link rel=manifest href="{}">'.format(new_url)
|
||||
head = MANIFEST_LINK_REGEX.sub(replacement, head)
|
||||
return head
|
||||
|
||||
|
||||
def get_spa_html(spa_url):
|
||||
return get_spa_file(spa_url, "index.html")
|
||||
|
||||
|
||||
def get_spa_file(spa_url, name):
|
||||
if spa_url.startswith("/"):
|
||||
# XXX: spa_url is an absolute path to index.html, on the local disk.
|
||||
# However, we may want to access manifest.json or other files as well, so we
|
||||
# strip the filename
|
||||
path = os.path.join(os.path.dirname(spa_url), name)
|
||||
# we try to open a local file
|
||||
with open(spa_url) as f:
|
||||
with open(path) as f:
|
||||
return f.read()
|
||||
cache_key = "spa-html:{}".format(spa_url)
|
||||
cache_key = "spa-file:{}:{}".format(spa_url, name)
|
||||
cached = caches["local"].get(cache_key)
|
||||
if cached:
|
||||
return cached
|
||||
|
||||
response = session.get_session().get(utils.join_url(spa_url, "index.html"),)
|
||||
response = session.get_session().get(utils.join_url(spa_url, name),)
|
||||
response.raise_for_status()
|
||||
content = response.text
|
||||
caches["local"].set(cache_key, content, settings.FUNKWHALE_SPA_HTML_CACHE_DURATION)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue