From d3598b861a44f8a4b5c059f636961394ca701af4 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 23 Jul 2019 21:00:17 +0100 Subject: [PATCH] Uploading shared items --- daemon.py | 7 +++++++ shares.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/daemon.py b/daemon.py index 2b93c081..b0884584 100644 --- a/daemon.py +++ b/daemon.py @@ -50,6 +50,7 @@ from webinterface import htmlInbox from webinterface import htmlOutbox from webinterface import htmlPostReplies from shares import getSharesFeedForPerson +from shares import outboxShareUpload import os import sys @@ -267,6 +268,12 @@ class PubServer(BaseHTTPRequestHandler): self.postToNickname,self.server.domain, \ self.server.port, messageJson,self.server.debug) + if self.server.debug: + print('DEBUG: handle share uploads') + outboxShareUpload(self.server.baseDir,self.server.httpPrefix, \ + self.postToNickname,self.server.domain, \ + self.server.port, + messageJson,self.server.debug) if self.server.debug: print('DEBUG: sending c2s post to named addresses') print('c2s sender: '+self.postToNickname+'@'+self.server.domain+':'+str(self.server.port)) diff --git a/shares.py b/shares.py index f71e7ff1..d4c381bd 100644 --- a/shares.py +++ b/shares.py @@ -341,3 +341,60 @@ def sendShareViaServer(session,fromNickname: str,password: str, print('DEBUG: c2s POST like success') return newShareJson + +def outboxShareUpload(baseDir: str,httpPrefix: str, \ + nickname: str,domain: str,port: int, \ + messageJson: {},debug: bool) -> None: + """ When a shared item is received by the outbox from c2s + """ + if not messageJson.get('type'): + return + if not messageJson['type']=='Add': + return + if not messageJson.get('object'): + return + if not isinstance(messageJson['object'], dict): + return + if not messageJson['object'].get('type'): + if debug: + print('DEBUG: undo block - no type') + return + if not messageJson['object']['type']=='Offer': + if debug: + print('DEBUG: not an Offer activity') + return + if not messageJson['object'].get('displayName'): + if debug: + print('DEBUG: displayName missing from Offer') + return + if not messageJson['object'].get('summary'): + if debug: + print('DEBUG: summary missing from Offer') + return + if not messageJson['object'].get('itemType'): + if debug: + print('DEBUG: itemType missing from Offer') + return + if not messageJson['object'].get('category'): + if debug: + print('DEBUG: category missing from Offer') + return + if not messageJson['object'].get('location'): + if debug: + print('DEBUG: location missing from Offer') + return + if not messageJson['object'].get('duration'): + if debug: + print('DEBUG: duration missing from Offer') + return + addShare(baseDir,nickname,domain, \ + messageJson['object']['displayName'], \ + messageJson['object']['summary'], \ + messageJson['object']['imageFilename'], \ + messageJson['object']['itemType'], \ + messageJson['object']['itemCategory'], \ + messageJson['object']['location'], \ + messageJson['object']['duration'], \ + debug) + if debug: + print('DEBUG: shared item received via c2s')