Move followers feed to its own method

main
Bob Mottram 2020-09-01 17:35:10 +01:00
parent 2587610924
commit 9d7aef0718
1 changed files with 99 additions and 79 deletions

174
daemon.py
View File

@ -6468,6 +6468,93 @@ class PubServer(BaseHTTPRequestHandler):
return True
return False
def _showFollowersFeed(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 followers feed
"""
followers = \
getFollowingFeed(baseDir, domain, port, path, httpPrefix,
authorized, followsPerPage, 'followers')
if followers:
if self._requestHTTP():
pageNumber = 1
if '?page=' not in path:
searchPath = path
# get a page of followers, not the summary
followers = \
getFollowingFeed(baseDir,
domain,
port,
path + '?page=1',
httpPrefix,
authorized, followsPerPage,
'followers')
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('/followers', ''),
baseDir)
if getPerson:
if not self.server.session:
print('Starting new session during following2')
self.server.session = createSession(proxyType)
if not self.server.session:
print('ERROR: GET failed to create session ' +
'during following2')
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, 'followers',
self.server.session,
self.server.cachedWebfingers,
self.server.personCache,
self.server.YTReplacementDomain,
followers,
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 3 done',
'show profile 4')
return True
else:
if self._fetchAuthenticated():
msg = json.dumps(followers,
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):
callingDomain = self.server.domainFull
if self.headers.get('Host'):
@ -8487,85 +8574,18 @@ class PubServer(BaseHTTPRequestHandler):
'show profile 2 done',
'show profile 3 done')
followers = \
getFollowingFeed(self.server.baseDir, self.server.domain,
self.server.port, self.path,
self.server.httpPrefix,
authorized, followsPerPage, 'followers')
if followers:
if self._requestHTTP():
pageNumber = 1
if '?page=' not in self.path:
searchPath = self.path
# get a page of followers, not the summary
followers = \
getFollowingFeed(self.server.baseDir,
self.server.domain,
self.server.port,
self.path + '?page=1',
self.server.httpPrefix,
authorized, followsPerPage,
'followers')
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('/followers', ''),
self.server.baseDir)
if getPerson:
if not self.server.session:
print('Starting new session during following2')
self.server.session = \
createSession(self.server.proxyType)
if not self.server.session:
print('ERROR: GET failed to create session ' +
'during following2')
self._404()
self.server.GETbusy = False
return
msg = \
htmlProfile(self.server.defaultTimeline,
self.server.recentPostsCache,
self.server.maxRecentPosts,
self.server.translate,
self.server.projectVersion,
if self._showFollowersFeed(authorized,
callingDomain, self.path,
self.server.baseDir,
self.server.httpPrefix,
authorized,
self.server.ocapAlways,
getPerson, 'followers',
self.server.session,
self.server.cachedWebfingers,
self.server.personCache,
self.server.YTReplacementDomain,
followers,
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 3 done',
'show profile 4')
return
else:
if self._fetchAuthenticated():
msg = json.dumps(followers,
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
self.server.domain,
self.server.domainFull,
self.server.port,
self.server.onionDomain,
self.server.i2pDomain,
GETstartTime, GETtimings,
self.server.proxyType,
cookie, self.server.debug):
return
self._benchmarkGETtimings(GETstartTime, GETtimings,