mirror of https://gitlab.com/bashrc2/epicyon
Voting on newswire items
parent
adc6cd9317
commit
576a2555e2
138
daemon.py
138
daemon.py
|
@ -4657,6 +4657,82 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
'follow approve shown')
|
'follow approve shown')
|
||||||
self.server.GETbusy = False
|
self.server.GETbusy = False
|
||||||
|
|
||||||
|
def _newswireVote(self, callingDomain: str, path: str,
|
||||||
|
cookie: str,
|
||||||
|
baseDir: str, httpPrefix: str,
|
||||||
|
domain: str, domainFull: str, port: int,
|
||||||
|
onionDomain: str, i2pDomain: str,
|
||||||
|
GETstartTime, GETtimings: {},
|
||||||
|
proxyType: str, debug: bool):
|
||||||
|
"""Vote for a newswire item
|
||||||
|
"""
|
||||||
|
originPathStr = path.split('/newswirevote=')[0]
|
||||||
|
dateStr = path.split('/newswirevote=')[1].replace('T', ' ') + '+00:00'
|
||||||
|
nickname = originPathStr.split('/users/')[1]
|
||||||
|
if '/' in nickname:
|
||||||
|
nickname = nickname.split('/')[0]
|
||||||
|
if self.newswire.get(dateStr):
|
||||||
|
if isModerator(baseDir, nickname):
|
||||||
|
if 'vote:' + nickname not in self.newswire[dateStr][2]:
|
||||||
|
self.newswire[dateStr][2].append('vote:' + nickname)
|
||||||
|
filename = self.newswire[dateStr][3]
|
||||||
|
if filename:
|
||||||
|
saveJson(self.newswire[dateStr][2],
|
||||||
|
filename + '.votes')
|
||||||
|
|
||||||
|
originPathStrAbsolute = \
|
||||||
|
httpPrefix + '://' + domainFull + originPathStr
|
||||||
|
if callingDomain.endswith('.onion') and onionDomain:
|
||||||
|
originPathStrAbsolute = \
|
||||||
|
'http://' + onionDomain + originPathStr
|
||||||
|
elif (callingDomain.endswith('.i2p') and i2pDomain):
|
||||||
|
originPathStrAbsolute = \
|
||||||
|
'http://' + i2pDomain + originPathStr
|
||||||
|
self._redirect_headers(originPathStrAbsolute,
|
||||||
|
cookie, callingDomain)
|
||||||
|
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
||||||
|
'unannounce done',
|
||||||
|
'follow approve shown')
|
||||||
|
self.server.GETbusy = False
|
||||||
|
|
||||||
|
def _newswireUnvote(self, callingDomain: str, path: str,
|
||||||
|
cookie: str,
|
||||||
|
baseDir: str, httpPrefix: str,
|
||||||
|
domain: str, domainFull: str, port: int,
|
||||||
|
onionDomain: str, i2pDomain: str,
|
||||||
|
GETstartTime, GETtimings: {},
|
||||||
|
proxyType: str, debug: bool):
|
||||||
|
"""Remove vote for a newswire item
|
||||||
|
"""
|
||||||
|
originPathStr = path.split('/newswirevote=')[0]
|
||||||
|
dateStr = path.split('/newswirevote=')[1].replace('T', ' ') + '+00:00'
|
||||||
|
nickname = originPathStr.split('/users/')[1]
|
||||||
|
if '/' in nickname:
|
||||||
|
nickname = nickname.split('/')[0]
|
||||||
|
if self.newswire.get(dateStr):
|
||||||
|
if isModerator(baseDir, nickname):
|
||||||
|
if 'vote:' + nickname in self.newswire[dateStr][2]:
|
||||||
|
self.newswire[dateStr][2].remove('vote:' + nickname)
|
||||||
|
filename = self.newswire[dateStr][3]
|
||||||
|
if filename:
|
||||||
|
saveJson(self.newswire[dateStr][2],
|
||||||
|
filename + '.votes')
|
||||||
|
|
||||||
|
originPathStrAbsolute = \
|
||||||
|
httpPrefix + '://' + domainFull + originPathStr
|
||||||
|
if callingDomain.endswith('.onion') and onionDomain:
|
||||||
|
originPathStrAbsolute = \
|
||||||
|
'http://' + onionDomain + originPathStr
|
||||||
|
elif (callingDomain.endswith('.i2p') and i2pDomain):
|
||||||
|
originPathStrAbsolute = \
|
||||||
|
'http://' + i2pDomain + originPathStr
|
||||||
|
self._redirect_headers(originPathStrAbsolute,
|
||||||
|
cookie, callingDomain)
|
||||||
|
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
||||||
|
'unannounce done',
|
||||||
|
'follow approve shown')
|
||||||
|
self.server.GETbusy = False
|
||||||
|
|
||||||
def _followDenyButton(self, callingDomain: str, path: str,
|
def _followDenyButton(self, callingDomain: str, path: str,
|
||||||
cookie: str,
|
cookie: str,
|
||||||
baseDir: str, httpPrefix: str,
|
baseDir: str, httpPrefix: str,
|
||||||
|
@ -8688,21 +8764,55 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
'show announce done',
|
'show announce done',
|
||||||
'unannounce done')
|
'unannounce done')
|
||||||
|
|
||||||
# send a newswire moderation approval from the web interface
|
# send a newswire moderation vote from the web interface
|
||||||
if authorized and '/newswireapprove=' in self.path and \
|
if authorized and '/newswirevote=' in self.path and \
|
||||||
self.path.startswith('/users/'):
|
self.path.startswith('/users/'):
|
||||||
self._moderationApproveButton(callingDomain, self.path,
|
self._newswireVote(callingDomain, self.path,
|
||||||
cookie,
|
cookie,
|
||||||
self.server.baseDir,
|
self.server.baseDir,
|
||||||
self.server.httpPrefix,
|
self.server.httpPrefix,
|
||||||
self.server.domain,
|
self.server.domain,
|
||||||
self.server.domainFull,
|
self.server.domainFull,
|
||||||
self.server.port,
|
self.server.port,
|
||||||
self.server.onionDomain,
|
self.server.onionDomain,
|
||||||
self.server.i2pDomain,
|
self.server.i2pDomain,
|
||||||
GETstartTime, GETtimings,
|
GETstartTime, GETtimings,
|
||||||
self.server.proxyType,
|
self.server.proxyType,
|
||||||
self.server.debug)
|
self.server.debug)
|
||||||
|
return
|
||||||
|
|
||||||
|
# send a newswire moderation unvote from the web interface
|
||||||
|
if authorized and '/newswireunvote=' in self.path and \
|
||||||
|
self.path.startswith('/users/'):
|
||||||
|
self._newswireUnvote(callingDomain, self.path,
|
||||||
|
cookie,
|
||||||
|
self.server.baseDir,
|
||||||
|
self.server.httpPrefix,
|
||||||
|
self.server.domain,
|
||||||
|
self.server.domainFull,
|
||||||
|
self.server.port,
|
||||||
|
self.server.onionDomain,
|
||||||
|
self.server.i2pDomain,
|
||||||
|
GETstartTime, GETtimings,
|
||||||
|
self.server.proxyType,
|
||||||
|
self.server.debug)
|
||||||
|
return
|
||||||
|
|
||||||
|
# send a follow request approval from the web interface
|
||||||
|
if authorized and '/followapprove=' in self.path and \
|
||||||
|
self.path.startswith('/users/'):
|
||||||
|
self._followApproveButton(callingDomain, self.path,
|
||||||
|
cookie,
|
||||||
|
self.server.baseDir,
|
||||||
|
self.server.httpPrefix,
|
||||||
|
self.server.domain,
|
||||||
|
self.server.domainFull,
|
||||||
|
self.server.port,
|
||||||
|
self.server.onionDomain,
|
||||||
|
self.server.i2pDomain,
|
||||||
|
GETstartTime, GETtimings,
|
||||||
|
self.server.proxyType,
|
||||||
|
self.server.debug)
|
||||||
return
|
return
|
||||||
|
|
||||||
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
||||||
|
|
|
@ -79,7 +79,7 @@ def xml2StrToDict(xmlStr: str) -> {}:
|
||||||
try:
|
try:
|
||||||
publishedDate = \
|
publishedDate = \
|
||||||
datetime.strptime(pubDate, "%a, %d %b %Y %H:%M:%S %z")
|
datetime.strptime(pubDate, "%a, %d %b %Y %H:%M:%S %z")
|
||||||
result[str(publishedDate)] = [title, link, []]
|
result[str(publishedDate)] = [title, link, [], '']
|
||||||
parsed = True
|
parsed = True
|
||||||
except BaseException:
|
except BaseException:
|
||||||
pass
|
pass
|
||||||
|
@ -230,9 +230,13 @@ def addAccountBlogsToNewswire(baseDir: str, nickname: str, domain: str,
|
||||||
published = postJsonObject['object']['published']
|
published = postJsonObject['object']['published']
|
||||||
published = published.replace('T', ' ')
|
published = published.replace('T', ' ')
|
||||||
published = published.replace('Z', '+00:00')
|
published = published.replace('Z', '+00:00')
|
||||||
|
votes = []
|
||||||
|
if os.path.isfile(fullPostFilename + '.votes'):
|
||||||
|
votes = loadJson(fullPostFilename + '.votes')
|
||||||
newswire[published] = \
|
newswire[published] = \
|
||||||
[postJsonObject['object']['summary'],
|
[postJsonObject['object']['summary'],
|
||||||
postJsonObject['object']['url'], []]
|
postJsonObject['object']['url'], votes,
|
||||||
|
fullPostFilename]
|
||||||
|
|
||||||
ctr += 1
|
ctr += 1
|
||||||
if ctr >= maxBlogsPerAccount:
|
if ctr >= maxBlogsPerAccount:
|
||||||
|
|
|
@ -5352,7 +5352,7 @@ def htmlNewswire(newswire: str, nickname: str, moderator: bool) -> str:
|
||||||
# count the total votes for this item
|
# count the total votes for this item
|
||||||
totalVotes = 0
|
totalVotes = 0
|
||||||
for line in item[2]:
|
for line in item[2]:
|
||||||
if '[vote:' in line:
|
if 'vote:' in line:
|
||||||
totalVotes += 1
|
totalVotes += 1
|
||||||
if totalVotes > 0:
|
if totalVotes > 0:
|
||||||
totalVotesStr = ' +' + str(totalVotes)
|
totalVotesStr = ' +' + str(totalVotes)
|
||||||
|
@ -5376,7 +5376,7 @@ def htmlNewswire(newswire: str, nickname: str, moderator: bool) -> str:
|
||||||
# count the total votes for this item
|
# count the total votes for this item
|
||||||
totalVotes = 0
|
totalVotes = 0
|
||||||
for line in item[2]:
|
for line in item[2]:
|
||||||
if '[vote:' in line:
|
if 'vote:' in line:
|
||||||
totalVotes += 1
|
totalVotes += 1
|
||||||
if totalVotes > 0:
|
if totalVotes > 0:
|
||||||
totalVotesStr = ' +' + str(totalVotes)
|
totalVotesStr = ' +' + str(totalVotes)
|
||||||
|
|
Loading…
Reference in New Issue