From 1467421c136518c1dc22eb24fb2336b907ef73a0 Mon Sep 17 00:00:00 2001 From: BlenderDumbass Date: Fri, 29 Nov 2024 19:56:59 +0200 Subject: [PATCH] Graph cookie fix ( better counting of views ) --- modules/Render.py | 18 ++++++++++++++++-- modules/Run.py | 6 ++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/modules/Render.py b/modules/Render.py index fce0344..2e103a4 100644 --- a/modules/Render.py +++ b/modules/Render.py @@ -523,6 +523,10 @@ def ArticlePage(server, url): if author: html = html + '
'+User( author )+'
' + timestamp = Articles.get(article, {}).get("timestamp", "") + arttime = str(datetime.fromtimestamp(timestamp).strftime("%B %d, %Y")) + html = html + "
"+str(arttime)+"
" + # 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 = """""" + html = """""" send(server, html, 200) def Login(server): diff --git a/modules/Run.py b/modules/Run.py index 23610cf..a2847dc 100644 --- a/modules/Run.py +++ b/modules/Run.py @@ -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())