comparison sat/plugins/plugin_comp_ap_gateway/http_server.py @ 3846:cc13efdd8360

component AP gateway: return item when `item` URL is used: a request on an `item` type URL will return the suitable cached item. rel 370
author Goffi <goffi@goffi.org>
date Thu, 14 Jul 2022 12:55:30 +0200
parents 65e5718e7710
children aaa4e7815ba8
comparison
equal deleted inserted replaced
3845:4f9d4650eab5 3846:cc13efdd8360
37 from sat.core.log import getLogger 37 from sat.core.log import getLogger
38 from sat.tools.common import date_utils, uri 38 from sat.tools.common import date_utils, uri
39 from sat.memory.sqla_mapping import SubscriptionState 39 from sat.memory.sqla_mapping import SubscriptionState
40 40
41 from .constants import ( 41 from .constants import (
42 CONTENT_TYPE_AP, TYPE_ACTOR, TYPE_INBOX, TYPE_SHARED_INBOX, TYPE_OUTBOX, 42 NS_AP, CONTENT_TYPE_AP, TYPE_ACTOR, TYPE_INBOX, TYPE_SHARED_INBOX, TYPE_OUTBOX,
43 AP_REQUEST_TYPES, PAGE_SIZE, ACTIVITY_TYPES_LOWER, ACTIVIY_NO_ACCOUNT_ALLOWED, 43 AP_REQUEST_TYPES, PAGE_SIZE, ACTIVITY_TYPES_LOWER, ACTIVIY_NO_ACCOUNT_ALLOWED,
44 SIGN_HEADERS, HS2019, SIGN_EXP, TYPE_FOLLOWERS, TYPE_FOLLOWING 44 SIGN_HEADERS, HS2019, SIGN_EXP, TYPE_FOLLOWERS, TYPE_FOLLOWING
45 ) 45 )
46 from .regex import RE_SIG_PARAM 46 from .regex import RE_SIG_PARAM
47 47
704 if len(extra_args) != 1: 704 if len(extra_args) != 1:
705 raise exceptions.DataError("avatar argument expected in URL") 705 raise exceptions.DataError("avatar argument expected in URL")
706 avatar_filename = extra_args[0] 706 avatar_filename = extra_args[0]
707 avatar_path = self.apg.host.common_cache.getPath(avatar_filename) 707 avatar_path = self.apg.host.common_cache.getPath(avatar_filename)
708 return static.File(str(avatar_path)).render(request) 708 return static.File(str(avatar_path)).render(request)
709 elif request_type == "item":
710 ret_data = await self.apg.apGetLocalObject(ap_url)
711 ret_data["@context"] = NS_AP
709 else: 712 else:
710 if len(extra_args) > 1: 713 if len(extra_args) > 1:
711 log.warning(f"unexpected extra arguments: {extra_args!r}") 714 log.warning(f"unexpected extra arguments: {extra_args!r}")
712 ap_account = extra_args[0] 715 ap_account = extra_args[0]
713 account_jid, node = await self.apg.getJIDAndNode(ap_account) 716 account_jid, node = await self.apg.getJIDAndNode(ap_account)