Move following feed to its own method

main
Bob Mottram 2020-09-01 17:28:22 +01:00
parent 06a6c93131
commit 2587610924
1 changed files with 99 additions and 79 deletions

178
daemon.py
View File

@ -6382,6 +6382,92 @@ class PubServer(BaseHTTPRequestHandler):
return True return True
return False return False
def _showFollowingFeed(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 following feed
"""
following = \
getFollowingFeed(baseDir, domain, port, path,
httpPrefix, authorized, followsPerPage)
if following:
if self._requestHTTP():
pageNumber = 1
if '?page=' not in path:
searchPath = path
# get a page of following, not the summary
following = \
getFollowingFeed(baseDir,
domain,
port,
path + '?page=true',
httpPrefix,
authorized, followsPerPage)
else:
pageNumberStr = path.split('?page=')[1]
if '#' in pageNumberStr:
pageNumberStr = pageNumberStr.split('#')[0]
if pageNumberStr.isdigit():
pageNumber = int(pageNumberStr)
searchPath = path.split('?page=')[0]
getPerson = \
personLookup(domain,
searchPath.replace('/following', ''),
baseDir)
if getPerson:
if not self.server.session:
print('Starting new session during following')
self.server.session = createSession(proxyType)
if not self.server.session:
print('ERROR: GET failed to create session ' +
'during following')
self._404()
self.server.GETbusy = False
return True
msg = \
htmlProfile(self.server.defaultTimeline,
self.server.recentPostsCache,
self.server.maxRecentPosts,
self.server.translate,
self.server.projectVersion,
baseDir, httpPrefix,
authorized,
self.server.ocapAlways,
getPerson, 'following',
self.server.session,
self.server.cachedWebfingers,
self.server.personCache,
self.server.YTReplacementDomain,
following,
pageNumber,
followsPerPage).encode('utf-8')
self._set_headers('text/html',
len(msg), cookie, callingDomain)
self._write(msg)
self.server.GETbusy = False
self._benchmarkGETtimings(GETstartTime, GETtimings,
'show profile 2 done',
'show profile 3')
return True
else:
if self._fetchAuthenticated():
msg = json.dumps(following,
ensure_ascii=False).encode('utf-8')
self._set_headers('application/json', len(msg),
None, callingDomain)
self._write(msg)
else:
self._404()
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'):
@ -8383,85 +8469,19 @@ class PubServer(BaseHTTPRequestHandler):
'show moderation done', 'show moderation done',
'show profile 2 done') 'show profile 2 done')
following = \ if self._showFollowingFeed(authorized,
getFollowingFeed(self.server.baseDir, self.server.domain, callingDomain, self.path,
self.server.port, self.path, self.server.baseDir,
self.server.httpPrefix, self.server.httpPrefix,
authorized, followsPerPage) self.server.domain,
if following: self.server.domainFull,
if self._requestHTTP(): self.server.port,
pageNumber = 1 self.server.onionDomain,
if '?page=' not in self.path: self.server.i2pDomain,
searchPath = self.path GETstartTime, GETtimings,
# get a page of following, not the summary self.server.proxyType,
following = \ cookie, self.server.debug):
getFollowingFeed(self.server.baseDir, return
self.server.domain,
self.server.port,
self.path + '?page=true',
self.server.httpPrefix,
authorized, followsPerPage)
else:
pageNumberStr = self.path.split('?page=')[1]
if '#' in pageNumberStr:
pageNumberStr = pageNumberStr.split('#')[0]
if pageNumberStr.isdigit():
pageNumber = int(pageNumberStr)
searchPath = self.path.split('?page=')[0]
getPerson = \
personLookup(self.server.domain,
searchPath.replace('/following', ''),
self.server.baseDir)
if getPerson:
if not self.server.session:
print('Starting new session during following')
self.server.session = \
createSession(self.server.proxyType)
if not self.server.session:
print('ERROR: GET failed to create session ' +
'during following')
self._404()
self.server.GETbusy = False
return
msg = \
htmlProfile(self.server.defaultTimeline,
self.server.recentPostsCache,
self.server.maxRecentPosts,
self.server.translate,
self.server.projectVersion,
self.server.baseDir,
self.server.httpPrefix,
authorized,
self.server.ocapAlways,
getPerson, 'following',
self.server.session,
self.server.cachedWebfingers,
self.server.personCache,
self.server.YTReplacementDomain,
following,
pageNumber,
followsPerPage).encode('utf-8')
self._set_headers('text/html',
len(msg), cookie, callingDomain)
self._write(msg)
self.server.GETbusy = False
self._benchmarkGETtimings(GETstartTime, GETtimings,
'show profile 2 done',
'show profile 3')
return
else:
if self._fetchAuthenticated():
msg = json.dumps(following,
ensure_ascii=False).encode('utf-8')
self._set_headers('application/json',
len(msg),
None, callingDomain)
self._write(msg)
else:
self._404()
self.server.GETbusy = False
return
self._benchmarkGETtimings(GETstartTime, GETtimings, self._benchmarkGETtimings(GETstartTime, GETtimings,
'show profile 2 done', 'show profile 2 done',