Move shares feed to its own method

main
Bob Mottram 2020-09-01 17:21:41 +01:00
parent 7bb1214813
commit 06a6c93131
1 changed files with 97 additions and 81 deletions

178
daemon.py
View File

@ -6298,6 +6298,90 @@ class PubServer(BaseHTTPRequestHandler):
self.server.GETbusy = False self.server.GETbusy = False
return True return True
def _showSharesFeed(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 shares feed
"""
shares = \
getSharesFeedForPerson(baseDir, domain, port, path,
httpPrefix, sharesPerPage)
if shares:
if self._requestHTTP():
pageNumber = 1
if '?page=' not in path:
searchPath = path
# get a page of shares, not the summary
shares = \
getSharesFeedForPerson(baseDir, domain, port,
path + '?page=true',
httpPrefix,
sharesPerPage)
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('/shares', ''),
baseDir)
if getPerson:
if not self.server.session:
print('Starting new session during profile')
self.server.session = createSession(proxyType)
if not self.server.session:
print('ERROR: GET failed to create session ' +
'during profile')
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, 'shares',
self.server.session,
self.server.cachedWebfingers,
self.server.personCache,
self.server.YTReplacementDomain,
shares,
pageNumber, sharesPerPage)
msg = msg.encode('utf-8')
self._set_headers('text/html', len(msg),
cookie, callingDomain)
self._write(msg)
self._benchmarkGETtimings(GETstartTime, GETtimings,
'show moderation done',
'show profile 2')
self.server.GETbusy = False
return True
else:
if self._fetchAuthenticated():
msg = json.dumps(shares,
ensure_ascii=False)
msg = msg.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'):
@ -8281,87 +8365,19 @@ class PubServer(BaseHTTPRequestHandler):
'show outbox done', 'show outbox done',
'show moderation done') 'show moderation done')
shares = \ if self._showSharesFeed(authorized,
getSharesFeedForPerson(self.server.baseDir, callingDomain, self.path,
self.server.domain, self.server.baseDir,
self.server.port, self.path, self.server.httpPrefix,
self.server.httpPrefix, self.server.domain,
sharesPerPage) self.server.domainFull,
if shares: self.server.port,
if self._requestHTTP(): self.server.onionDomain,
pageNumber = 1 self.server.i2pDomain,
if '?page=' not in self.path: GETstartTime, GETtimings,
searchPath = self.path self.server.proxyType,
# get a page of shares, not the summary cookie, self.server.debug):
shares = \ return
getSharesFeedForPerson(self.server.baseDir,
self.server.domain,
self.server.port,
self.path + '?page=true',
self.server.httpPrefix,
sharesPerPage)
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('/shares', ''),
self.server.baseDir)
if getPerson:
if not self.server.session:
print('Starting new session during profile')
self.server.session = \
createSession(self.server.proxyType)
if not self.server.session:
print('ERROR: GET failed to create session ' +
'during profile')
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, 'shares',
self.server.session,
self.server.cachedWebfingers,
self.server.personCache,
self.server.YTReplacementDomain,
shares,
pageNumber, sharesPerPage)
msg = msg.encode('utf-8')
self._set_headers('text/html',
len(msg),
cookie, callingDomain)
self._write(msg)
self._benchmarkGETtimings(GETstartTime, GETtimings,
'show moderation done',
'show profile 2')
self.server.GETbusy = False
return
else:
if self._fetchAuthenticated():
msg = json.dumps(shares,
ensure_ascii=False)
msg = msg.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 moderation done', 'show moderation done',