mirror of https://gitlab.com/bashrc2/epicyon
Move blogs timeline to its own method
parent
7ca102b169
commit
c0f2d3de90
210
daemon.py
210
daemon.py
|
@ -5757,6 +5757,107 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def _showBlogsTimeline(self, authorized: bool,
|
||||||
|
callingDomain: str, path: str,
|
||||||
|
baseDir: str, httpPrefix: str,
|
||||||
|
domain: str, domainFull: str, port: int,
|
||||||
|
onionDomain: str, i2pDomain: str,
|
||||||
|
GETstartTime, GETtimings: {},
|
||||||
|
proxyType: str, cookie: str,
|
||||||
|
debug: str) -> bool:
|
||||||
|
"""Shows the blogs timeline
|
||||||
|
"""
|
||||||
|
if '/users/' in path:
|
||||||
|
if authorized:
|
||||||
|
inboxBlogsFeed = \
|
||||||
|
personBoxJson(self.server.recentPostsCache,
|
||||||
|
self.server.session,
|
||||||
|
baseDir,
|
||||||
|
domain,
|
||||||
|
port,
|
||||||
|
path,
|
||||||
|
httpPrefix,
|
||||||
|
maxPostsInBlogsFeed, 'tlblogs',
|
||||||
|
True, self.server.ocapAlways)
|
||||||
|
if not inboxBlogsFeed:
|
||||||
|
inboxBlogsFeed = []
|
||||||
|
if self._requestHTTP():
|
||||||
|
nickname = path.replace('/users/', '')
|
||||||
|
nickname = nickname.replace('/tlblogs', '')
|
||||||
|
pageNumber = 1
|
||||||
|
if '?page=' in nickname:
|
||||||
|
pageNumber = nickname.split('?page=')[1]
|
||||||
|
nickname = nickname.split('?page=')[0]
|
||||||
|
if pageNumber.isdigit():
|
||||||
|
pageNumber = int(pageNumber)
|
||||||
|
else:
|
||||||
|
pageNumber = 1
|
||||||
|
if 'page=' not in path:
|
||||||
|
# if no page was specified then show the first
|
||||||
|
inboxBlogsFeed = \
|
||||||
|
personBoxJson(self.server.recentPostsCache,
|
||||||
|
self.server.session,
|
||||||
|
baseDir,
|
||||||
|
domain,
|
||||||
|
port,
|
||||||
|
path + '?page=1',
|
||||||
|
httpPrefix,
|
||||||
|
maxPostsInBlogsFeed, 'tlblogs',
|
||||||
|
True, self.server.ocapAlways)
|
||||||
|
msg = \
|
||||||
|
htmlInboxBlogs(self.server.defaultTimeline,
|
||||||
|
self.server.recentPostsCache,
|
||||||
|
self.server.maxRecentPosts,
|
||||||
|
self.server.translate,
|
||||||
|
pageNumber, maxPostsInBlogsFeed,
|
||||||
|
self.server.session,
|
||||||
|
baseDir,
|
||||||
|
self.server.cachedWebfingers,
|
||||||
|
self.server.personCache,
|
||||||
|
nickname,
|
||||||
|
domain,
|
||||||
|
port,
|
||||||
|
inboxBlogsFeed,
|
||||||
|
self.server.allowDeletion,
|
||||||
|
httpPrefix,
|
||||||
|
self.server.projectVersion,
|
||||||
|
self._isMinimal(nickname),
|
||||||
|
self.server.YTReplacementDomain)
|
||||||
|
msg = msg.encode('utf-8')
|
||||||
|
self._set_headers('text/html', len(msg),
|
||||||
|
cookie, callingDomain)
|
||||||
|
self._write(msg)
|
||||||
|
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
||||||
|
'show media 2 done',
|
||||||
|
'show blogs 2')
|
||||||
|
else:
|
||||||
|
# don't need authenticated fetch here because there is
|
||||||
|
# already the authorization check
|
||||||
|
msg = json.dumps(inboxBlogsFeed,
|
||||||
|
ensure_ascii=False)
|
||||||
|
msg = msg.encode('utf-8')
|
||||||
|
self._set_headers('application/json',
|
||||||
|
len(msg),
|
||||||
|
None, callingDomain)
|
||||||
|
self._write(msg)
|
||||||
|
self.server.GETbusy = False
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
if debug:
|
||||||
|
nickname = self.path.replace('/users/', '')
|
||||||
|
nickname = nickname.replace('/tlblogs', '')
|
||||||
|
print('DEBUG: ' + nickname +
|
||||||
|
' was not authorized to access ' + path)
|
||||||
|
if path != '/tlblogs':
|
||||||
|
# not the blogs inbox
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: GET access to blogs is unauthorized')
|
||||||
|
self.send_response(405)
|
||||||
|
self.end_headers()
|
||||||
|
self.server.GETbusy = False
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
callingDomain = self.server.domainFull
|
callingDomain = self.server.domainFull
|
||||||
if self.headers.get('Host'):
|
if self.headers.get('Host'):
|
||||||
|
@ -7534,7 +7635,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
'show skills done',
|
'show skills done',
|
||||||
'show status done')
|
'show status done')
|
||||||
|
|
||||||
# get the inbox for a given person
|
# get the inbox timeline for a given person
|
||||||
if self.path.endswith('/inbox') or '/inbox?page=' in self.path:
|
if self.path.endswith('/inbox') or '/inbox?page=' in self.path:
|
||||||
if self._showInbox(authorized,
|
if self._showInbox(authorized,
|
||||||
callingDomain, self.path,
|
callingDomain, self.path,
|
||||||
|
@ -7554,7 +7655,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
'show status done',
|
'show status done',
|
||||||
'show inbox done')
|
'show inbox done')
|
||||||
|
|
||||||
# get the direct messages for a given person
|
# get the direct messages timeline for a given person
|
||||||
if self.path.endswith('/dm') or '/dm?page=' in self.path:
|
if self.path.endswith('/dm') or '/dm?page=' in self.path:
|
||||||
if self._showDMs(authorized,
|
if self._showDMs(authorized,
|
||||||
callingDomain, self.path,
|
callingDomain, self.path,
|
||||||
|
@ -7574,7 +7675,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
'show inbox done',
|
'show inbox done',
|
||||||
'show dms done')
|
'show dms done')
|
||||||
|
|
||||||
# get the replies for a given person
|
# get the replies timeline for a given person
|
||||||
if self.path.endswith('/tlreplies') or '/tlreplies?page=' in self.path:
|
if self.path.endswith('/tlreplies') or '/tlreplies?page=' in self.path:
|
||||||
if self._showReplies(authorized,
|
if self._showReplies(authorized,
|
||||||
callingDomain, self.path,
|
callingDomain, self.path,
|
||||||
|
@ -7594,7 +7695,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
'show dms done',
|
'show dms done',
|
||||||
'show replies 2 done')
|
'show replies 2 done')
|
||||||
|
|
||||||
# get the media for a given person
|
# get the media timeline for a given person
|
||||||
if self.path.endswith('/tlmedia') or '/tlmedia?page=' in self.path:
|
if self.path.endswith('/tlmedia') or '/tlmedia?page=' in self.path:
|
||||||
if self._showMediaTimeline(authorized,
|
if self._showMediaTimeline(authorized,
|
||||||
callingDomain, self.path,
|
callingDomain, self.path,
|
||||||
|
@ -7616,95 +7717,18 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
|
|
||||||
# get the blogs for a given person
|
# get the blogs for a given person
|
||||||
if self.path.endswith('/tlblogs') or '/tlblogs?page=' in self.path:
|
if self.path.endswith('/tlblogs') or '/tlblogs?page=' in self.path:
|
||||||
if '/users/' in self.path:
|
if self._showBlogsTimeline(authorized,
|
||||||
if authorized:
|
callingDomain, self.path,
|
||||||
inboxBlogsFeed = \
|
self.server.baseDir,
|
||||||
personBoxJson(self.server.recentPostsCache,
|
self.server.httpPrefix,
|
||||||
self.server.session,
|
self.server.domain,
|
||||||
self.server.baseDir,
|
self.server.domainFull,
|
||||||
self.server.domain,
|
self.server.port,
|
||||||
self.server.port,
|
self.server.onionDomain,
|
||||||
self.path,
|
self.server.i2pDomain,
|
||||||
self.server.httpPrefix,
|
GETstartTime, GETtimings,
|
||||||
maxPostsInBlogsFeed, 'tlblogs',
|
self.server.proxyType,
|
||||||
True, self.server.ocapAlways)
|
cookie, self.server.debug):
|
||||||
if not inboxBlogsFeed:
|
|
||||||
inboxBlogsFeed = []
|
|
||||||
if self._requestHTTP():
|
|
||||||
nickname = self.path.replace('/users/', '')
|
|
||||||
nickname = nickname.replace('/tlblogs', '')
|
|
||||||
pageNumber = 1
|
|
||||||
if '?page=' in nickname:
|
|
||||||
pageNumber = nickname.split('?page=')[1]
|
|
||||||
nickname = nickname.split('?page=')[0]
|
|
||||||
if pageNumber.isdigit():
|
|
||||||
pageNumber = int(pageNumber)
|
|
||||||
else:
|
|
||||||
pageNumber = 1
|
|
||||||
if 'page=' not in self.path:
|
|
||||||
# if no page was specified then show the first
|
|
||||||
inboxBlogsFeed = \
|
|
||||||
personBoxJson(self.server.recentPostsCache,
|
|
||||||
self.server.session,
|
|
||||||
self.server.baseDir,
|
|
||||||
self.server.domain,
|
|
||||||
self.server.port,
|
|
||||||
self.path + '?page=1',
|
|
||||||
self.server.httpPrefix,
|
|
||||||
maxPostsInBlogsFeed, 'tlblogs',
|
|
||||||
True, self.server.ocapAlways)
|
|
||||||
msg = \
|
|
||||||
htmlInboxBlogs(self.server.defaultTimeline,
|
|
||||||
self.server.recentPostsCache,
|
|
||||||
self.server.maxRecentPosts,
|
|
||||||
self.server.translate,
|
|
||||||
pageNumber, maxPostsInBlogsFeed,
|
|
||||||
self.server.session,
|
|
||||||
self.server.baseDir,
|
|
||||||
self.server.cachedWebfingers,
|
|
||||||
self.server.personCache,
|
|
||||||
nickname,
|
|
||||||
self.server.domain,
|
|
||||||
self.server.port,
|
|
||||||
inboxBlogsFeed,
|
|
||||||
self.server.allowDeletion,
|
|
||||||
self.server.httpPrefix,
|
|
||||||
self.server.projectVersion,
|
|
||||||
self._isMinimal(nickname),
|
|
||||||
self.server.YTReplacementDomain)
|
|
||||||
msg = msg.encode('utf-8')
|
|
||||||
self._set_headers('text/html',
|
|
||||||
len(msg),
|
|
||||||
cookie, callingDomain)
|
|
||||||
self._write(msg)
|
|
||||||
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
|
||||||
'show media 2 done',
|
|
||||||
'show blogs 2')
|
|
||||||
else:
|
|
||||||
# don't need authenticated fetch here because there is
|
|
||||||
# already the authorization check
|
|
||||||
msg = json.dumps(inboxBlogsFeed,
|
|
||||||
ensure_ascii=False)
|
|
||||||
msg = msg.encode('utf-8')
|
|
||||||
self._set_headers('application/json',
|
|
||||||
len(msg),
|
|
||||||
None, callingDomain)
|
|
||||||
self._write(msg)
|
|
||||||
self.server.GETbusy = False
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
if self.server.debug:
|
|
||||||
nickname = self.path.replace('/users/', '')
|
|
||||||
nickname = nickname.replace('/tlblogs', '')
|
|
||||||
print('DEBUG: ' + nickname +
|
|
||||||
' was not authorized to access ' + self.path)
|
|
||||||
if self.path != '/tlblogs':
|
|
||||||
# not the blogs inbox
|
|
||||||
if self.server.debug:
|
|
||||||
print('DEBUG: GET access to blogs is unauthorized')
|
|
||||||
self.send_response(405)
|
|
||||||
self.end_headers()
|
|
||||||
self.server.GETbusy = False
|
|
||||||
return
|
return
|
||||||
|
|
||||||
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
||||||
|
|
Loading…
Reference in New Issue