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 webfinger import webfingerLookup
from person import personLookup from person import personLookup
from person import personKeyLookup from person import personKeyLookup
from person import personOutboxJson
from inbox import inboxPermittedMessage from inbox import inboxPermittedMessage
import os import os
import sys import sys
@ -30,6 +31,12 @@ federationList=[]
# Avoid giant messages # Avoid giant messages
maxMessageLength=5000 maxMessageLength=5000
# maximum number of posts to list in outbox feed
maxPostsInFeed=20
# Whether to use https
useHttps=True
def readFollowList(filename: str): def readFollowList(filename: str):
"""Returns a list of ActivityPub addresses to follow """Returns a list of ActivityPub addresses to follow
""" """
@ -89,6 +96,13 @@ class PubServer(BaseHTTPRequestHandler):
# get webfinger endpoint for a person # get webfinger endpoint for a person
if self._webfinger(): if self._webfinger():
return 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 # look up a person
getPerson = personLookup(thisDomain,self.path) getPerson = personLookup(thisDomain,self.path)
if getPerson: if getPerson:

View File

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

View File

@ -13,6 +13,7 @@ import fileinput
from Crypto.PublicKey import RSA from Crypto.PublicKey import RSA
from webfinger import createWebfingerEndpoint from webfinger import createWebfingerEndpoint
from webfinger import storeWebfingerEndpoint from webfinger import storeWebfingerEndpoint
from posts import createOutbox
def generateRSAKey() -> (str,str): def generateRSAKey() -> (str,str):
key = RSA.generate(2048) key = RSA.generate(2048)
@ -136,7 +137,7 @@ def personKeyLookup(domain: str,path: str) -> str:
def personLookup(domain: str,path: str) -> {}: def personLookup(domain: str,path: str) -> {}:
"""Lookup the person for an given username """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: for ending in notPersonLookup:
if path.endswith(ending): if path.endswith(ending):
return None return None
@ -159,6 +160,23 @@ def personLookup(domain: str,path: str) -> {}:
personJson=commentjson.load(fp) personJson=commentjson.load(fp)
return personJson 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: def setPreferredUsername(username: str, domain: str, preferredName: str) -> bool:
if len(preferredName)>32: if len(preferredName)>32:
return False return False