RSS wasn't properly generated. Fixed!

This commit is contained in:
BlenderDumbass 2024-12-01 02:59:19 +02:00
parent 161eb85e29
commit 6b5d67f429
2 changed files with 90 additions and 11 deletions

View file

@ -4,6 +4,7 @@
import os import os
import json import json
import time import time
import email
import random import random
import hashlib import hashlib
import urllib.parse import urllib.parse
@ -14,9 +15,12 @@ from modules import Set
from modules import markdown from modules import markdown
from modules.Common import * from modules.Common import *
KnownCookies = [] KnownCookies = []
RecentArticles = {} RecentArticles = {}
RefferedArticles = {} RefferedArticles = {}
ProblematicRefreshes = []
def guess_type(path): def guess_type(path):
@ -1267,7 +1271,58 @@ def EditorPage(server):
<img style="vertical-align: middle" src="/icon/mus"> <img style="vertical-align: middle" src="/icon/mus">
<input class="button" style="width:90%" name="recording" placeholder="Link To Sound Recording ( Optional )" value='"""+article.get("recording", "").replace("'", "&apos;")+"""'> <input class="button" style="width:90%" name="recording" placeholder="Link To Sound Recording ( Optional )" value='"""+article.get("recording", "").replace("'", "&apos;")+"""'>
"""
# Optional release options
if rank(user.get("username","")) == 0:
html = html + """
<details>
<summary class="button">
<img alt="[icon unlock]" style="vertical-align: middle" src="/icon/unlock">
Unlock
</summary>
<div class="dark_box">
<br>
<br>
<center><small>
For unlockable files that will be published after a certain statistics is reached.
</small></center>
<br><br>
<img alt="[icon file]" style="vertical-align: middle" src="/icon/file">
<input class="button" style="width:90%" name="unlock_file" placeholder="Unlocked File ( on the server )">
<br>
<img alt="[icon link]" style="vertical-align: middle" src="/icon/link">
<input class="button" style="width:90%" name="unlock_file" placeholder="API to check">
<br>
<img alt="[icon checlist]" style="vertical-align: middle" src="/icon/checklist">
<input class="button" style="width:90%" name="unlock_file" placeholder="Key To Look For ( split with / for nested deep data )">
<br>
<img alt="[icon ok]" style="vertical-align: middle" src="/icon/ok">
<input class="button" style="width:90%" name="unlock_file" placeholder="Goal ( should be a number )">
<br>
<img alt="[icon scene]" style="vertical-align: middle" src="/icon/scene">
<input class="button" style="width:90%" name="unlock_file" placeholder="Statistic's Name">
<br>
</div>
</details>
"""
html = html + """
<br> <br>
<center> <center>
@ -1276,6 +1331,7 @@ def EditorPage(server):
<textarea class="toot" rows="5" style="width:95%" name="description" placeholder="Description ( Optional )">"""+article.get("description", "")+"""</textarea> <textarea class="toot" rows="5" style="width:95%" name="description" placeholder="Description ( Optional )">"""+article.get("description", "")+"""</textarea>
</center> </center>
<button class="button" type="submit"> <button class="button" type="submit">
<img style="vertical-align: middle" src="/icon/scene_new"> <img style="vertical-align: middle" src="/icon/scene_new">
Publish Publish
@ -1288,6 +1344,7 @@ def EditorPage(server):
html = html + LoginButton(server) html = html + LoginButton(server)
send(server, html, 200) send(server, html, 200)
### ###
@ -1325,7 +1382,7 @@ def ArticlePreview(article, Tabs, cookie=""):
html = html + '<img alt="[icon '+tab+']" src="/icon/'+Tabs.get(tab, {}).get("icon", "folder")+'" style="vertical-align: middle">' html = html + '<img alt="[icon '+tab+']" src="/icon/'+Tabs.get(tab, {}).get("icon", "folder")+'" style="vertical-align: middle">'
html = html + article.get("title", "")+"</h1></a>"+sup+"\n" html = html + article.get("title", "")+"</h1></a>"+sup+"\n"
if "thumbnail" in article: if article.get("thumbnail"):
html = html + '<center><a href="'+url+'"><img alt="[thumbnail]" src="'+article["thumbnail"]+'"></a></center>' html = html + '<center><a href="'+url+'"><img alt="[thumbnail]" src="'+article["thumbnail"]+'"></a></center>'
author = article.get("author", "") author = article.get("author", "")
@ -1401,11 +1458,17 @@ def Graph(server, url):
# it, since a lot of people might just click # it, since a lot of people might just click
# the link once. In which case the entire page # the link once. In which case the entire page
# including graph loads before the cookie. # including graph loads before the cookie.
if not server.cookie:
if not server.cookie and server.headers.get("user-agent", "") not in ProblematicRefreshes:
Redirect(server, server.path) Redirect(server, server.path)
ProblematicRefreshes.append(server.headers.get("user-agent", ""))
return return
if server.headers.get("user-agent", "") in ProblematicRefreshes:
ProblematicRefreshes.remove(server.headers.get("user-agent", ""))
# Sometimes scrapers try to load graph without # Sometimes scrapers try to load graph without
# loading the article first. We don't want to count # loading the article first. We don't want to count
# it as a view. # it as a view.
@ -1413,6 +1476,7 @@ def Graph(server, url):
print(consoleForm(server.cookie), "Article wasn't loaded, scrapers!") print(consoleForm(server.cookie), "Article wasn't loaded, scrapers!")
AccessDenied(server) AccessDenied(server)
return return
user = validate(server.cookie) user = validate(server.cookie)
@ -2390,9 +2454,7 @@ def RSS(server):
title = account.get("title", author)+" at: "+title title = account.get("title", author)+" at: "+title
rss = """ rss = """<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/"> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel> <channel>
@ -2419,14 +2481,15 @@ def RSS(server):
pubDate = Articles[article].get("timestamp", 0) pubDate = Articles[article].get("timestamp", 0)
pubDate = datetime.fromtimestamp(pubDate) pubDate = datetime.fromtimestamp(pubDate)
pubDate = pubDate.strftime('%a, %d %b %H:%M:%S')+" -0000" pubDate = email.utils.format_datetime(pubDate)
rss = rss + """ rss = rss + """
<item> <item>
<title>"""+Articles[article].get("title", article)+"""</title> <title>"""+Articles[article].get("title", article).replace("&", "&amp;")+"""</title>
<link>https://"""+config.get("domain", "example.com")+Articles[article].get("url", "")+"""</link> <link>https://"""+config.get("domain", "example.com")+Articles[article].get("url", "")+"""</link>
<description><![CDATA["""+markdown.convert(Articles[article].get("description", article), False)+"""]]></description> <guid>https://"""+config.get("domain", "example.com")+Articles[article].get("url", "")+"""</guid>
<description><![CDATA["""+markdown.convert(Articles[article].get("description", article), False, fullpath=True)+"""]]></description>
<pubDate>"""+pubDate+"""</pubDate> <pubDate>"""+pubDate+"""</pubDate>
</item> </item>

