Save blogs to their own box

main
Bob Mottram 2020-02-24 22:34:54 +00:00
parent fd24aee2fc
commit 7c37ffcd36
3 changed files with 45 additions and 28 deletions

View File

@ -627,6 +627,7 @@ if args.message:
mediaType=getAttachmentMediaType(attach) mediaType=getAttachmentMediaType(attach)
replyTo=args.replyto replyTo=args.replyto
followersOnly=False followersOnly=False
isArticle=False
print('Sending post to '+args.sendto) print('Sending post to '+args.sendto)
sendPostViaServer(__version__, \ sendPostViaServer(__version__, \
@ -636,7 +637,7 @@ if args.message:
httpPrefix,sendMessage,followersOnly, \ httpPrefix,sendMessage,followersOnly, \
attach,mediaType, \ attach,mediaType, \
attachedImageDescription,useBlurhash, \ attachedImageDescription,useBlurhash, \
cachedWebfingers,personCache, \ cachedWebfingers,personCache,isArticle, \
args.debug,replyTo,replyTo,subject) args.debug,replyTo,replyTo,subject)
for i in range(10): for i in range(10):
# TODO detect send success/fail # TODO detect send success/fail

View File

@ -403,7 +403,7 @@ def getPosts(session,outboxUrl: str,maxPosts: int, \
def deleteAllPosts(baseDir: str,nickname: str, domain: str,boxname: str) -> None: def deleteAllPosts(baseDir: str,nickname: str, domain: str,boxname: str) -> None:
"""Deletes all posts for a person from inbox or outbox """Deletes all posts for a person from inbox or outbox
""" """
if boxname!='inbox' and boxname!='outbox': if boxname!='inbox' and boxname!='outbox' and boxname!='tlblogs':
return return
boxDir = createPersonDir(nickname,domain,baseDir,boxname) boxDir = createPersonDir(nickname,domain,baseDir,boxname)
for deleteFilename in os.scandir(boxDir): for deleteFilename in os.scandir(boxDir):
@ -422,7 +422,8 @@ def savePostToBox(baseDir: str,httpPrefix: str,postId: str, \
"""Saves the give json to the give box """Saves the give json to the give box
Returns the filename Returns the filename
""" """
if boxname!='inbox' and boxname!='outbox' and boxname!='scheduled': if boxname!='inbox' and boxname!='outbox' and \
boxname!='tlblogs' and boxname!='scheduled':
return None return None
originalDomain=domain originalDomain=domain
if ':' in domain: if ':' in domain:
@ -507,7 +508,8 @@ def createPostBase(baseDir: str,nickname: str,domain: str,port: int, \
followersOnly: bool,saveToFile: bool,clientToServer: bool, \ followersOnly: bool,saveToFile: bool,clientToServer: bool, \
attachImageFilename: str, \ attachImageFilename: str, \
mediaType: str,imageDescription: str, \ mediaType: str,imageDescription: str, \
useBlurhash: bool,isModerationReport: bool,inReplyTo=None, \ useBlurhash: bool,isModerationReport: bool,isArticle: bool, \
inReplyTo=None, \
inReplyToAtomUri=None,subject=None, \ inReplyToAtomUri=None,subject=None, \
schedulePost=False, \ schedulePost=False, \
eventDate=None,eventTime=None,location=None) -> {}: eventDate=None,eventTime=None,location=None) -> {}:
@ -766,8 +768,12 @@ def createPostBase(baseDir: str,nickname: str,domain: str,port: int, \
print('Unable to create scheduled post without date and time values') print('Unable to create scheduled post without date and time values')
return newPost return newPost
elif saveToFile: elif saveToFile:
savePostToBox(baseDir,httpPrefix,newPostId, \ if not isArticle:
nickname,domain,newPost,'outbox') savePostToBox(baseDir,httpPrefix,newPostId, \
nickname,domain,newPost,'outbox')
else:
savePostToBox(baseDir,httpPrefix,newPostId, \
nickname,domain,newPost,'tlblogs')
return newPost return newPost
def outboxMessageCreateWrap(httpPrefix: str, \ def outboxMessageCreateWrap(httpPrefix: str, \
@ -889,7 +895,7 @@ def createPublicPost(baseDir: str, \
clientToServer, \ clientToServer, \
attachImageFilename,mediaType, \ attachImageFilename,mediaType, \
imageDescription,useBlurhash, \ imageDescription,useBlurhash, \
False,inReplyTo,inReplyToAtomUri,subject, \ False,False,inReplyTo,inReplyToAtomUri,subject, \
schedulePost,eventDate,eventTime,location) schedulePost,eventDate,eventTime,location)
def createBlogPost(baseDir: str, \ def createBlogPost(baseDir: str, \
@ -938,7 +944,7 @@ def createQuestionPost(baseDir: str,
clientToServer, \ clientToServer, \
attachImageFilename,mediaType, \ attachImageFilename,mediaType, \
imageDescription,useBlurhash, \ imageDescription,useBlurhash, \
False,None,None,subject, \ False,False,None,None,subject, \
False,None,None,None) False,None,None,None)
messageJson['object']['type']='Question' messageJson['object']['type']='Question'
messageJson['object']['oneOf']=[] messageJson['object']['oneOf']=[]
@ -982,7 +988,7 @@ def createUnlistedPost(baseDir: str,
clientToServer, \ clientToServer, \
attachImageFilename,mediaType, \ attachImageFilename,mediaType, \
imageDescription,useBlurhash, \ imageDescription,useBlurhash, \
False,inReplyTo, inReplyToAtomUri, subject, \ False,False,inReplyTo,inReplyToAtomUri,subject, \
schedulePost,eventDate,eventTime,location) schedulePost,eventDate,eventTime,location)
def createFollowersOnlyPost(baseDir: str, def createFollowersOnlyPost(baseDir: str,
@ -1008,7 +1014,7 @@ def createFollowersOnlyPost(baseDir: str,
clientToServer, \ clientToServer, \
attachImageFilename,mediaType, \ attachImageFilename,mediaType, \
imageDescription,useBlurhash, \ imageDescription,useBlurhash, \
False,inReplyTo, inReplyToAtomUri, subject, \ False,False,inReplyTo,inReplyToAtomUri,subject, \
schedulePost,eventDate,eventTime,location) schedulePost,eventDate,eventTime,location)
def getMentionedPeople(baseDir: str,httpPrefix: str, \ def getMentionedPeople(baseDir: str,httpPrefix: str, \
@ -1071,7 +1077,7 @@ def createDirectMessagePost(baseDir: str,
clientToServer, \ clientToServer, \
attachImageFilename,mediaType, \ attachImageFilename,mediaType, \
imageDescription,useBlurhash, \ imageDescription,useBlurhash, \
False,inReplyTo,inReplyToAtomUri,subject, \ False,False,inReplyTo,inReplyToAtomUri,subject, \
schedulePost,eventDate,eventTime,location) schedulePost,eventDate,eventTime,location)
# mentioned recipients go into To rather than Cc # mentioned recipients go into To rather than Cc
messageJson['to']=messageJson['object']['cc'] messageJson['to']=messageJson['object']['cc']
@ -1160,7 +1166,7 @@ def createReportPost(baseDir: str,
clientToServer, \ clientToServer, \
attachImageFilename,mediaType, \ attachImageFilename,mediaType, \
imageDescription,useBlurhash, \ imageDescription,useBlurhash, \
True,None,None,subject, \ True,False,None,None,subject, \
False,None,None,None) False,None,None,None)
if not postJsonObject: if not postJsonObject:
continue continue
@ -1246,6 +1252,7 @@ def sendPost(projectVersion: str, \
imageDescription: str,useBlurhash: bool, \ imageDescription: str,useBlurhash: bool, \
federationList: [],\ federationList: [],\
sendThreads: [], postLog: [], cachedWebfingers: {},personCache: {}, \ sendThreads: [], postLog: [], cachedWebfingers: {},personCache: {}, \
isArticle: bool, \
debug=False,inReplyTo=None,inReplyToAtomUri=None,subject=None) -> int: debug=False,inReplyTo=None,inReplyToAtomUri=None,subject=None) -> int:
"""Post to another inbox """Post to another inbox
""" """
@ -1273,6 +1280,8 @@ def sendPost(projectVersion: str, \
postToBox='inbox' postToBox='inbox'
else: else:
postToBox='outbox' postToBox='outbox'
if isArticle:
postToBox='tlblogs'
# get the actor inbox for the To handle # get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,toPersonId,sharedInbox,capabilityAcquisition,avatarUrl,displayName = \ inboxUrl,pubKeyId,pubKey,toPersonId,sharedInbox,capabilityAcquisition,avatarUrl,displayName = \
@ -1301,7 +1310,7 @@ def sendPost(projectVersion: str, \
followersOnly,saveToFile,clientToServer, \ followersOnly,saveToFile,clientToServer, \
attachImageFilename,mediaType, \ attachImageFilename,mediaType, \
imageDescription,useBlurhash, \ imageDescription,useBlurhash, \
False,inReplyTo,inReplyToAtomUri,subject, \ False,isArticle,inReplyTo,inReplyToAtomUri,subject, \
False,None,None,None) False,None,None,None)
# get the senders private key # get the senders private key
@ -1350,6 +1359,7 @@ def sendPostViaServer(projectVersion: str, \
attachImageFilename: str,mediaType: str, \ attachImageFilename: str,mediaType: str, \
imageDescription: str,useBlurhash: bool, \ imageDescription: str,useBlurhash: bool, \
cachedWebfingers: {},personCache: {}, \ cachedWebfingers: {},personCache: {}, \
isArticle: bool, \
debug=False,inReplyTo=None, \ debug=False,inReplyTo=None, \
inReplyToAtomUri=None,subject=None) -> int: inReplyToAtomUri=None,subject=None) -> int:
"""Send a post via a proxy (c2s) """Send a post via a proxy (c2s)
@ -1376,6 +1386,8 @@ def sendPostViaServer(projectVersion: str, \
return 1 return 1
postToBox='outbox' postToBox='outbox'
if isArticle:
postToBox='tlblogs'
# get the actor inbox for the To handle # get the actor inbox for the To handle
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,displayName = \ inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl,displayName = \
@ -1417,6 +1429,7 @@ def sendPostViaServer(projectVersion: str, \
if ':' not in toDomain: if ':' not in toDomain:
toDomainFull=toDomain+':'+str(toPort) toDomainFull=toDomain+':'+str(toPort)
toPersonId=httpPrefix+'://'+toDomainFull+'/users/'+toNickname toPersonId=httpPrefix+'://'+toDomainFull+'/users/'+toNickname
postJsonObject = \ postJsonObject = \
createPostBase(baseDir, \ createPostBase(baseDir, \
fromNickname,fromDomain,fromPort, \ fromNickname,fromDomain,fromPort, \
@ -1424,7 +1437,7 @@ def sendPostViaServer(projectVersion: str, \
followersOnly,saveToFile,clientToServer, \ followersOnly,saveToFile,clientToServer, \
attachImageFilename,mediaType, \ attachImageFilename,mediaType, \
imageDescription,useBlurhash, \ imageDescription,useBlurhash, \
False,inReplyTo,inReplyToAtomUri,subject, \ False,isArticle,inReplyTo,inReplyToAtomUri,subject, \
False,None,None,None) False,None,None,None)
authHeader=createBasicAuthHeader(fromNickname,password) authHeader=createBasicAuthHeader(fromNickname,password)

View File

@ -422,19 +422,20 @@ def testPostMessageBetweenServers():
mediaType=getAttachmentMediaType(attachedImageFilename) mediaType=getAttachmentMediaType(attachedImageFilename)
attachedImageDescription='Logo' attachedImageDescription='Logo'
useBlurhash=True useBlurhash=True
isArticle=False
# nothing in Alice's outbox # nothing in Alice's outbox
outboxPath=aliceDir+'/accounts/alice@'+aliceDomain+'/outbox' outboxPath=aliceDir+'/accounts/alice@'+aliceDomain+'/outbox'
assert len([name for name in os.listdir(outboxPath) if os.path.isfile(os.path.join(outboxPath, name))])==0 assert len([name for name in os.listdir(outboxPath) if os.path.isfile(os.path.join(outboxPath, name))])==0
sendResult = \ sendResult = \
sendPost(__version__, \ sendPost(__version__, \
sessionAlice,aliceDir,'alice', aliceDomain, alicePort, \ sessionAlice,aliceDir,'alice',aliceDomain,alicePort, \
'bob', bobDomain, bobPort, ccUrl, httpPrefix, \ 'bob',bobDomain,bobPort,ccUrl,httpPrefix, \
'Why is a mouse when it spins? यह एक परीक्षण है #sillyquestion', followersOnly, \ 'Why is a mouse when it spins? यह एक परीक्षण है #sillyquestion',followersOnly, \
saveToFile, clientToServer,attachedImageFilename,mediaType, \ saveToFile,clientToServer,attachedImageFilename,mediaType, \
attachedImageDescription,useBlurhash, federationList, \ attachedImageDescription,useBlurhash,federationList, \
aliceSendThreads, alicePostLog, aliceCachedWebfingers, \ aliceSendThreads,alicePostLog,aliceCachedWebfingers, \
alicePersonCache,inReplyTo, inReplyToAtomUri, subject) alicePersonCache,isArticle,inReplyTo,inReplyToAtomUri,subject)
print('sendResult: '+str(sendResult)) print('sendResult: '+str(sendResult))
queuePath=bobDir+'/accounts/bob@'+bobDomain+'/queue' queuePath=bobDir+'/accounts/bob@'+bobDomain+'/queue'
@ -669,14 +670,15 @@ def testFollowBetweenServers():
aliceCachedWebfingers={} aliceCachedWebfingers={}
alicePostLog=[] alicePostLog=[]
useBlurhash=False useBlurhash=False
isArticle=False
sendResult = \ sendResult = \
sendPost(__version__, \ sendPost(__version__, \
sessionAlice,aliceDir,'alice', aliceDomain, alicePort, \ sessionAlice,aliceDir,'alice',aliceDomain,alicePort, \
'bob', bobDomain, bobPort, ccUrl, \ 'bob',bobDomain,bobPort,ccUrl, \
httpPrefix, 'Alice message', followersOnly, saveToFile, \ httpPrefix,'Alice message',followersOnly,saveToFile, \
clientToServer,None,None,None,useBlurhash, federationList, \ clientToServer,None,None,None,useBlurhash, federationList, \
aliceSendThreads, alicePostLog, aliceCachedWebfingers, \ aliceSendThreads,alicePostLog,aliceCachedWebfingers, \
alicePersonCache,inReplyTo, inReplyToAtomUri, subject) alicePersonCache,isArticle,inReplyTo,inReplyToAtomUri,subject)
print('sendResult: '+str(sendResult)) print('sendResult: '+str(sendResult))
queuePath=bobDir+'/accounts/bob@'+bobDomain+'/queue' queuePath=bobDir+'/accounts/bob@'+bobDomain+'/queue'
@ -1101,6 +1103,7 @@ def testClientToServer():
mediaType=getAttachmentMediaType(attachedImageFilename) mediaType=getAttachmentMediaType(attachedImageFilename)
attachedImageDescription='Logo' attachedImageDescription='Logo'
useBlurhash=False useBlurhash=False
isArticle=False
cachedWebfingers={} cachedWebfingers={}
personCache={} personCache={}
password='alicepass' password='alicepass'
@ -1116,7 +1119,7 @@ def testClientToServer():
httpPrefix,'Sent from my ActivityPub client',followersOnly, \ httpPrefix,'Sent from my ActivityPub client',followersOnly, \
attachedImageFilename,mediaType, \ attachedImageFilename,mediaType, \
attachedImageDescription,useBlurhash, \ attachedImageDescription,useBlurhash, \
cachedWebfingers,personCache, \ cachedWebfingers,personCache,isArticle, \
True,None,None,None) True,None,None,None)
print('sendResult: '+str(sendResult)) print('sendResult: '+str(sendResult))