GET on outbox

master
Bob Mottram 2019-06-29 15:35:26 +01:00
parent e2aaa123d7
commit ed39eb1ac6
3 changed files with 41 additions and 9 deletions

View File

@ -17,6 +17,7 @@ from webfinger import webfingerMeta
from webfinger import webfingerLookup
from person import personLookup
from person import personKeyLookup
from person import personOutboxJson
from inbox import inboxPermittedMessage
import os
import sys
@ -30,6 +31,12 @@ federationList=[]
# Avoid giant messages
maxMessageLength=5000
# maximum number of posts to list in outbox feed
maxPostsInFeed=20
# Whether to use https
useHttps=True
def readFollowList(filename: str):
"""Returns a list of ActivityPub addresses to follow
"""
@ -89,6 +96,13 @@ class PubServer(BaseHTTPRequestHandler):
# get webfinger endpoint for a person
if self._webfinger():
return
# get outbox feed for a person
outboxHeader,outboxFeed=personOutboxJson(thisDomain,self.path,useHttps,maxPostsInFeed)
if outboxHeader and outboxFeed:
self._set_headers('application/json')
outboxFeedList=[outboxHeader,outboxFeed]
self.wfile.write(json.dumps(outboxFeedList).encode('utf-8'))
return
# look up a person
getPerson = personLookup(thisDomain,self.path)
if getPerson:

View File

@ -38,16 +38,16 @@ privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(username,domain,https,
setPreferredUsername(username,domain,'badger')
setBio(username,domain,'Some personal info')
#createPublicPost(username, domain, https, "G'day world!", False, True, None, None, 'Not suitable for Vogons')
archivePosts(username,domain,4)
outboxHeader,outboxJson=createOutbox(username,domain,https,3,None)
pprint(outboxHeader)
print('\n')
pprint(outboxJson)
#archivePosts(username,domain,4)
#outboxHeader,outboxJson=createOutbox(username,domain,https,3,None)
#pprint(outboxHeader)
#print('\n')
#pprint(outboxJson)
#runDaemon(domain,port,federationList,useTor)
runDaemon(domain,port,federationList,useTor)
#testHttpsig()
sys.exit()
#sys.exit()
#pprint(person)
#print('\n')

View File

@ -13,6 +13,7 @@ import fileinput
from Crypto.PublicKey import RSA
from webfinger import createWebfingerEndpoint
from webfinger import storeWebfingerEndpoint
from posts import createOutbox
def generateRSAKey() -> (str,str):
key = RSA.generate(2048)
@ -136,7 +137,7 @@ def personKeyLookup(domain: str,path: str) -> str:
def personLookup(domain: str,path: str) -> {}:
"""Lookup the person for an given username
"""
notPersonLookup=['/inbox','/outbox','/followers','/following','/featured','.png','.jpg','.gif','.mpv','#main-key','/main-key']
notPersonLookup=['/inbox','/outbox','/outboxarchive','/followers','/following','/featured','.png','.jpg','.gif','.mpv','#main-key','/main-key']
for ending in notPersonLookup:
if path.endswith(ending):
return None
@ -158,7 +159,24 @@ def personLookup(domain: str,path: str) -> {}:
with open(filename, 'r') as fp:
personJson=commentjson.load(fp)
return personJson
def personOutboxJson(domain: str,path: str,https: bool,noOfItems: int) -> ({},{}):
"""Obtain the outbox feed for the given person
"""
if not path.endswith('/outbox'):
return None,None
username=None
if path.startswith('/users/'):
username=path.replace('/users/','',1).replace('/outbox','')
if path.startswith('/@'):
username=path.replace('/@','',1).replace('/outbox','')
if not username:
return None,None
if not validUsername(username):
return None,None
startMessageId=None
return createOutbox(username,domain,https,noOfItems,startMessageId)
def setPreferredUsername(username: str, domain: str, preferredName: str) -> bool:
if len(preferredName)>32:
return False