Skip to content

Commit

Permalink
Added static files for news user.
Browse files Browse the repository at this point in the history
Updated routes to use content types when there is
no accept header.
  • Loading branch information
steve-bate committed Sep 3, 2024
1 parent b15b0ce commit 4c9be45
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions firm_server/cli/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ async def actor_update(
if description:
actor_resource["summary"] = description
if header_image:
actor_resource["image"] = header_image
actor_resource["image"] = {"type": "Image", "url": header_image}
if avatar:
actor_resource["icon"] = avatar
actor_resource["icon"] = {"type": "Image", "url": avatar}
if hashtags:
tenant_prefix = get_url_prefix(uri)
actor_resource["tag"] = [
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 12 additions & 7 deletions firm_server/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ async def deliver(self, activity: JSONObject) -> None:
await self._post(inbox, message=message, auth=auth)


class AcceptedTypeRoute(Route):
class MimeTypeRoute(Route):
def __init__(self, *args, **kwargs):
self._mimetypes = kwargs.pop("mimetypes", None)
super().__init__(*args, **kwargs)
Expand All @@ -189,12 +189,17 @@ def _get_header(scope: Scope, name: bytes) -> str | None:
for key, value in scope["headers"]:
if key == name:
return value.decode()
return None
return ""

def _matches_mimetype(self, scope: Scope) -> bool:
return self._mimetypes is None or mimeparse.best_match(
self._mimetypes, self._get_header(scope, b"accept")
)
if accepted_types := self._get_header(scope, b"accept"):
return self._mimetypes is None or mimeparse.best_match(
self._mimetypes, accepted_types
)
elif content_type := self._get_header(scope, b"content-type"):
return self._mimetypes is None or content_type in self._mimetypes
else:
raise HTTPException(400, "No accept or content-type header")

def matches(self, scope: Scope) -> tuple[Match, Scope]:
return (
Expand All @@ -215,7 +220,7 @@ def get_routes(config: ServerConfig):
for prefix in config.tenants
]
)
activitypub_route = AcceptedTypeRoute(
activitypub_route = MimeTypeRoute(
"/{path:path}",
endpoint=_adapt_endpoint(activitypub_service.process_request),
mimetypes=[
Expand Down Expand Up @@ -243,7 +248,7 @@ def get_routes(config: ServerConfig):
Route("/.well-known/nodeinfo", endpoint=_adapt_endpoint(nodeinfo_index)),
Route("/nodeinfo/{version}", endpoint=_adapt_endpoint(nodeinfo_version)),
Route("/static/{file_path:path}", endpoint=html_static_endpoint(config)),
AcceptedTypeRoute(
MimeTypeRoute(
"/{path:path}",
endpoint=html_endpoint(config),
mimetypes=["text/html"],
Expand Down

0 comments on commit 4c9be45

Please sign in to comment.