epicyon/metadata.py

129 lines
4.3 KiB
Python
Raw Normal View History

2020-04-03 16:59:12 +00:00
__filename__ = "metadata.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
2024-01-21 19:01:20 +00:00
__version__ = "1.5.0"
2020-04-03 16:59:12 +00:00
__maintainer__ = "Bob Mottram"
2021-09-10 16:14:50 +00:00
__email__ = "bob@libreserver.org"
2020-04-03 16:59:12 +00:00
__status__ = "Production"
2021-06-15 15:08:12 +00:00
__module_group__ = "Metadata"
2019-11-13 10:32:12 +00:00
2019-11-13 12:45:41 +00:00
import os
2021-12-28 14:41:10 +00:00
from utils import no_of_active_accounts_monthly
from utils import no_of_accounts
from utils import get_status_count
2021-06-05 09:22:35 +00:00
2021-12-28 17:20:43 +00:00
def meta_data_node_info(base_dir: str,
2022-01-03 10:27:55 +00:00
about_url: str,
terms_of_service_url: str,
2021-12-28 17:20:43 +00:00
registration: bool, version: str,
2024-05-16 10:05:14 +00:00
show_accounts: bool,
2024-06-04 18:18:02 +00:00
domain: str,
instance_description_short: str,
2024-06-04 18:18:02 +00:00
instance_description: str) -> {}:
""" /nodeinfo/2.2 endpoint
Also see https://socialhub.activitypub.rocks/t/
2024-06-04 18:18:02 +00:00
https://github.com/jhass/nodeinfo/blob/main/schemas/2.2/example.json
fep-f1d5-nodeinfo-in-fediverse-software/1190/4
Note that there are security considerations with this. If an adversary
sees a lot of accounts and "local" posts then the instance may be
considered a higher priority target.
Also exposure of the version number and number of accounts could be
sensitive
2019-11-13 10:32:12 +00:00
"""
2022-05-30 15:15:17 +00:00
if show_accounts:
2022-01-03 10:27:55 +00:00
active_accounts = no_of_accounts(base_dir)
active_accounts_monthly = no_of_active_accounts_monthly(base_dir, 1)
active_accounts_half_year = no_of_active_accounts_monthly(base_dir, 6)
local_posts = get_status_count(base_dir)
else:
2022-01-03 10:27:55 +00:00
active_accounts = 1
active_accounts_monthly = 1
active_accounts_half_year = 1
local_posts = 1
2020-04-03 16:59:12 +00:00
nodeinfo = {
2024-06-04 18:18:02 +00:00
"version": "2.2",
2021-05-04 09:39:15 +00:00
'documents': {
2022-01-03 10:27:55 +00:00
'about': about_url,
'terms': terms_of_service_url
2021-05-04 09:39:15 +00:00
},
2024-06-04 18:18:02 +00:00
"instance": {
"name": instance_description_short,
2024-06-04 18:18:02 +00:00
"description": instance_description
},
"software": {
"name": "epicyon",
"repository": "https://gitlab.com/bashrc2/epicyon",
"homepage": "https://gitlab.com/bashrc2/epicyon",
"version": version
},
"protocols": ["activitypub"],
"services": {
"outbound": ["rss2.0"]
},
"openRegistrations": registration,
"usage": {
"localComments": 0,
"localPosts": local_posts,
"users": {
"activeHalfyear": active_accounts_half_year,
"activeMonth": active_accounts_monthly,
"total": active_accounts
2019-11-13 10:32:12 +00:00
}
},
2024-06-04 18:18:02 +00:00
"metadata": {
"accountActivationRequired": False,
"features": [
"editing",
"exposable_reactions"
2024-05-16 10:05:14 +00:00
],
2024-06-04 18:18:02 +00:00
"chat_enabled": False,
"federatedTimelineAvailable": False,
"federation": {
"enabled": True
2024-05-16 10:05:14 +00:00
},
2024-06-04 18:18:02 +00:00
"suggestions": {
"enabled": False
2024-05-16 10:05:14 +00:00
},
2024-06-04 18:18:02 +00:00
"invitesEnabled": False,
"private": True,
"privilegedStaff": True,
"nodeName": domain,
"mailerEnabled": False,
"publicTimelineVisibility": {},
"postFormats": ["text/plain", "text/html", "text/markdown"],
"FEPs": ["c648", "521a", "8fcf", "4ccd", "c118", "fffd",
2024-06-23 09:11:17 +00:00
"1970", "0837", "7628", "2677", "5e53"]
2024-06-04 18:18:02 +00:00
}
2019-11-13 10:32:12 +00:00
}
return nodeinfo
2019-11-13 12:45:41 +00:00
2020-04-03 16:59:12 +00:00
2021-12-28 17:20:43 +00:00
def metadata_custom_emoji(base_dir: str,
http_prefix: str, domain_full: str) -> {}:
2021-05-27 22:08:49 +00:00
"""Returns the custom emoji
Endpoint /api/v1/custom_emojis
See https://docs.joinmastodon.org/methods/instance/custom_emojis
"""
result = []
2022-01-03 10:27:55 +00:00
emojis_url = http_prefix + '://' + domain_full + '/emoji'
for _, _, files in os.walk(base_dir + '/emoji'):
for fname in files:
if len(fname) < 3:
2021-05-27 22:19:52 +00:00
continue
2022-01-03 10:27:55 +00:00
if fname[0].isdigit() or fname[1].isdigit():
2021-05-27 22:08:49 +00:00
continue
2022-01-03 10:27:55 +00:00
if not fname.endswith('.png'):
2021-05-27 22:08:49 +00:00
continue
2022-01-03 10:27:55 +00:00
url = os.path.join(emojis_url, fname)
2021-05-27 22:08:49 +00:00
result.append({
2022-01-03 10:27:55 +00:00
"shortcode": fname.replace('.png', ''),
2021-05-27 22:08:49 +00:00
"url": url,
"static_url": url,
"visible_in_picker": True
})
break
return result