Remove identity avatar fetching

This commit is contained in:
Andrew Godwin 2022-12-19 20:55:27 +00:00
parent 0dca7eae5f
commit c3a60bbf13
2 changed files with 0 additions and 27 deletions

View file

@ -1,6 +1,5 @@
import os import os
import secrets import secrets
import urllib.parse
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from django.utils import timezone from django.utils import timezone
@ -18,16 +17,6 @@ def upload_namer(prefix, instance, filename):
By default, obscures the original name with a random UUID. By default, obscures the original name with a random UUID.
""" """
_, old_extension = os.path.splitext(filename) _, old_extension = os.path.splitext(filename)
if prefix == "profile_images":
# If we're saving images for an Identity, we name predictably as
# avatar images are not considered "secret", and otherwise we'll waste
# space.
handle_safe = urllib.parse.quote(instance.handle)
return (
f"{prefix}/{handle_safe[:2]}/{handle_safe[:4]}/{handle_safe}{old_extension}"
)
new_filename = secrets.token_urlsafe(20) new_filename = secrets.token_urlsafe(20)
now = timezone.now() now = timezone.now()
return f"{prefix}/{now.year}/{now.month}/{now.day}/{new_filename}{old_extension}" return f"{prefix}/{now.year}/{now.month}/{now.day}/{new_filename}{old_extension}"

View file

@ -5,14 +5,12 @@ from urllib.parse import urlparse
import httpx import httpx
import urlman import urlman
from asgiref.sync import async_to_sync, sync_to_async from asgiref.sync import async_to_sync, sync_to_async
from django.conf import settings
from django.db import IntegrityError, models from django.db import IntegrityError, models
from django.template.defaultfilters import linebreaks_filter from django.template.defaultfilters import linebreaks_filter
from django.utils import timezone from django.utils import timezone
from django.utils.functional import lazy from django.utils.functional import lazy
from core.exceptions import ActorMismatchError from core.exceptions import ActorMismatchError
from core.files import get_remote_file
from core.html import sanitize_post, strip_html from core.html import sanitize_post, strip_html
from core.ld import ( from core.ld import (
canonicalise, canonicalise,
@ -50,20 +48,6 @@ class IdentityStates(StateGraph):
return cls.updated return cls.updated
# Run the actor fetch and progress to updated if it succeeds # Run the actor fetch and progress to updated if it succeeds
if await identity.fetch_actor(): if await identity.fetch_actor():
# Also stash their icon if we can
if identity.icon_uri:
try:
file, mimetype = await get_remote_file(
identity.icon_uri,
timeout=settings.SETUP.REMOTE_TIMEOUT,
max_size=settings.SETUP.AVATAR_MAX_IMAGE_FILESIZE_KB * 1024,
)
except httpx.RequestError:
# We've still got enough info to consider ourselves updated
return cls.updated
if file:
identity.icon = file
await sync_to_async(identity.save)()
return cls.updated return cls.updated
@classmethod @classmethod