Move rss3 feed to its own method

main
Bob Mottram 2020-08-31 16:55:00 +01:00
parent 7a864db6aa
commit a11295572d
1 changed files with 56 additions and 42 deletions

View File

@ -3689,6 +3689,53 @@ class PubServer(BaseHTTPRequestHandler):
path + ' ' + callingDomain)
self._404()
def _getRSS3feed(self, authorized: bool,
callingDomain: str, path: str,
baseDir: str, httpPrefix: str,
domain: str, port: int, proxyType: str,
GETstartTime, GETtimings: {},
debug: bool):
"""Returns an RSS3 feed
"""
nickname = path.split('/blog/')[1]
if '/' in nickname:
nickname = nickname.split('/')[0]
if not nickname.startswith('rss.'):
if os.path.isdir(baseDir +
'/accounts/' + nickname + '@' + domain):
if not self.server.session:
print('Starting new session during RSS3 request')
self.server.session = \
createSession(proxyType)
if not self.server.session:
print('ERROR: GET failed to create session ' +
'during RSS3 request')
self._404()
return
msg = \
htmlBlogPageRSS3(authorized,
self.server.session,
baseDir, httpPrefix,
self.server.translate,
nickname, domain, port,
maxPostsInRSSFeed, 1)
if msg is not None:
msg = msg.encode('utf-8')
self._set_headers('text/plain; charset=utf-8',
len(msg), None, callingDomain)
self._write(msg)
if self.server.debug:
print('Sent rss3 feed: ' +
path + ' ' + callingDomain)
self._benchmarkGETtimings(GETstartTime, GETtimings,
'sharedInbox enabled',
'blog rss3')
return
if debug:
print('Failed to get rss3 feed: ' +
path + ' ' + callingDomain)
self._404()
def do_GET(self):
callingDomain = self.server.domainFull
if self.headers.get('Host'):
@ -3872,48 +3919,15 @@ class PubServer(BaseHTTPRequestHandler):
# RSS 3.0
if self.path.startswith('/blog/') and \
self.path.endswith('/rss.txt'):
nickname = self.path.split('/blog/')[1]
if '/' in nickname:
nickname = nickname.split('/')[0]
if not nickname.startswith('rss.'):
if os.path.isdir(self.server.baseDir +
'/accounts/' + nickname +
'@' + self.server.domain):
if not self.server.session:
print('Starting new session during RSS3 request')
self.server.session = \
createSession(self.server.proxyType)
if not self.server.session:
print('ERROR: GET failed to create session ' +
'during RSS3 request')
self._404()
return
msg = \
htmlBlogPageRSS3(authorized,
self.server.session,
self.server.baseDir,
self.server.httpPrefix,
self.server.translate,
nickname,
self.server.domain,
self.server.port,
maxPostsInRSSFeed, 1)
if msg is not None:
msg = msg.encode('utf-8')
self._set_headers('text/plain; charset=utf-8',
len(msg), cookie, callingDomain)
self._write(msg)
if self.server.debug:
print('Sent rss3 feed: ' +
self.path + ' ' + callingDomain)
self._benchmarkGETtimings(GETstartTime, GETtimings,
'sharedInbox enabled',
'blog rss3')
return
if self.server.debug:
print('Failed to get rss3 feed: ' +
self.path + ' ' + callingDomain)
self._404()
self._getRSS3feed(authorized,
callingDomain, self.path,
self.server.baseDir,
self.server.httpPrefix,
self.server.domain,
self.server.port,
self.server.proxyType,
GETstartTime, GETtimings,
self.server.debug)
return
self._benchmarkGETtimings(GETstartTime, GETtimings,