From 7779ab44e3af8560a9525783625ed5f5b22a257b Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 28 Nov 2019 16:16:43 +0000 Subject: [PATCH] Media instance option --- daemon.py | 69 ++++++++++++++++++++++++++++++++----------------- epicyon.py | 11 +++++++- tests.py | 6 ++--- webinterface.py | 53 +++++++++++++++++++++++-------------- 4 files changed, 92 insertions(+), 47 deletions(-) diff --git a/daemon.py b/daemon.py index bcdfdcba..55160fb7 100644 --- a/daemon.py +++ b/daemon.py @@ -1144,7 +1144,7 @@ class PubServer(BaseHTTPRequestHandler): self.server.baseDir, \ actor,shareName).encode() if not msg: - self._redirect_headers(actor+'/inbox',cookie) + self._redirect_headers(actor+'/tlshares',cookie) return self._set_headers('text/html',len(msg),cookie) self._write(msg) @@ -2069,13 +2069,13 @@ class PubServer(BaseHTTPRequestHandler): if actor not in deleteUrl: # You can only delete your own posts self.server.GETbusy=False - self._redirect_headers(actor+'/inbox',cookie) + self._redirect_headers(actor+'/'+self.server.defaultTimeline,cookie) return self.postToNickname=getNicknameFromActor(actor) if not self.postToNickname: print('WARN: unable to find nickname in '+actor) self.server.GETbusy=False - self._redirect_headers(actor+'/inbox',cookie) + self._redirect_headers(actor+'/'+self.server.defaultTimeline,cookie) return if not self.server.session: self.server.session= \ @@ -2095,7 +2095,7 @@ class PubServer(BaseHTTPRequestHandler): self.server.GETbusy=False return self.server.GETbusy=False - self._redirect_headers(actor+'/inbox',cookie) + self._redirect_headers(actor+'/'+self.server.defaultTimeline,cookie) return # reply from the web interface icon @@ -2572,7 +2572,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.httpPrefix, \ maxPostsInFeed, 'inbox', \ authorized,self.server.ocapAlways) - msg=htmlInbox(self.server.recentPostsCache, \ + msg=htmlInbox(self.server.defaultTimeline, \ + self.server.recentPostsCache, \ self.server.maxRecentPosts, \ self.server.translate, \ pageNumber,maxPostsInFeed, \ @@ -2650,7 +2651,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.httpPrefix, \ maxPostsInFeed, 'dm', \ authorized,self.server.ocapAlways) - msg=htmlInboxDMs(self.server.recentPostsCache, \ + msg=htmlInboxDMs(self.server.defaultTimeline, \ + self.server.recentPostsCache, \ self.server.maxRecentPosts, \ self.server.translate, \ pageNumber,maxPostsInFeed, \ @@ -2729,7 +2731,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.httpPrefix, \ maxPostsInFeed, 'tlreplies', \ True,self.server.ocapAlways) - msg=htmlInboxReplies(self.server.recentPostsCache, \ + msg=htmlInboxReplies(self.server.defaultTimeline, \ + self.server.recentPostsCache, \ self.server.maxRecentPosts, \ self.server.translate, \ pageNumber,maxPostsInFeed, \ @@ -2808,7 +2811,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.httpPrefix, \ maxPostsInMediaFeed, 'tlmedia', \ True,self.server.ocapAlways) - msg=htmlInboxMedia(self.server.recentPostsCache, \ + msg=htmlInboxMedia(self.server.defaultTimeline, \ + self.server.recentPostsCache, \ self.server.maxRecentPosts, \ self.server.translate, \ pageNumber,maxPostsInMediaFeed, \ @@ -2863,7 +2867,8 @@ class PubServer(BaseHTTPRequestHandler): pageNumber=int(pageNumber) else: pageNumber=1 - msg=htmlShares(self.server.recentPostsCache, \ + msg=htmlShares(self.server.defaultTimeline, \ + self.server.recentPostsCache, \ self.server.maxRecentPosts, \ self.server.translate, \ pageNumber,maxPostsInFeed, \ @@ -2926,7 +2931,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.httpPrefix, \ maxPostsInFeed, 'tlbookmarks', \ authorized,self.server.ocapAlways) - msg=htmlBookmarks(self.server.recentPostsCache, \ + msg=htmlBookmarks(self.server.defaultTimeline, \ + self.server.recentPostsCache, \ self.server.maxRecentPosts, \ self.server.translate, \ pageNumber,maxPostsInFeed, \ @@ -3000,7 +3006,8 @@ class PubServer(BaseHTTPRequestHandler): maxPostsInFeed, 'outbox', \ authorized, \ self.server.ocapAlways) - msg=htmlOutbox(self.server.recentPostsCache, \ + msg=htmlOutbox(self.server.defaultTimeline, \ + self.server.recentPostsCache, \ self.server.maxRecentPosts, \ self.server.translate, \ pageNumber,maxPostsInFeed, \ @@ -3068,7 +3075,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.httpPrefix, \ maxPostsInFeed, 'moderation', \ True,self.server.ocapAlways) - msg=htmlModeration(self.server.recentPostsCache, \ + msg=htmlModeration(self.server.defaultTimeline, \ + self.server.recentPostsCache, \ self.server.maxRecentPosts, \ self.server.translate, \ pageNumber,maxPostsInFeed, \ @@ -3885,7 +3893,7 @@ class PubServer(BaseHTTPRequestHandler): self.send_header('Location', \ self.server.httpPrefix+'://'+ \ self.server.domainFull+ \ - '/users/'+loginNickname+'/inbox') + '/users/'+loginNickname+'/'+self.server.defaultTimeline) self.send_header('Content-Length', '0') self.send_header('X-Robots-Tag','noindex') self.end_headers() @@ -4348,7 +4356,7 @@ class PubServer(BaseHTTPRequestHandler): self.server.domainFull+self.path.replace('/question','') nickname=getNicknameFromActor(actor) if not nickname: - self._redirect_headers(actor+'/inbox?page='+ \ + self._redirect_headers(actor+'/'+self.server.defaultTimeline+'?page='+ \ str(pageNumber),cookie) self.server.POSTbusy=False return @@ -4369,7 +4377,8 @@ class PubServer(BaseHTTPRequestHandler): if '&' in answer: answer=answer.split('&')[0] self._sendReplyToQuestion(nickname,messageId,answer) - self._redirect_headers(actor+'/inbox?page='+str(pageNumber),cookie) + self._redirect_headers(actor+'/'+self.server.defaultTimeline+ \ + '?page='+str(pageNumber),cookie) self.server.POSTbusy=False return @@ -4498,7 +4507,7 @@ class PubServer(BaseHTTPRequestHandler): self._write(msg) self.server.POSTbusy=False return - self._redirect_headers(actorStr+'/inbox',cookie) + self._redirect_headers(actorStr+'/'+self.server.defaultTimeline,cookie) self.server.POSTbusy=False return @@ -4904,7 +4913,8 @@ class PubServer(BaseHTTPRequestHandler): nickname=thisActor.split('/users/')[1] personSnooze(self.server.baseDir,nickname,self.server.domain,optionsActor) self._redirect_headers(thisActor+ \ - '/inbox?page='+str(pageNumber),cookie) + '/'+self.server.defaultTimeline+ \ + '?page='+str(pageNumber),cookie) self.server.POSTbusy=False return if '&submitUnSnooze=' in optionsConfirmParams: @@ -4917,7 +4927,8 @@ class PubServer(BaseHTTPRequestHandler): nickname=thisActor.split('/users/')[1] personUnsnooze(self.server.baseDir,nickname,self.server.domain,optionsActor) self._redirect_headers(thisActor+ \ - '/inbox?page='+str(pageNumber),cookie) + '/'+self.server.defaultTimeline+ \ + '?page='+str(pageNumber),cookie) self.server.POSTbusy=False return if '&submitReport=' in optionsConfirmParams: @@ -4946,7 +4957,8 @@ class PubServer(BaseHTTPRequestHandler): nickname=nickname.split('/')[0] self._redirect_headers(self.server.httpPrefix+'://'+self.server.domainFull+ \ '/users/'+nickname+ \ - '/inbox?page='+str(pageNumber),cookie) + '/'+self.server.defaultTimeline+ \ + '?page='+str(pageNumber),cookie) self.server.POSTbusy=False return pageNumber=self._receiveNewPost(authorized,'newunlisted',self.path) @@ -4956,7 +4968,8 @@ class PubServer(BaseHTTPRequestHandler): nickname=nickname.split('/')[0] self._redirect_headers(self.server.httpPrefix+'://'+self.server.domainFull+ \ '/users/'+nickname+ \ - '/inbox?page='+str(pageNumber),cookie) + '/'+self.server.defaultTimeline+ \ + '?page='+str(pageNumber),cookie) self.server.POSTbusy=False return pageNumber=self._receiveNewPost(authorized,'newfollowers',self.path) @@ -4966,7 +4979,8 @@ class PubServer(BaseHTTPRequestHandler): nickname=nickname.split('/')[0] self._redirect_headers(self.server.httpPrefix+'://'+self.server.domainFull+ \ '/users/'+nickname+ \ - '/inbox?page='+str(pageNumber),cookie) + '/'+self.server.defaultTimeline+ \ + '?page='+str(pageNumber),cookie) self.server.POSTbusy=False return pageNumber=self._receiveNewPost(authorized,'newdm',self.path) @@ -4976,7 +4990,8 @@ class PubServer(BaseHTTPRequestHandler): nickname=nickname.split('/')[0] self._redirect_headers(self.server.httpPrefix+'://'+self.server.domainFull+ \ '/users/'+nickname+ \ - '/inbox?page='+str(pageNumber),cookie) + '/'+self.server.defaultTimeline+ \ + '?page='+str(pageNumber),cookie) self.server.POSTbusy=False return pageNumber=self._receiveNewPost(authorized,'newreport',self.path) @@ -4986,7 +5001,8 @@ class PubServer(BaseHTTPRequestHandler): nickname=nickname.split('/')[0] self._redirect_headers(self.server.httpPrefix+'://'+self.server.domainFull+ \ '/users/'+nickname+ \ - '/inbox?page='+str(pageNumber),cookie) + '/'+self.server.defaultTimeline+ \ + '?page='+str(pageNumber),cookie) self.server.POSTbusy=False return pageNumber=self._receiveNewPost(authorized,'newshare',self.path) @@ -5321,7 +5337,7 @@ def loadTokens(baseDir: str,tokensDict: {},tokensLookup: {}) -> None: tokensDict[nickname]=token tokensLookup[token]=nickname -def runDaemon(maxRecentPosts: int, \ +def runDaemon(mediaInstance: bool,maxRecentPosts: int, \ enableSharedInbox: bool,registration: bool, \ language: str,projectVersion: str, \ instanceId: str,clientToServer: bool, \ @@ -5348,6 +5364,11 @@ def runDaemon(maxRecentPosts: int, \ else: httpd = ThreadingHTTPServer(serverAddress, PubServer) + httpd.mediaInstance=mediaInstance + httpd.defaultTimeline='inbox' + if mediaInstance: + httpd.defaultTimeline='tlmedia' + # load translations dictionary httpd.translate={} httpd.systemLanguage='en' diff --git a/epicyon.py b/epicyon.py index 05844203..0fd2cd5d 100644 --- a/epicyon.py +++ b/epicyon.py @@ -148,6 +148,9 @@ parser.add_argument('--json', dest='json', type=str,default=None, \ help='Show the json for a given activitypub url') parser.add_argument('-f','--federate', nargs='+',dest='federationList', \ help='Specify federation list separated by spaces') +parser.add_argument("--mediainstance", type=str2bool, nargs='?', \ + const=True, default=False, \ + help="Media Instance - favor media over text") parser.add_argument("--debug", type=str2bool, nargs='?', \ const=True, default=False, \ help="Show debug messages") @@ -376,6 +379,11 @@ if not themeName: setConfigParam(baseDir,'theme','default') themeName='default' +if not args.mediainstance: + mediaInstance=getConfigParam(baseDir,'mediaInstance') + if mediaInstance!=None: + args.mediainstance=mediaInstance + # set the instance title in config.json title=getConfigParam(baseDir,'instanceTitle') if not title: @@ -1486,7 +1494,8 @@ if not registration: if setTheme(baseDir,themeName): print('Theme set to '+themeName) -runDaemon(args.maxRecentPosts,not args.nosharedinbox, \ +runDaemon(args.mediainstance,args.maxRecentPosts, \ + not args.nosharedinbox, \ registration,args.language,__version__, \ instanceId,args.client,baseDir, \ domain,port,proxyPort,httpPrefix, \ diff --git a/tests.py b/tests.py index 2fd85d21..a542a4b2 100644 --- a/tests.py +++ b/tests.py @@ -233,7 +233,7 @@ def createServerAlice(path: str,domain: str,port: int,federationList: [], \ maxMentions=10 maxEmoji=10 print('Server running: Alice') - runDaemon(5,True,True,'en',__version__, \ + runDaemon(False,5,True,True,'en',__version__, \ "instanceId",False,path,domain,port,port, \ httpPrefix,federationList,maxMentions,maxEmoji,False, \ noreply,nolike,nopics,noannounce,cw,ocapAlways, \ @@ -289,7 +289,7 @@ def createServerBob(path: str,domain: str,port: int,federationList: [], \ maxMentions=10 maxEmoji=10 print('Server running: Bob') - runDaemon(5,True,True,'en',__version__, \ + runDaemon(False,5,True,True,'en',__version__, \ "instanceId",False,path,domain,port,port, \ httpPrefix,federationList,maxMentions,maxEmoji,False, \ noreply,nolike,nopics,noannounce,cw,ocapAlways, \ @@ -325,7 +325,7 @@ def createServerEve(path: str,domain: str,port: int,federationList: [], \ maxMentions=10 maxEmoji=10 print('Server running: Eve') - runDaemon(5,True,True,'en',__version__, \ + runDaemon(False,5,True,True,'en',__version__, \ "instanceId",False,path,domain,port,port, \ httpPrefix,federationList,maxMentions,maxEmoji,False, \ noreply,nolike,nopics,noannounce,cw,ocapAlways, \ diff --git a/webinterface.py b/webinterface.py index d53f7e28..c2d50336 100644 --- a/webinterface.py +++ b/webinterface.py @@ -2494,7 +2494,8 @@ def isQuestion(postObjectJson: {}) -> bool: return False return True -def htmlTimeline(recentPostsCache: {},maxRecentPosts: int, +def htmlTimeline(defaultTimeline: str, \ + recentPostsCache: {},maxRecentPosts: int, \ translate: {},pageNumber: int, \ itemsPerPage: int,session,baseDir: str, \ wfRequest: {},personCache: {}, \ @@ -2659,10 +2660,16 @@ def htmlTimeline(recentPostsCache: {},maxRecentPosts: int, tlStr+='
' tlStr+='
' tlStr+='
\n' - tlStr+=' ' + if defaultTimeline!='tlmedia': + tlStr+=' ' + else: + tlStr+=' ' tlStr+=' ' tlStr+=' ' - tlStr+=' ' + if defaultTimeline!='tlmedia': + tlStr+=' ' + else: + tlStr+=' ' tlStr+=' ' tlStr+=sharesButtonStr+bookmarksButtonStr+moderationButtonStr+newPostButtonStr tlStr+=' '+translate['Search and follow']+'' @@ -2747,7 +2754,8 @@ def htmlTimeline(recentPostsCache: {},maxRecentPosts: int, tlStr+=htmlFooter() return tlStr -def htmlShares(recentPostsCache: {},maxRecentPosts: int, \ +def htmlShares(defaultTimeline: str, \ + recentPostsCache: {},maxRecentPosts: int, \ translate: {},pageNumber: int,itemsPerPage: int, \ session,baseDir: str,wfRequest: {},personCache: {}, \ nickname: str,domain: str,port: int, \ @@ -2758,13 +2766,14 @@ def htmlShares(recentPostsCache: {},maxRecentPosts: int, \ manuallyApproveFollowers= \ followerApprovalActive(baseDir,nickname,domain) - return htmlTimeline(recentPostsCache,maxRecentPosts, \ + return htmlTimeline(defaultTimeline,recentPostsCache,maxRecentPosts, \ translate,pageNumber, \ itemsPerPage,session,baseDir,wfRequest,personCache, \ nickname,domain,port,None,'tlshares',allowDeletion, \ httpPrefix,projectVersion,manuallyApproveFollowers) -def htmlInbox(recentPostsCache: {},maxRecentPosts: int, \ +def htmlInbox(defaultTimeline: str, \ + recentPostsCache: {},maxRecentPosts: int, \ translate: {},pageNumber: int,itemsPerPage: int, \ session,baseDir: str,wfRequest: {},personCache: {}, \ nickname: str,domain: str,port: int,inboxJson: {}, \ @@ -2775,13 +2784,14 @@ def htmlInbox(recentPostsCache: {},maxRecentPosts: int, \ manuallyApproveFollowers= \ followerApprovalActive(baseDir,nickname,domain) - return htmlTimeline(recentPostsCache,maxRecentPosts, \ + return htmlTimeline(defaultTimeline,recentPostsCache,maxRecentPosts, \ translate,pageNumber, \ itemsPerPage,session,baseDir,wfRequest,personCache, \ nickname,domain,port,inboxJson,'inbox',allowDeletion, \ httpPrefix,projectVersion,manuallyApproveFollowers) -def htmlBookmarks(recentPostsCache: {},maxRecentPosts: int, \ +def htmlBookmarks(defaultTimeline: str, \ + recentPostsCache: {},maxRecentPosts: int, \ translate: {},pageNumber: int,itemsPerPage: int, \ session,baseDir: str,wfRequest: {},personCache: {}, \ nickname: str,domain: str,port: int,bookmarksJson: {}, \ @@ -2792,13 +2802,14 @@ def htmlBookmarks(recentPostsCache: {},maxRecentPosts: int, \ manuallyApproveFollowers= \ followerApprovalActive(baseDir,nickname,domain) - return htmlTimeline(recentPostsCache,maxRecentPosts, \ + return htmlTimeline(defaultTimeline,recentPostsCache,maxRecentPosts, \ translate,pageNumber, \ itemsPerPage,session,baseDir,wfRequest,personCache, \ nickname,domain,port,bookmarksJson,'tlbookmarks',allowDeletion, \ httpPrefix,projectVersion,manuallyApproveFollowers) -def htmlInboxDMs(recentPostsCache: {},maxRecentPosts: int, \ +def htmlInboxDMs(defaultTimeline: str, \ + recentPostsCache: {},maxRecentPosts: int, \ translate: {},pageNumber: int,itemsPerPage: int, \ session,baseDir: str,wfRequest: {},personCache: {}, \ nickname: str,domain: str,port: int,inboxJson: {}, \ @@ -2806,13 +2817,14 @@ def htmlInboxDMs(recentPostsCache: {},maxRecentPosts: int, \ httpPrefix: str,projectVersion: str) -> str: """Show the DM timeline as html """ - return htmlTimeline(recentPostsCache,maxRecentPosts, \ + return htmlTimeline(defaultTimeline,recentPostsCache,maxRecentPosts, \ translate,pageNumber, \ itemsPerPage,session,baseDir,wfRequest,personCache, \ nickname,domain,port,inboxJson,'dm',allowDeletion, \ httpPrefix,projectVersion,False) -def htmlInboxReplies(recentPostsCache: {},maxRecentPosts: int, \ +def htmlInboxReplies(defaultTimeline: str, \ + recentPostsCache: {},maxRecentPosts: int, \ translate: {},pageNumber: int,itemsPerPage: int, \ session,baseDir: str,wfRequest: {},personCache: {}, \ nickname: str,domain: str,port: int,inboxJson: {}, \ @@ -2820,13 +2832,14 @@ def htmlInboxReplies(recentPostsCache: {},maxRecentPosts: int, \ httpPrefix: str,projectVersion: str) -> str: """Show the replies timeline as html """ - return htmlTimeline(recentPostsCache,maxRecentPosts, \ + return htmlTimeline(defaultTimeline,recentPostsCache,maxRecentPosts, \ translate,pageNumber, \ itemsPerPage,session,baseDir,wfRequest,personCache, \ nickname,domain,port,inboxJson,'tlreplies',allowDeletion, \ httpPrefix,projectVersion,False) -def htmlInboxMedia(recentPostsCache: {},maxRecentPosts: int, \ +def htmlInboxMedia(defaultTimeline: str, \ + recentPostsCache: {},maxRecentPosts: int, \ translate: {},pageNumber: int,itemsPerPage: int, \ session,baseDir: str,wfRequest: {},personCache: {}, \ nickname: str,domain: str,port: int,inboxJson: {}, \ @@ -2834,13 +2847,14 @@ def htmlInboxMedia(recentPostsCache: {},maxRecentPosts: int, \ httpPrefix: str,projectVersion: str) -> str: """Show the media timeline as html """ - return htmlTimeline(recentPostsCache,maxRecentPosts, \ + return htmlTimeline(defaultTimeline,recentPostsCache,maxRecentPosts, \ translate,pageNumber, \ itemsPerPage,session,baseDir,wfRequest,personCache, \ nickname,domain,port,inboxJson,'tlmedia',allowDeletion, \ httpPrefix,projectVersion,False) -def htmlModeration(recentPostsCache: {},maxRecentPosts: int, \ +def htmlModeration(defaultTimeline: str, \ + recentPostsCache: {},maxRecentPosts: int, \ translate: {},pageNumber: int,itemsPerPage: int, \ session,baseDir: str,wfRequest: {},personCache: {}, \ nickname: str,domain: str,port: int,inboxJson: {}, \ @@ -2848,13 +2862,14 @@ def htmlModeration(recentPostsCache: {},maxRecentPosts: int, \ httpPrefix: str,projectVersion: str) -> str: """Show the moderation feed as html """ - return htmlTimeline(recentPostsCache,maxRecentPosts, \ + return htmlTimeline(defaultTimeline,recentPostsCache,maxRecentPosts, \ translate,pageNumber, \ itemsPerPage,session,baseDir,wfRequest,personCache, \ nickname,domain,port,inboxJson,'moderation',allowDeletion, \ httpPrefix,projectVersion,True) -def htmlOutbox(recentPostsCache: {},maxRecentPosts: int, \ +def htmlOutbox(defaultTimeline: str, \ + recentPostsCache: {},maxRecentPosts: int, \ translate: {},pageNumber: int,itemsPerPage: int, \ session,baseDir: str,wfRequest: {},personCache: {}, \ nickname: str,domain: str,port: int,outboxJson: {}, \ @@ -2864,7 +2879,7 @@ def htmlOutbox(recentPostsCache: {},maxRecentPosts: int, \ """ manuallyApproveFollowers= \ followerApprovalActive(baseDir,nickname,domain) - return htmlTimeline(recentPostsCache,maxRecentPosts, \ + return htmlTimeline(defaultTimeline,recentPostsCache,maxRecentPosts, \ translate,pageNumber, \ itemsPerPage,session,baseDir,wfRequest,personCache, \ nickname,domain,port,outboxJson,'outbox',allowDeletion, \