1
0
Fork 0
mirror of https://gitlab.com/SIGBUS/nyaa.git synced 2024-12-22 09:19:59 +00:00

Finalize RSS ES fix

This commit is contained in:
TheAMM 2017-05-19 19:25:48 +03:00
parent e7614bcef1
commit daef4a9c6a
3 changed files with 25 additions and 9 deletions

View file

@ -8,6 +8,7 @@ from werkzeug.security import generate_password_hash, check_password_hash
from sqlalchemy_fulltext import FullText
import re
import base64
from markupsafe import escape as escape_markup
from urllib.parse import unquote as unquote_url
@ -121,6 +122,14 @@ class Torrent(db.Model):
# Escaped
return escape_markup(self.information)
@property
def info_hash_as_b32(self):
return base64.b32encode(self.info_hash).decode('utf-8')
@property
def info_hash_as_hex(self):
return self.info_hash.hex()
@property
def magnet_uri(self):
return create_magnet(self)

View file

@ -367,7 +367,6 @@ def render_rss(label, query, use_elastic):
use_elastic=use_elastic,
term=label,
site_url=flask.request.url_root,
compute_hash=lambda x: base64.b32encode(x).decode('utf-8'),
torrent_query=query)
response = flask.make_response(rss_xml)
response.headers['Content-Type'] = 'application/xml'

View file

@ -1,13 +1,13 @@
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<title>{{ config.SITE_NAME }} Torrent File RSS (No magnets)</title>
<title>{{ config.SITE_NAME }} Torrent File RSS</title>
<description>RSS Feed for {{ term }}</description>
<link>{{ url_for('home', _external=True) }}</link>
<atom:link href="{{ url_for('home', page='rss', _external=True) }}" rel="self" type="application/rss+xml" />
{% for torrent in torrent_query %}
<item>
<title>{{ torrent.display_name }}</title>
<description><![CDATA[{{ torrent.description }}]]></description>
{# <description><![CDATA[{{ torrent.description }}]]></description> #}
{% if use_elastic %}
{% if torrent.has_torrent %}
<link>{{ url_for('download_torrent', torrent_id=torrent.meta.id, _external=True) }}</link>
@ -16,6 +16,11 @@
{% endif %}
<guid isPermaLink="true">{{ url_for('view_torrent', torrent_id=torrent.meta.id, _external=True) }}</guid>
<pubDate>{{ torrent.created_time|rfc822_es }}</pubDate>
<seeders> {{- torrent.seed_count }}</seeders>
<leechers> {{- torrent.leech_count }}</leechers>
<downloads>{{- torrent.download_count }}</downloads>
<infoHash> {{- torrent.info_hash }}</infoHash>
{% else %}
{% if torrent.has_torrent %}
<link>{{ url_for('download_torrent', torrent_id=torrent.id, _external=True) }}</link>
@ -24,13 +29,16 @@
{% endif %}
<guid isPermaLink="true">{{ url_for('view_torrent', torrent_id=torrent.id, _external=True) }}</guid>
<pubDate>{{ torrent.created_time|rfc822 }}</pubDate>
<seeders> {{- torrent.stats.seed_count }}</seeders>
<leechers> {{- torrent.stats.leech_count }}</leechers>
<downloads>{{- torrent.stats.download_count }}</downloads>
<infoHash> {{- torrent.info_hash_as_hex }}</infoHash>
{% endif %}
<category>{{ torrent.main_category.name }} - {{ torrent.sub_category.name }}</category>
<size>{{ torrent.filesize | filesizeformat(True) }}</size>
<seeders>{{ torrent.stats.seed_count }}</seeders>
<leechers>{{ torrent.stats.leech_count }}</leechers>
<downloads>{{ torrent.stats.download_count }}</downloads>
<infoHash>{{ compute_hash(torrent.info_hash) }}</infoHash>
{% set cat_id = use_elastic and ((torrent.main_category_id|string) + '_' + (torrent.sub_category_id|string)) or torrent.sub_category.id_as_string %}
<categoryId>{{- cat_id }}</categoryId>
<category> {{- category_name(cat_id) }}</category>
<size> {{- torrent.filesize | filesizeformat(True) }}</size>
</item>
{% endfor %}
</channel>