mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-03 23:09:17 +02:00
Resolve "Per-user libraries" (use !368 instead)
This commit is contained in:
parent
b0ca181016
commit
2ea21994ee
144 changed files with 6749 additions and 5347 deletions
|
@ -2,6 +2,10 @@ import unicodedata
|
|||
import re
|
||||
from django.conf import settings
|
||||
|
||||
from funkwhale_api.common import session
|
||||
|
||||
from . import signing
|
||||
|
||||
|
||||
def full_url(path):
|
||||
"""
|
||||
|
@ -52,3 +56,35 @@ def slugify_username(username):
|
|||
)
|
||||
value = re.sub(r"[^\w\s-]", "", value).strip()
|
||||
return re.sub(r"[-\s]+", "_", value)
|
||||
|
||||
|
||||
def retrieve(fid, actor=None, serializer_class=None, queryset=None):
|
||||
if queryset:
|
||||
try:
|
||||
# queryset can also be a Model class
|
||||
existing = queryset.filter(fid=fid).first()
|
||||
except AttributeError:
|
||||
existing = queryset.objects.filter(fid=fid).first()
|
||||
if existing:
|
||||
return existing
|
||||
|
||||
auth = (
|
||||
None if not actor else signing.get_auth(actor.private_key, actor.private_key_id)
|
||||
)
|
||||
response = session.get_session().get(
|
||||
fid,
|
||||
auth=auth,
|
||||
timeout=5,
|
||||
verify=settings.EXTERNAL_REQUESTS_VERIFY_SSL,
|
||||
headers={
|
||||
"Accept": "application/activity+json",
|
||||
"Content-Type": "application/activity+json",
|
||||
},
|
||||
)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
if not serializer_class:
|
||||
return data
|
||||
serializer = serializer_class(data=data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
return serializer.save()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue