2019-11-13 10:32:12 +00:00
|
|
|
__filename__ = "metadata.py"
|
|
|
|
__author__ = "Bob Mottram"
|
|
|
|
__license__ = "AGPL3+"
|
|
|
|
__version__ = "1.0.0"
|
|
|
|
__maintainer__ = "Bob Mottram"
|
|
|
|
__email__ = "bob@freedombone.net"
|
|
|
|
__status__ = "Production"
|
|
|
|
|
2019-11-13 12:45:41 +00:00
|
|
|
import os
|
2019-11-13 10:32:12 +00:00
|
|
|
import json
|
2019-11-13 12:45:41 +00:00
|
|
|
import commentjson
|
2019-11-13 14:02:45 +00:00
|
|
|
from utils import noOfAccounts
|
2019-11-13 15:19:43 +00:00
|
|
|
from utils import noOfActiveAccountsMonthly
|
2019-11-13 10:32:12 +00:00
|
|
|
|
2019-11-13 14:02:45 +00:00
|
|
|
def metaDataNodeInfo(baseDir: str,registration: bool,version: str) -> {}:
|
2019-11-13 10:32:12 +00:00
|
|
|
""" /nodeinfo/2.0 endpoint
|
|
|
|
"""
|
2019-11-13 14:02:45 +00:00
|
|
|
activeAccounts=noOfAccounts(baseDir)
|
2019-11-13 15:19:43 +00:00
|
|
|
activeAccountsMonthly=noOfActiveAccountsMonthly(baseDir,1)
|
|
|
|
activeAccountsHalfYear=noOfActiveAccountsMonthly(baseDir,6)
|
2019-11-13 10:32:12 +00:00
|
|
|
nodeinfo = {
|
|
|
|
'openRegistrations': registration,
|
|
|
|
'protocols': ['activitypub'],
|
|
|
|
'software': {
|
|
|
|
'name': 'epicyon',
|
|
|
|
'version': version
|
|
|
|
},
|
|
|
|
'usage': {
|
|
|
|
'localPosts': 1,
|
|
|
|
'users': {
|
2019-11-13 15:19:43 +00:00
|
|
|
'activeHalfyear': activeAccountsHalfYear,
|
|
|
|
'activeMonth': activeAccountsMonthly,
|
2019-11-13 14:02:45 +00:00
|
|
|
'total': activeAccounts
|
2019-11-13 10:32:12 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
'version': '2.0'
|
|
|
|
}
|
|
|
|
return nodeinfo
|
2019-11-13 12:45:41 +00:00
|
|
|
|
|
|
|
def metaDataInstance(instanceTitle: str, \
|
|
|
|
instanceDescriptionShort: str, \
|
|
|
|
instanceDescription: str, \
|
|
|
|
httpPrefix: str,baseDir: str, \
|
|
|
|
adminNickname: str,domain: str,domainFull: str, \
|
|
|
|
registration: bool,systemLanguage: str, \
|
|
|
|
version: str) -> {}:
|
|
|
|
""" /api/v1/instance endpoint
|
|
|
|
"""
|
|
|
|
adminActorFilename=baseDir+'/accounts/'+adminNickname+'@'+domain+'.json'
|
|
|
|
if not os.path.isfile(adminActorFilename):
|
|
|
|
return {}
|
|
|
|
|
|
|
|
adminActor=None
|
|
|
|
try:
|
|
|
|
with open(adminActorFilename, 'r') as fp:
|
|
|
|
adminActor=commentjson.load(fp)
|
|
|
|
except:
|
|
|
|
print('WARN: commentjson exception metaDataInstance')
|
|
|
|
|
|
|
|
if not adminActor:
|
|
|
|
return {}
|
|
|
|
|
2019-11-13 13:17:35 +00:00
|
|
|
isBot=False
|
|
|
|
if adminActor['type']!='Person':
|
|
|
|
isBot=True
|
2019-11-13 14:02:45 +00:00
|
|
|
|
2019-11-13 12:45:41 +00:00
|
|
|
instance = {
|
2019-11-13 12:55:37 +00:00
|
|
|
'approval_required': False,
|
2019-11-13 12:45:41 +00:00
|
|
|
'contact_account': {'acct': adminActor['preferredUsername'],
|
|
|
|
'avatar': adminActor['icon']['url'],
|
|
|
|
'avatar_static': adminActor['icon']['url'],
|
2019-11-13 13:17:35 +00:00
|
|
|
'bot': isBot,
|
2019-11-13 12:45:41 +00:00
|
|
|
'created_at': '2019-07-01T10:30:00Z',
|
|
|
|
'display_name': adminActor['name'],
|
|
|
|
'emojis': [],
|
|
|
|
'fields': [],
|
|
|
|
'followers_count': 1,
|
|
|
|
'following_count': 1,
|
|
|
|
'header': adminActor['image']['url'],
|
|
|
|
'header_static': adminActor['image']['url'],
|
|
|
|
'id': '1',
|
|
|
|
'last_status_at': '2019-07-01T10:30:00Z',
|
2019-11-13 12:54:01 +00:00
|
|
|
'locked': adminActor['manuallyApprovesFollowers'],
|
2019-11-13 12:45:41 +00:00
|
|
|
'note': '<p>Admin of '+domain+'</p>',
|
|
|
|
'statuses_count': 1,
|
|
|
|
'url': httpPrefix+'://'+domainFull+'/@'+adminActor['preferredUsername'],
|
|
|
|
'username': adminActor['preferredUsername']
|
|
|
|
},
|
|
|
|
'description': instanceDescription,
|
|
|
|
'email': 'admin@'+domain,
|
|
|
|
'languages': [systemLanguage],
|
|
|
|
'registrations': registration,
|
|
|
|
'short_description': instanceDescriptionShort,
|
|
|
|
'stats': {
|
2019-11-13 14:02:45 +00:00
|
|
|
'domain_count': 2,
|
2019-11-13 12:45:41 +00:00
|
|
|
'status_count': 1,
|
2019-11-13 14:02:45 +00:00
|
|
|
'user_count': noOfAccounts(baseDir)
|
2019-11-13 12:45:41 +00:00
|
|
|
},
|
|
|
|
'thumbnail': httpPrefix+'://'+domainFull+'/login.png',
|
|
|
|
'title': instanceTitle,
|
|
|
|
'uri': domainFull,
|
|
|
|
'urls': {},
|
|
|
|
'version': version
|
|
|
|
}
|
|
|
|
|
|
|
|
return instance
|