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
|
2023-10-02 18:56:22 +00:00
|
|
|
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,
|
2022-05-30 15:15:17 +00:00
|
|
|
show_accounts: bool) -> {}:
|
2023-06-25 10:25:49 +00:00
|
|
|
""" /nodeinfo/2.1 endpoint
|
2021-05-03 10:05:05 +00:00
|
|
|
Also see https://socialhub.activitypub.rocks/t/
|
2023-06-25 10:25:49 +00:00
|
|
|
https://github.com/jhass/nodeinfo/blob/main/schemas/2.1/example.json
|
2021-05-03 10:05:05 +00:00
|
|
|
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)
|
2023-10-02 18:56:22 +00:00
|
|
|
local_posts = get_status_count(base_dir)
|
2021-05-03 10:05:05 +00:00
|
|
|
else:
|
2022-01-03 10:27:55 +00:00
|
|
|
active_accounts = 1
|
|
|
|
active_accounts_monthly = 1
|
|
|
|
active_accounts_half_year = 1
|
|
|
|
local_posts = 1
|
2021-05-03 10:05:05 +00:00
|
|
|
|
2020-04-03 16:59:12 +00:00
|
|
|
nodeinfo = {
|
2019-11-13 10:32:12 +00:00
|
|
|
'openRegistrations': registration,
|
|
|
|
'protocols': ['activitypub'],
|
2022-11-08 11:25:32 +00:00
|
|
|
'services': {
|
|
|
|
'outbound': ['rss2.0']
|
|
|
|
},
|
2019-11-13 10:32:12 +00:00
|
|
|
'software': {
|
|
|
|
'name': 'epicyon',
|
2023-06-25 09:59:29 +00:00
|
|
|
'repository': 'https://gitlab.com/bashrc2/epicyon',
|
2023-06-25 10:24:09 +00:00
|
|
|
'homepage': 'https://gitlab.com/bashrc2/epicyon',
|
2019-11-13 10:32:12 +00:00
|
|
|
'version': version
|
|
|
|
},
|
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
|
|
|
},
|
2019-11-13 10:32:12 +00:00
|
|
|
'usage': {
|
2022-01-03 10:27:55 +00:00
|
|
|
'localPosts': local_posts,
|
2019-11-13 10:32:12 +00:00
|
|
|
'users': {
|
2022-01-03 10:27:55 +00:00
|
|
|
'activeHalfyear': active_accounts_half_year,
|
|
|
|
'activeMonth': active_accounts_monthly,
|
|
|
|
'total': active_accounts
|
2019-11-13 10:32:12 +00:00
|
|
|
}
|
|
|
|
},
|
2023-06-25 10:24:09 +00:00
|
|
|
'metadata': {
|
|
|
|
'chat_enabled': False,
|
2023-07-15 18:44:42 +00:00
|
|
|
'postFormats': ['text/plain', 'text/html', 'text/markdown'],
|
2023-08-20 17:30:03 +00:00
|
|
|
'FEPs': ['c648', '521a', '8fcf', '4ccd', 'c118', 'fffd',
|
2023-10-19 13:51:53 +00:00
|
|
|
'1970', '0837', '7628', '2677']
|
2023-06-25 10:24:09 +00:00
|
|
|
},
|
|
|
|
'version': '2.1'
|
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
|