View file

@ -399,8 +399,13 @@ def search_convert(s):
r = r + i r = r + i
return r return r
def convert(filename, isfile=True): def convert(filename, isfile=True, fullpath=True):
if fullpath:
from modules import Set
config = Set.Load()
domain = config.get("domain", "")
textReturn = "" textReturn = ""
if isfile: if isfile:
@ -458,11 +463,17 @@ def convert(filename, isfile=True):
textReturn = textReturn + '\n<br></div><br><div class="dark_box"><br><a href="#'+search_convert(i[-1].replace("#", "").replace("\n", "")[1:])+'"><h'+str(i[0])+' id="'+search_convert(i[-1].replace("#", "").replace("\n", "")[1:])+'">' + i[-1].replace("#", "") +"</h"+str(i[0])+"></a><br><br>" textReturn = textReturn + '\n<br></div><br><div class="dark_box"><br><a href="#'+search_convert(i[-1].replace("#", "").replace("\n", "")[1:])+'"><h'+str(i[0])+' id="'+search_convert(i[-1].replace("#", "").replace("\n", "")[1:])+'">' + i[-1].replace("#", "") +"</h"+str(i[0])+"></a><br><br>"
elif i[0] == "image_link": elif i[0] == "image_link":
if fullpath and i[-1].startswith("/"):
i[-1] = "https://"+domain+i[-1]
textReturn = textReturn + '\n<center><a href="'+i[-1]+'">'+'<img src="'+i[1]+'">'+"</a></center>" textReturn = textReturn + '\n<center><a href="'+i[-1]+'">'+'<img src="'+i[1]+'">'+"</a></center>"
elif i[0] == "image": elif i[0] == "image":
if fullpath and i[-1].startswith("/"):
i[-1] = "https://"+domain+i[-1]
if i[1] == "audio": if i[1] == "audio":
try: try:
@ -486,9 +497,14 @@ def convert(filename, isfile=True):
elif i[0] == "link": elif i[0] == "link":
if not i[-1]: if not i[-1]:
i[-1] = "/search?text="+urllib.parse.quote_plus(i[1]) i[-1] = "/search?text="+urllib.parse.quote_plus(i[1])
if fullpath and i[-1].startswith("/"):
i[-1] = "https://"+domain+i[-1]
textReturn = textReturn + '<a href="'+i[-1]+'">'+i[1]+"</a>" textReturn = textReturn + '<a href="'+i[-1]+'">'+i[1]+"</a>"