mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-03 23:59:15 +02:00
Deliver is now a proper celery task
This commit is contained in:
parent
2a4ce0a48c
commit
64e88b83f7
3 changed files with 50 additions and 38 deletions
|
@ -1,18 +1,5 @@
|
|||
import logging
|
||||
import json
|
||||
import requests_http_signature
|
||||
import uuid
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from funkwhale_api.common import session
|
||||
from funkwhale_api.common import utils as funkwhale_utils
|
||||
|
||||
from . import models
|
||||
from . import serializers
|
||||
from . import signing
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
from . import tasks
|
||||
|
||||
ACTIVITY_TYPES = [
|
||||
'Accept',
|
||||
|
@ -65,31 +52,16 @@ OBJECT_TYPES = [
|
|||
|
||||
|
||||
def deliver(activity, on_behalf_of, to=[]):
|
||||
from . import actors
|
||||
logger.info('Preparing activity delivery to %s', to)
|
||||
auth = signing.get_auth(
|
||||
on_behalf_of.private_key, on_behalf_of.private_key_id)
|
||||
for url in to:
|
||||
recipient_actor = actors.get_actor(url)
|
||||
logger.debug('delivering to %s', recipient_actor.inbox_url)
|
||||
logger.debug('activity content: %s', json.dumps(activity))
|
||||
response = session.get_session().post(
|
||||
auth=auth,
|
||||
json=activity,
|
||||
url=recipient_actor.inbox_url,
|
||||
timeout=5,
|
||||
verify=settings.EXTERNAL_REQUESTS_VERIFY_SSL,
|
||||
headers={
|
||||
'Content-Type': 'application/activity+json'
|
||||
}
|
||||
)
|
||||
response.raise_for_status()
|
||||
logger.debug('Remote answered with %s', response.status_code)
|
||||
return tasks.send.delay(
|
||||
activity=activity,
|
||||
actor_id=on_behalf_of.pk,
|
||||
to=to
|
||||
)
|
||||
|
||||
|
||||
def accept_follow(follow):
|
||||
serializer = serializers.AcceptFollowSerializer(follow)
|
||||
deliver(
|
||||
return deliver(
|
||||
serializer.data,
|
||||
to=[follow.actor.url],
|
||||
on_behalf_of=follow.target)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue