From ed39eb1ac62f55ffdcb359d33893790582dbf645 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 29 Jun 2019 15:35:26 +0100 Subject: [PATCH] GET on outbox --- daemon.py | 14 ++++++++++++++ epicyon.py | 14 +++++++------- person.py | 22 ++++++++++++++++++++-- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/daemon.py b/daemon.py index 16537f5e..3eeac0f9 100644 --- a/daemon.py +++ b/daemon.py @@ -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: diff --git a/epicyon.py b/epicyon.py index 6b14c50a..8d528b4c 100644 --- a/epicyon.py +++ b/epicyon.py @@ -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') diff --git a/person.py b/person.py index c334917b..c586e9fb 100644 --- a/person.py +++ b/person.py @@ -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