Create id of object

master
Bob Mottram 2019-07-03 23:59:56 +01:00
parent 4ef93d01c5
commit 6602d0b78e
2 changed files with 28 additions and 15 deletions

View File

@ -107,8 +107,9 @@ class PubServer(BaseHTTPRequestHandler):
Client to server message post
https://www.w3.org/TR/activitypub/#client-to-server-outbox-delivery
"""
if not messageJson.get('object'):
if messageJson.get('type') and messageJson.get('content'):
if not messageJson.get('type'):
return False
if not messageJson.get('object') and messageJson.get('content'):
if messageJson['type']!='Create':
# https://www.w3.org/TR/activitypub/#object-without-create
if self.server.debug:
@ -134,7 +135,11 @@ class PubServer(BaseHTTPRequestHandler):
if self.server.debug:
print('DEBUG POST to outbox: '+messageJson['type']+' is not a permitted activity type')
return False
savePostToOutbox(self.server.baseDir,messageJson['id'],self.postToNickname,self.server.domain,messageJson)
if messageJson.get('id'):
postId=messageJson['id']
else:
postId=None
savePostToOutbox(self.server.baseDir,postId,self.postToNickname,self.server.domain,messageJson)
return True
def do_GET(self):

View File

@ -249,11 +249,19 @@ def deleteAllPosts(baseDir: str,nickname: str, domain: str) -> None:
except Exception as e:
print(e)
def savePostToOutbox(baseDir: str,postId: str,nickname: str, domain: str,postJson: {}) -> None:
def savePostToOutbox(baseDir: str,httpPrefix: str,postId: str,nickname: str, domain: str,postJson: {}) -> None:
"""Saves the give json to the outbox
"""
if ':' in domain:
domain=domain.split(':')[0]
if not postId:
statusNumber,published = getStatusNumber()
postId=httpPrefix+'://'+domain+'/users/'+nickname+'/statuses/'+statusNumber
postJson['id']=postId+'/activity'
if postJson.get('object'):
postJson['object']['id']=postId
postJson['object']['atomUri']=postId
outboxDir = createOutboxDir(nickname,domain,baseDir)
filename=outboxDir+'/'+postId.replace('/','#')+'.json'
with open(filename, 'w') as fp:
@ -301,7 +309,7 @@ def createPostBase(baseDir: str,nickname: str, domain: str, port: int, \
'to': [toUrl],
'cc': [],
'sensitive': sensitive,
'atomUri': httpPrefix+'://'+domain+'/users/'+nickname+'/statuses/'+statusNumber,
'atomUri': newPostId,
'inReplyToAtomUri': inReplyToAtomUri,
'conversation': 'tag:'+domain+','+conversationDate+':objectId='+conversationId+':objectType=Conversation',
'content': content,
@ -333,7 +341,7 @@ def createPostBase(baseDir: str,nickname: str, domain: str, port: int, \
'to': [toUrl],
'cc': [],
'sensitive': sensitive,
'atomUri': httpPrefix+'://'+domain+'/users/'+nickname+'/statuses/'+statusNumber,
'atomUri': newPostId,
'inReplyToAtomUri': inReplyToAtomUri,
'conversation': 'tag:'+domain+','+conversationDate+':objectId='+conversationId+':objectType=Conversation',
'content': content,
@ -349,7 +357,7 @@ def createPostBase(baseDir: str,nickname: str, domain: str, port: int, \
newPost['cc']=ccUrl
newPost['object']['cc']=ccUrl
if saveToFile:
savePostToOutbox(baseDir,newPostId,nickname,domain,newPost)
savePostToOutbox(baseDir,httpPrefix,newPostId,nickname,domain,newPost)
return newPost
def outboxMessageCreateWrap(httpPrefix str,nickname: str,domain: str,messageJson: {}) -> {}: