mirror of https://gitlab.com/bashrc2/epicyon
Move function out of daemon
parent
2eb101823d
commit
f1e3a2591c
31
blog.py
31
blog.py
|
@ -863,3 +863,34 @@ def htmlEditBlog(mediaInstance: bool, translate: {},
|
||||||
|
|
||||||
editBlogForm += htmlFooter()
|
editBlogForm += htmlFooter()
|
||||||
return editBlogForm
|
return editBlogForm
|
||||||
|
|
||||||
|
|
||||||
|
def pathContainsBlogLink(baseDir: str,
|
||||||
|
httpPrefix: str, domain: str,
|
||||||
|
domainFull: str, path: str) -> (str, str):
|
||||||
|
"""If the path contains a blog entry then return its filename
|
||||||
|
"""
|
||||||
|
if '/users/' not in path:
|
||||||
|
return None, None
|
||||||
|
userEnding = path.split('/users/', 1)[1]
|
||||||
|
if '/' not in userEnding:
|
||||||
|
return None, None
|
||||||
|
userEnding2 = userEnding.split('/')
|
||||||
|
nickname = userEnding2[0]
|
||||||
|
if len(userEnding2) != 2:
|
||||||
|
return None, None
|
||||||
|
if len(userEnding2[1]) < 14:
|
||||||
|
return None, None
|
||||||
|
userEnding2[1] = userEnding2[1].strip()
|
||||||
|
if not userEnding2[1].isdigit():
|
||||||
|
return None, None
|
||||||
|
# check for blog posts
|
||||||
|
blogIndexFilename = baseDir + '/accounts/' + \
|
||||||
|
nickname + '@' + domain + '/tlblogs.index'
|
||||||
|
if not os.path.isfile(blogIndexFilename):
|
||||||
|
return None, None
|
||||||
|
if '#' + userEnding2[1] + '.' not in open(blogIndexFilename).read():
|
||||||
|
return None, None
|
||||||
|
messageId = httpPrefix + '://' + domainFull + \
|
||||||
|
'/users/' + nickname + '/statuses/' + userEnding2[1]
|
||||||
|
return locatePost(baseDir, nickname, domain, messageId), nickname
|
||||||
|
|
33
daemon.py
33
daemon.py
|
@ -130,6 +130,7 @@ from roles import clearModeratorStatus
|
||||||
from roles import clearEditorStatus
|
from roles import clearEditorStatus
|
||||||
from roles import clearCounselorStatus
|
from roles import clearCounselorStatus
|
||||||
from roles import clearArtistStatus
|
from roles import clearArtistStatus
|
||||||
|
from blog import pathContainsBlogLink
|
||||||
from blog import htmlBlogPageRSS2
|
from blog import htmlBlogPageRSS2
|
||||||
from blog import htmlBlogPageRSS3
|
from blog import htmlBlogPageRSS3
|
||||||
from blog import htmlBlogView
|
from blog import htmlBlogView
|
||||||
|
@ -1362,36 +1363,6 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
print('POST TIMING|' + str(ctr) + '|' + timeDiff)
|
print('POST TIMING|' + str(ctr) + '|' + timeDiff)
|
||||||
ctr += 1
|
ctr += 1
|
||||||
|
|
||||||
def _pathContainsBlogLink(self, baseDir: str,
|
|
||||||
httpPrefix: str, domain: str,
|
|
||||||
domainFull: str, path: str) -> (str, str):
|
|
||||||
"""If the path contains a blog entry then return its filename
|
|
||||||
"""
|
|
||||||
if '/users/' not in path:
|
|
||||||
return None, None
|
|
||||||
userEnding = path.split('/users/', 1)[1]
|
|
||||||
if '/' not in userEnding:
|
|
||||||
return None, None
|
|
||||||
userEnding2 = userEnding.split('/')
|
|
||||||
nickname = userEnding2[0]
|
|
||||||
if len(userEnding2) != 2:
|
|
||||||
return None, None
|
|
||||||
if len(userEnding2[1]) < 14:
|
|
||||||
return None, None
|
|
||||||
userEnding2[1] = userEnding2[1].strip()
|
|
||||||
if not userEnding2[1].isdigit():
|
|
||||||
return None, None
|
|
||||||
# check for blog posts
|
|
||||||
blogIndexFilename = baseDir + '/accounts/' + \
|
|
||||||
nickname + '@' + domain + '/tlblogs.index'
|
|
||||||
if not os.path.isfile(blogIndexFilename):
|
|
||||||
return None, None
|
|
||||||
if '#' + userEnding2[1] + '.' not in open(blogIndexFilename).read():
|
|
||||||
return None, None
|
|
||||||
messageId = httpPrefix + '://' + domainFull + \
|
|
||||||
'/users/' + nickname + '/statuses/' + userEnding2[1]
|
|
||||||
return locatePost(baseDir, nickname, domain, messageId), nickname
|
|
||||||
|
|
||||||
def _loginScreen(self, path: str, callingDomain: str, cookie: str,
|
def _loginScreen(self, path: str, callingDomain: str, cookie: str,
|
||||||
baseDir: str, httpPrefix: str,
|
baseDir: str, httpPrefix: str,
|
||||||
domain: str, domainFull: str, port: int,
|
domain: str, domainFull: str, port: int,
|
||||||
|
@ -11135,7 +11106,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
'person options done')
|
'person options done')
|
||||||
# show blog post
|
# show blog post
|
||||||
blogFilename, nickname = \
|
blogFilename, nickname = \
|
||||||
self._pathContainsBlogLink(self.server.baseDir,
|
pathContainsBlogLink(self.server.baseDir,
|
||||||
self.server.httpPrefix,
|
self.server.httpPrefix,
|
||||||
self.server.domain,
|
self.server.domain,
|
||||||
self.server.domainFull,
|
self.server.domainFull,
|
||||||
|
|
Loading…
Reference in New Issue