mirror of https://gitlab.com/bashrc2/epicyon
instance metadata endpoint
parent
2124e31ba0
commit
4b5ddf1d48
25
daemon.py
25
daemon.py
|
@ -25,6 +25,7 @@ from webfinger import webfingerNodeInfo
|
||||||
from webfinger import webfingerLookup
|
from webfinger import webfingerLookup
|
||||||
from webfinger import webfingerHandle
|
from webfinger import webfingerHandle
|
||||||
from metadata import metaDataNodeInfo
|
from metadata import metaDataNodeInfo
|
||||||
|
from metadata import metaDataInstance
|
||||||
from donate import getDonationUrl
|
from donate import getDonationUrl
|
||||||
from donate import setDonationUrl
|
from donate import setDonationUrl
|
||||||
from person import activateAccount
|
from person import activateAccount
|
||||||
|
@ -336,6 +337,26 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
return False
|
return False
|
||||||
if self.server.debug:
|
if self.server.debug:
|
||||||
print('DEBUG: mastodon api '+self.path)
|
print('DEBUG: mastodon api '+self.path)
|
||||||
|
if self.path=='/api/v1/instance':
|
||||||
|
adminNickname=getConfigParam(self.server.baseDir,'admin')
|
||||||
|
instanceDescriptionShort=getConfigParam(self.server.baseDir,'instanceDescriptionShort')
|
||||||
|
instanceDescription=getConfigParam(self.server.baseDir,'instanceDescription')
|
||||||
|
instanceTitle=getConfigParam(self.server.baseDir,'instanceTitle')
|
||||||
|
instanceJson= \
|
||||||
|
metaDataInstance(instanceTitle, \
|
||||||
|
instanceDescriptionShort, \
|
||||||
|
instanceDescription, \
|
||||||
|
self.server.httpPrefix, \
|
||||||
|
self.server.baseDir, \
|
||||||
|
adminNickname, \
|
||||||
|
self.server.domain,self.server.domainFull, \
|
||||||
|
self.server.registration, \
|
||||||
|
self.server.systemLanguage, \
|
||||||
|
self.server.projectVersion)
|
||||||
|
msg=json.dumps(instanceJson).encode('utf-8')
|
||||||
|
self._set_headers('application/ld+json',len(msg),None)
|
||||||
|
self._write(msg)
|
||||||
|
return True
|
||||||
if self.path.startswith('/api/v1/instance/peers'):
|
if self.path.startswith('/api/v1/instance/peers'):
|
||||||
# This is just a dummy result.
|
# This is just a dummy result.
|
||||||
# Showing the full list of peers would have privacy implications.
|
# Showing the full list of peers would have privacy implications.
|
||||||
|
@ -365,7 +386,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self._set_headers('application/ld+json',len(msg),None)
|
self._set_headers('application/ld+json',len(msg),None)
|
||||||
self._write(msg)
|
self._write(msg)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _webfinger(self) -> bool:
|
def _webfinger(self) -> bool:
|
||||||
if not self.path.startswith('/.well-known'):
|
if not self.path.startswith('/.well-known'):
|
||||||
return False
|
return False
|
||||||
|
@ -4465,6 +4486,7 @@ def runDaemon(registration: bool, \
|
||||||
|
|
||||||
# load translations dictionary
|
# load translations dictionary
|
||||||
httpd.translate={}
|
httpd.translate={}
|
||||||
|
httpd.systemLanguage='en'
|
||||||
if not unitTest:
|
if not unitTest:
|
||||||
if not os.path.isdir(baseDir+'/translations'):
|
if not os.path.isdir(baseDir+'/translations'):
|
||||||
print('ERROR: translations directory not found')
|
print('ERROR: translations directory not found')
|
||||||
|
@ -4486,6 +4508,7 @@ def runDaemon(registration: bool, \
|
||||||
systemLanguage='en'
|
systemLanguage='en'
|
||||||
translationsFile=baseDir+'/translations/'+systemLanguage+'.json'
|
translationsFile=baseDir+'/translations/'+systemLanguage+'.json'
|
||||||
print('System language: '+systemLanguage)
|
print('System language: '+systemLanguage)
|
||||||
|
httpd.systemLanguage=systemLanguage
|
||||||
httpd.translate=loadJson(translationsFile)
|
httpd.translate=loadJson(translationsFile)
|
||||||
|
|
||||||
httpd.registration=registration
|
httpd.registration=registration
|
||||||
|
|
17
epicyon.py
17
epicyon.py
|
@ -366,7 +366,22 @@ if not os.path.isdir(baseDir+'/cache/announce'):
|
||||||
themeName=getConfigParam(baseDir,'theme')
|
themeName=getConfigParam(baseDir,'theme')
|
||||||
if not themeName:
|
if not themeName:
|
||||||
setConfigParam(baseDir,'theme','default')
|
setConfigParam(baseDir,'theme','default')
|
||||||
|
|
||||||
|
# set the instance title in config.json
|
||||||
|
title=getConfigParam(baseDir,'instanceTitle')
|
||||||
|
if not title:
|
||||||
|
setConfigParam(baseDir,'instanceTitle','Epicyon')
|
||||||
|
|
||||||
|
# set the instance description in config.json
|
||||||
|
descFull=getConfigParam(baseDir,'instanceDescription')
|
||||||
|
if not descFull:
|
||||||
|
setConfigParam(baseDir,'instanceDescription','Just another ActivityPub server')
|
||||||
|
|
||||||
|
# set the short instance description in config.json
|
||||||
|
descShort=getConfigParam(baseDir,'instanceDescriptionShort')
|
||||||
|
if not descShort:
|
||||||
|
setConfigParam(baseDir,'instanceDescriptionShort','Just another ActivityPub server')
|
||||||
|
|
||||||
if args.domain:
|
if args.domain:
|
||||||
domain=args.domain
|
domain=args.domain
|
||||||
setConfigParam(baseDir,'domain',domain)
|
setConfigParam(baseDir,'domain',domain)
|
||||||
|
|
66
metadata.py
66
metadata.py
|
@ -6,7 +6,9 @@ __maintainer__ = "Bob Mottram"
|
||||||
__email__ = "bob@freedombone.net"
|
__email__ = "bob@freedombone.net"
|
||||||
__status__ = "Production"
|
__status__ = "Production"
|
||||||
|
|
||||||
|
import os
|
||||||
import json
|
import json
|
||||||
|
import commentjson
|
||||||
|
|
||||||
def metaDataNodeInfo(registration: bool,version: str) -> {}:
|
def metaDataNodeInfo(registration: bool,version: str) -> {}:
|
||||||
""" /nodeinfo/2.0 endpoint
|
""" /nodeinfo/2.0 endpoint
|
||||||
|
@ -29,3 +31,67 @@ def metaDataNodeInfo(registration: bool,version: str) -> {}:
|
||||||
'version': '2.0'
|
'version': '2.0'
|
||||||
}
|
}
|
||||||
return nodeinfo
|
return nodeinfo
|
||||||
|
|
||||||
|
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 {}
|
||||||
|
|
||||||
|
instance = {
|
||||||
|
'approval_required': False,
|
||||||
|
'contact_account': {'acct': adminActor['preferredUsername'],
|
||||||
|
'avatar': adminActor['icon']['url'],
|
||||||
|
'avatar_static': adminActor['icon']['url'],
|
||||||
|
'bot': False,
|
||||||
|
'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',
|
||||||
|
'locked': False,
|
||||||
|
'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': {
|
||||||
|
'domain_count': 1,
|
||||||
|
'status_count': 1,
|
||||||
|
'user_count': 1
|
||||||
|
},
|
||||||
|
'thumbnail': httpPrefix+'://'+domainFull+'/login.png',
|
||||||
|
'title': instanceTitle,
|
||||||
|
'uri': domainFull,
|
||||||
|
'urls': {},
|
||||||
|
'version': version
|
||||||
|
}
|
||||||
|
|
||||||
|
return instance
|
||||||
|
|
Loading…
Reference in New Issue