mirror of https://gitlab.com/bashrc2/epicyon
Move blog page to its own module
parent
993a463c70
commit
eaac57228e
108
daemon.py
108
daemon.py
|
@ -6732,6 +6732,61 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def _showBlogPage(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,
|
||||||
|
translate: {}, debug: str) -> bool:
|
||||||
|
"""Shows a blog page
|
||||||
|
"""
|
||||||
|
pageNumber = 1
|
||||||
|
nickname = path.split('/blog/')[1]
|
||||||
|
if '/' in nickname:
|
||||||
|
nickname = nickname.split('/')[0]
|
||||||
|
if '?' in nickname:
|
||||||
|
nickname = nickname.split('?')[0]
|
||||||
|
if '?page=' in path:
|
||||||
|
pageNumberStr = path.split('?page=')[1]
|
||||||
|
if '?' in pageNumberStr:
|
||||||
|
pageNumberStr = pageNumberStr.split('?')[0]
|
||||||
|
if '#' in pageNumberStr:
|
||||||
|
pageNumberStr = pageNumberStr.split('#')[0]
|
||||||
|
if pageNumberStr.isdigit():
|
||||||
|
pageNumber = int(pageNumberStr)
|
||||||
|
if pageNumber < 1:
|
||||||
|
pageNumber = 1
|
||||||
|
elif pageNumber > 10:
|
||||||
|
pageNumber = 10
|
||||||
|
if not self.server.session:
|
||||||
|
print('Starting new session during blog page')
|
||||||
|
self.server.session = createSession(proxyType)
|
||||||
|
if not self.server.session:
|
||||||
|
print('ERROR: GET failed to create session ' +
|
||||||
|
'during blog page')
|
||||||
|
self._404()
|
||||||
|
return True
|
||||||
|
msg = htmlBlogPage(authorized,
|
||||||
|
self.server.session,
|
||||||
|
baseDir,
|
||||||
|
httpPrefix,
|
||||||
|
translate,
|
||||||
|
nickname,
|
||||||
|
domain, port,
|
||||||
|
maxPostsInBlogsFeed, pageNumber)
|
||||||
|
if msg is not None:
|
||||||
|
msg = msg.encode('utf-8')
|
||||||
|
self._set_headers('text/html', len(msg),
|
||||||
|
cookie, callingDomain)
|
||||||
|
self._write(msg)
|
||||||
|
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
||||||
|
'blog view done', 'blog page')
|
||||||
|
return True
|
||||||
|
self._404()
|
||||||
|
return True
|
||||||
|
|
||||||
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'):
|
||||||
|
@ -6970,50 +7025,19 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
# for a particular account
|
# for a particular account
|
||||||
if htmlGET and self.path.startswith('/blog/'):
|
if htmlGET and self.path.startswith('/blog/'):
|
||||||
if '/rss.xml' not in self.path:
|
if '/rss.xml' not in self.path:
|
||||||
pageNumber = 1
|
if self._showBlogPage(authorized,
|
||||||
nickname = self.path.split('/blog/')[1]
|
callingDomain, self.path,
|
||||||
if '/' in nickname:
|
|
||||||
nickname = nickname.split('/')[0]
|
|
||||||
if '?' in nickname:
|
|
||||||
nickname = nickname.split('?')[0]
|
|
||||||
if '?page=' in self.path:
|
|
||||||
pageNumberStr = self.path.split('?page=')[1]
|
|
||||||
if '?' in pageNumberStr:
|
|
||||||
pageNumberStr = pageNumberStr.split('?')[0]
|
|
||||||
if '#' in pageNumberStr:
|
|
||||||
pageNumberStr = pageNumberStr.split('#')[0]
|
|
||||||
if pageNumberStr.isdigit():
|
|
||||||
pageNumber = int(pageNumberStr)
|
|
||||||
if pageNumber < 1:
|
|
||||||
pageNumber = 1
|
|
||||||
elif pageNumber > 10:
|
|
||||||
pageNumber = 10
|
|
||||||
if not self.server.session:
|
|
||||||
print('Starting new session during blog page')
|
|
||||||
self.server.session = \
|
|
||||||
createSession(self.server.proxyType)
|
|
||||||
if not self.server.session:
|
|
||||||
print('ERROR: GET failed to create session ' +
|
|
||||||
'during blog page')
|
|
||||||
self._404()
|
|
||||||
return
|
|
||||||
msg = htmlBlogPage(authorized,
|
|
||||||
self.server.session,
|
|
||||||
self.server.baseDir,
|
self.server.baseDir,
|
||||||
self.server.httpPrefix,
|
self.server.httpPrefix,
|
||||||
self.server.translate,
|
self.server.domain,
|
||||||
nickname,
|
self.server.domainFull,
|
||||||
self.server.domain, self.server.port,
|
self.server.port,
|
||||||
maxPostsInBlogsFeed, pageNumber)
|
self.server.onionDomain,
|
||||||
if msg is not None:
|
self.server.i2pDomain,
|
||||||
msg = msg.encode('utf-8')
|
GETstartTime, GETtimings,
|
||||||
self._set_headers('text/html', len(msg),
|
self.server.proxyType,
|
||||||
cookie, callingDomain)
|
cookie, self.server.translate,
|
||||||
self._write(msg)
|
self.server.debug):
|
||||||
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
|
||||||
'blog view done', 'blog page')
|
|
||||||
return
|
|
||||||
self._404()
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# list of registered devices for e2ee
|
# list of registered devices for e2ee
|
||||||
|
|
Loading…
Reference in New Issue