Make local actor icon optional

If a remote actor has no icon, we show our local default icon.

If we have no icon, we should allow remote instances to show their
default icon, instead of sending ours.
main
Kevin Wallace 2022-11-17 21:46:04 -08:00 committed by Thomas Sileo
parent a2254f2674
commit b37b77ad34
4 changed files with 17 additions and 11 deletions

View File

@ -135,11 +135,6 @@ ME = {
"url": config.ID + "/", # XXX: the path is important for Mastodon compat "url": config.ID + "/", # XXX: the path is important for Mastodon compat
"manuallyApprovesFollowers": config.CONFIG.manually_approves_followers, "manuallyApprovesFollowers": config.CONFIG.manually_approves_followers,
"attachment": _LOCAL_ACTOR_METADATA, "attachment": _LOCAL_ACTOR_METADATA,
"icon": {
"mediaType": mimetypes.guess_type(config.CONFIG.icon_url)[0],
"type": "Image",
"url": config.CONFIG.icon_url,
},
"publicKey": { "publicKey": {
"id": f"{config.ID}#main-key", "id": f"{config.ID}#main-key",
"owner": config.ID, "owner": config.ID,
@ -148,6 +143,13 @@ ME = {
"tag": dedup_tags(_LOCAL_ACTOR_TAGS), "tag": dedup_tags(_LOCAL_ACTOR_TAGS),
} }
if config.CONFIG.icon_url:
ME["icon"] = {
"mediaType": mimetypes.guess_type(config.CONFIG.icon_url)[0],
"type": "Image",
"url": config.CONFIG.icon_url,
}
if ALSO_KNOWN_AS: if ALSO_KNOWN_AS:
ME["alsoKnownAs"] = [ALSO_KNOWN_AS] ME["alsoKnownAs"] = [ALSO_KNOWN_AS]

View File

@ -91,7 +91,7 @@ class Config(pydantic.BaseModel):
name: str name: str
summary: str summary: str
https: bool https: bool
icon_url: str icon_url: str | None = None
image_url: str | None = None image_url: str | None = None
secret: str secret: str
debug: bool = False debug: bool = False

View File

@ -1431,7 +1431,7 @@ async def json_feed(
], ],
} }
) )
return { result = {
"version": "https://jsonfeed.org/version/1", "version": "https://jsonfeed.org/version/1",
"title": f"{LOCAL_ACTOR.display_name}'s microblog'", "title": f"{LOCAL_ACTOR.display_name}'s microblog'",
"home_page_url": LOCAL_ACTOR.url, "home_page_url": LOCAL_ACTOR.url,
@ -1439,10 +1439,12 @@ async def json_feed(
"author": { "author": {
"name": LOCAL_ACTOR.display_name, "name": LOCAL_ACTOR.display_name,
"url": LOCAL_ACTOR.url, "url": LOCAL_ACTOR.url,
"avatar": LOCAL_ACTOR.icon_url,
}, },
"items": data, "items": data,
} }
if LOCAL_ACTOR.icon_url:
result["author"]["avatar"] = LOCAL_ACTOR.icon_url
return result
async def _gen_rss_feed( async def _gen_rss_feed(
@ -1454,6 +1456,7 @@ async def _gen_rss_feed(
fg.description(f"{LOCAL_ACTOR.display_name}'s microblog") fg.description(f"{LOCAL_ACTOR.display_name}'s microblog")
fg.author({"name": LOCAL_ACTOR.display_name}) fg.author({"name": LOCAL_ACTOR.display_name})
fg.link(href=LOCAL_ACTOR.url, rel="alternate") fg.link(href=LOCAL_ACTOR.url, rel="alternate")
if LOCAL_ACTOR.icon_url:
fg.logo(LOCAL_ACTOR.icon_url) fg.logo(LOCAL_ACTOR.icon_url)
fg.language("en") fg.language("en")

View File

@ -75,9 +75,10 @@ def main() -> None:
proto = "http" proto = "http"
print("Note that you can put your icon/avatar in the static/ directory") print("Note that you can put your icon/avatar in the static/ directory")
dat["icon_url"] = prompt( if icon_url := prompt(
"icon URL: ", default=f'{proto}://{dat["domain"]}/static/nopic.png' "icon URL: ", default=f'{proto}://{dat["domain"]}/static/nopic.png'
) ):
dat["icon_url"] = icon_url
dat["secret"] = os.urandom(16).hex() dat["secret"] = os.urandom(16).hex()
with config_file.open("w") as f: with config_file.open("w") as f: