Graph cookie fix ( better counting of views )

This commit is contained in:
BlenderDumbass 2024-11-29 19:56:59 +02:00
parent a87eb14ebc
commit 1467421c13
2 changed files with 22 additions and 2 deletions

View file

@ -523,6 +523,10 @@ def ArticlePage(server, url):
if author:
html = html + '<center>'+User( author )+'</center>'
timestamp = Articles.get(article, {}).get("timestamp", "")
arttime = str(datetime.fromtimestamp(timestamp).strftime("%B %d, %Y"))
html = html + "<br><small><center>"+str(arttime)+"</center></small>"
# Page views
# Views are calculated using an iframe which only loads when the page is
# rendered in a browser. It is also looking at whether the same cookie renders
@ -1357,6 +1361,16 @@ def User(username, stretch=False):
def Graph(server, url):
# Since /graph/ is used to count views
# we need the cookie to be generated and
# used by the user's browser before we load
# it, since a lot of people might just click
# the link once. In which case the entire page
# including graph loads before the cookie.
if not server.cookie:
Redirect(server, server.path, time=2)
user = validate(server.cookie)
html = """
@ -1654,9 +1668,9 @@ def AccessDenied(server):
###
def Redirect(server, url):
def Redirect(server, url, time=0):
html = """<meta http-equiv="Refresh" content="0; url='"""+url+"""'" />"""
html = """<meta http-equiv="Refresh" content=\""""+str(time)+"""; url='"""+url+"""'" />"""
send(server, html, 200)
def Login(server):

View file

@ -117,6 +117,12 @@ class handler(BaseHTTPRequestHandler):
self.cookie = self.headers.get("Cookie")
if self.cookie: self.cookie = self.cookie[-50:]
# ignore = ["/rss"]
# if not self.cookie and not self.path.startswith(tuple(ignore)):
# Render.Redirect(self, self.path)
# return
self.newview = False
categories = list(Render.tabs().keys())