1
0
Fork 0
mirror of https://gitlab.com/SIGBUS/nyaa.git synced 2024-12-22 07:50:01 +00:00

[templates, config] Add SITE_FLAVOR for selecting nyaa/sukebei, update templates

By default TABLE_PREFIX is derived from flavor.
Added back Date column, adjusted column widths
This commit is contained in:
TheAMM 2017-05-13 02:23:02 +03:00
parent 1eaaf08e8a
commit 517d3e8e32
5 changed files with 82 additions and 146 deletions

View file

@ -20,8 +20,8 @@ CSRF_SESSION_KEY = '***'
SECRET_KEY = '***' SECRET_KEY = '***'
# Prefix for running multiple sites, user table will not be prefixed. # Prefix for running multiple sites, user table will not be prefixed.
# For sukebei, change 'nyaa_' to 'sukebei_' SITE_FLAVOR = 'nyaa' # 'nyaa' or 'sukebei'
TABLE_PREFIX = 'nyaa_' TABLE_PREFIX = SITE_FLAVOR + '_'
# for recaptcha and email verification: # for recaptcha and email verification:
# keys for localhost. Change as appropriate when actual domain is registered. # keys for localhost. Change as appropriate when actual domain is registered.

View file

@ -7,7 +7,7 @@ db.create_all()
# Insert categories # Insert categories
if app.config['TABLE_PREFIX'] == 'nyaa_': if app.config['SITE_FLAVOR'] == 'nyaa':
CATEGORIES = [ CATEGORIES = [
('Anime', ['Anime Music Video', 'English-translated', 'Non-English-translated', 'Raw']), ('Anime', ['Anime Music Video', 'English-translated', 'Non-English-translated', 'Raw']),
('Audio', ['Lossless', 'Lossy']), ('Audio', ['Lossless', 'Lossy']),
@ -16,7 +16,7 @@ if app.config['TABLE_PREFIX'] == 'nyaa_':
('Pictures', ['Graphics', 'Photos']), ('Pictures', ['Graphics', 'Photos']),
('Software', ['Applications', 'Games']), ('Software', ['Applications', 'Games']),
] ]
elif app.config['TABLE_PREFIX'] == 'sukebei_': elif app.config['SITE_FLAVOR'] == 'sukebei':
CATEGORIES = [ CATEGORIES = [
('Art', ['Anime', 'Doujinshi', 'Games', 'Manga', 'Pictures']), ('Art', ['Anime', 'Doujinshi', 'Games', 'Manga', 'Pictures']),
('Real Life', ['Photobooks / Pictures', 'Videos']), ('Real Life', ['Photobooks / Pictures', 'Videos']),

View file

@ -33,9 +33,10 @@ class TorrentFlags(IntEnum):
COMPLETE = 16 COMPLETE = 16
DELETED = 32 DELETED = 32
DB_TABLE_PREFIX = app.config['TABLE_PREFIX']
class Torrent(db.Model): class Torrent(db.Model):
__tablename__ = app.config['TABLE_PREFIX'] + 'torrents' __tablename__ = DB_TABLE_PREFIX + 'torrents'
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
info_hash = db.Column(BinaryType(length=20), unique=True, nullable=False, index=True) info_hash = db.Column(BinaryType(length=20), unique=True, nullable=False, index=True)
@ -56,17 +57,17 @@ class Torrent(db.Model):
default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False) default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
main_category_id = db.Column(db.Integer, db.ForeignKey( main_category_id = db.Column(db.Integer, db.ForeignKey(
app.config['TABLE_PREFIX'] + 'main_categories.id'), nullable=False) DB_TABLE_PREFIX + 'main_categories.id'), nullable=False)
sub_category_id = db.Column(db.Integer, nullable=False) sub_category_id = db.Column(db.Integer, nullable=False)
redirect = db.Column(db.Integer, db.ForeignKey( redirect = db.Column(db.Integer, db.ForeignKey(
app.config['TABLE_PREFIX'] + 'torrents.id'), nullable=True) DB_TABLE_PREFIX + 'torrents.id'), nullable=True)
__table_args__ = ( __table_args__ = (
Index('uploader_flag_idx', 'uploader_id', 'flags'), Index('uploader_flag_idx', 'uploader_id', 'flags'),
ForeignKeyConstraint( ForeignKeyConstraint(
['main_category_id', 'sub_category_id'], ['main_category_id', 'sub_category_id'],
[app.config['TABLE_PREFIX'] + 'sub_categories.main_category_id', [DB_TABLE_PREFIX + 'sub_categories.main_category_id',
app.config['TABLE_PREFIX'] + 'sub_categories.id'] DB_TABLE_PREFIX + 'sub_categories.id']
), {} ), {}
) )
@ -150,32 +151,32 @@ class TorrentNameSearch(FullText, Torrent):
class TorrentFilelist(db.Model): class TorrentFilelist(db.Model):
__tablename__ = app.config['TABLE_PREFIX'] + 'torrents_filelist' __tablename__ = DB_TABLE_PREFIX + 'torrents_filelist'
__table_args__ = {'mysql_row_format': 'COMPRESSED'} __table_args__ = {'mysql_row_format': 'COMPRESSED'}
torrent_id = db.Column(db.Integer, db.ForeignKey( torrent_id = db.Column(db.Integer, db.ForeignKey(
app.config['TABLE_PREFIX'] + 'torrents.id', ondelete="CASCADE"), primary_key=True) DB_TABLE_PREFIX + 'torrents.id', ondelete="CASCADE"), primary_key=True)
filelist_blob = db.Column(MediumBlobType, nullable=True) filelist_blob = db.Column(MediumBlobType, nullable=True)
torrent = db.relationship('Torrent', uselist=False, back_populates='filelist') torrent = db.relationship('Torrent', uselist=False, back_populates='filelist')
class TorrentInfo(db.Model): class TorrentInfo(db.Model):
__tablename__ = app.config['TABLE_PREFIX'] + 'torrents_info' __tablename__ = DB_TABLE_PREFIX + 'torrents_info'
__table_args__ = {'mysql_row_format': 'COMPRESSED'} __table_args__ = {'mysql_row_format': 'COMPRESSED'}
torrent_id = db.Column(db.Integer, db.ForeignKey( torrent_id = db.Column(db.Integer, db.ForeignKey(
app.config['TABLE_PREFIX'] + 'torrents.id', ondelete="CASCADE"), primary_key=True) DB_TABLE_PREFIX + 'torrents.id', ondelete="CASCADE"), primary_key=True)
info_dict = db.Column(MediumBlobType, nullable=True) info_dict = db.Column(MediumBlobType, nullable=True)
torrent = db.relationship('Torrent', uselist=False, back_populates='info') torrent = db.relationship('Torrent', uselist=False, back_populates='info')
class Statistic(db.Model): class Statistic(db.Model):
__tablename__ = app.config['TABLE_PREFIX'] + 'statistics' __tablename__ = DB_TABLE_PREFIX + 'statistics'
torrent_id = db.Column(db.Integer, db.ForeignKey( torrent_id = db.Column(db.Integer, db.ForeignKey(
app.config['TABLE_PREFIX'] + 'torrents.id', ondelete="CASCADE"), primary_key=True) DB_TABLE_PREFIX + 'torrents.id', ondelete="CASCADE"), primary_key=True)
seed_count = db.Column(db.Integer, default=0, nullable=False, index=True) seed_count = db.Column(db.Integer, default=0, nullable=False, index=True)
leech_count = db.Column(db.Integer, default=0, nullable=False, index=True) leech_count = db.Column(db.Integer, default=0, nullable=False, index=True)
@ -198,9 +199,9 @@ class Trackers(db.Model):
class TorrentTrackers(db.Model): class TorrentTrackers(db.Model):
__tablename__ = app.config['TABLE_PREFIX'] + 'torrent_trackers' __tablename__ = DB_TABLE_PREFIX + 'torrent_trackers'
torrent_id = db.Column(db.Integer, db.ForeignKey(app.config['TABLE_PREFIX'] + 'torrents.id', ondelete="CASCADE"), primary_key=True) torrent_id = db.Column(db.Integer, db.ForeignKey(DB_TABLE_PREFIX + 'torrents.id', ondelete="CASCADE"), primary_key=True)
tracker_id = db.Column(db.Integer, db.ForeignKey('trackers.id', ondelete="CASCADE"), primary_key=True) tracker_id = db.Column(db.Integer, db.ForeignKey('trackers.id', ondelete="CASCADE"), primary_key=True)
order = db.Column(db.Integer, nullable=False, index=True) order = db.Column(db.Integer, nullable=False, index=True)
@ -212,7 +213,7 @@ class TorrentTrackers(db.Model):
class MainCategory(db.Model): class MainCategory(db.Model):
__tablename__ = app.config['TABLE_PREFIX'] + 'main_categories' __tablename__ = DB_TABLE_PREFIX + 'main_categories'
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(length=64), nullable=False) name = db.Column(db.String(length=64), nullable=False)
@ -233,11 +234,11 @@ class MainCategory(db.Model):
class SubCategory(db.Model): class SubCategory(db.Model):
__tablename__ = app.config['TABLE_PREFIX'] + 'sub_categories' __tablename__ = DB_TABLE_PREFIX + 'sub_categories'
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
main_category_id = db.Column(db.Integer, db.ForeignKey( main_category_id = db.Column(db.Integer, db.ForeignKey(
app.config['TABLE_PREFIX'] + 'main_categories.id'), primary_key=True) DB_TABLE_PREFIX + 'main_categories.id'), primary_key=True)
name = db.Column(db.String(length=64), nullable=False) name = db.Column(db.String(length=64), nullable=False)
main_category = db.relationship('MainCategory', uselist=False, back_populates='sub_categories') main_category = db.relationship('MainCategory', uselist=False, back_populates='sub_categories')

View file

@ -68,9 +68,9 @@
</ul> </ul>
</li> </li>
<li><a href="{% if rss_filter %}{{ url_for('home', page='rss', **rss_filter) }}{% else %}{{ url_for('home', page='rss') }}{% endif %}">RSS</a></li> <li><a href="{% if rss_filter %}{{ url_for('home', page='rss', **rss_filter) }}{% else %}{{ url_for('home', page='rss') }}{% endif %}">RSS</a></li>
{% if config.TABLE_PREFIX == 'nyaa_' %} {% if config.SITE_FLAVOR == 'nyaa' %}
<li><a href="https://sukebei.nyaa.si/">R-18</a></li> <li><a href="https://sukebei.nyaa.si/">R-18</a></li>
{% elif config.TABLE_PREFIX == 'sukebei_' %} {% elif config.SITE_FLAVOR == 'sukebei' %}
<li><a href="https://nyaa.si/">SFW</a></li> <li><a href="https://nyaa.si/">SFW</a></li>
{% endif %} {% endif %}
</ul> </ul>
@ -153,115 +153,53 @@
</select> </select>
</div> </div>
<div class="input-group-btn" id="navFilter"> <div class="input-group-btn" id="navFilter">
{% if config.TABLE_PREFIX == 'nyaa_' %} {% set nyaa_cats = [('1_0', 'Anime', 'Anime'),
<select class="selectpicker show-tick" title="Category" data-width="170px" name="c"> ('1_1', '- Anime Music Video', 'Anime - AMV'),
<option value="0_0" title="Show all" {% if search is defined and search["category"] == "0_0" %}selected{% else %}selected{% endif %}> ('1_2', '- English-translated', 'Anime - English'),
Show all ('1_3', '- Non-English-translated', 'Anime - Non-English'),
</option> ('1_4', '- Raw', 'Anime - Raw'),
<option value="1_0" title="Anime" {% if search is defined and search["category"] == "1_0" %}selected{% endif %}> ('2_0', 'Audio', 'Audio'),
Anime ('2_1', '- Lossless', 'Audio - Lossless'),
</option> ('2_2', '- Lossy', 'Audio - Lossy'),
<option value="1_1" title="Anime - AMV" {% if search is defined and search["category"] == "1_1" %}selected{% endif %}> ('3_0', 'Literature', 'Literature'),
- Anime Music Video ('3_1', '- English-translated', 'Literature - English'),
</option> ('3_2', '- Non-English-translated', 'Literature - Non-English'),
<option value="1_2" title="Anime - English" {% if search is defined and search["category"] == "1_2" %}selected{% endif %}> ('3_3', '- Raw', 'Literature - Raw'),
- English-translated ('4_0', 'Live Action', 'Live Action'),
</option> ('4_1', '- English-translated', 'Live Action - English'),
<option value="1_3" title="Anime - Non-English" {% if search is defined and search["category"] == "1_3" %}selected{% endif %}> ('4_2', '- Idol/Promotional Video', 'Live Action - Idol/PV'),
- Non-English-translated ('4_3', '- Non-English-translated', 'Live Action - Non-English'),
</option> ('4_4', '- Raw', 'Live Action - Raw'),
<option value="1_4" title="Anime - Raw" {% if search is defined and search["category"] == "1_4" %}selected{% endif %}> ('5_0', 'Pictures', 'Pictures'),
- Raw ('5_1', '- Graphics', 'Pictures - Graphics'),
</option> ('5_2', '- Photos', 'Pictures - Photos'),
<option value="2_0" title="Audio" {% if search is defined and search["category"] == "2_0" %}selected{% endif %}> ('6_0', 'Software', 'Software'),
Audio ('6_1', '- Applications', 'Software - Apps'),
</option> ('6_2', '- Games', 'Software - Games')] %}
<option value="2_1" title="Audio - Lossless" {% if search is defined and search["category"] == "2_1" %}selected{% endif %}> {% set suke_cats = [('1_0', 'Art', 'Art'),
- Lossless ('1_1', '- Anime', 'Art - Anime'),
</option> ('1_2', '- Doujinshi', 'Art - Doujinshi'),
<option value="2_2" title="Audio - Lossy" {% if search is defined and search["category"] == "2_2" %}selected{% endif %}> ('1_3', '- Games', 'Art - Games'),
- Lossy ('1_4', '- Manga', 'Art - Manga'),
</option> ('1_5', '- Pictures', 'Art - Pictures'),
<option value="3_0" title="Literature" {% if search is defined and search["category"] == "3_0" %}selected{% endif %}> ('2_0', 'Real Life', 'Real Life'),
Literature ('2_1', '- Photobooks and Pictures', 'Real Life - Pictures'),
</option> ('2_2', '- Videos', 'Real Life - Videos')] %}
<option value="3_1" title="Literature - English" {% if search is defined and search["category"] == "3_1" %}selected{% endif %}> {% if config.SITE_FLAVOR == 'nyaa' %}
- English-translated {% set used_cats = nyaa_cats %}
</option> {% elif config.SITE_FLAVOR == 'sukebei' %}
<option value="3_2" title="Literature - Non-English" {% if search is defined and search["category"] == "3_2" %}selected{% endif %}> {% set used_cats = suke_cats %}
- Non-English-translated
</option>
<option value="3_3" title="Literature - Raw" {% if search is defined and search["category"] == "3_3" %}selected{% endif %}>
- Raw
</option>
<option value="4_0" title="Live Action" {% if search is defined and search["category"] == "4_0" %}selected{% endif %}>
Live Action
</option>
<option value="4_1" title="Live Action - English" {% if search is defined and search["category"] == "4_1" %}selected{% endif %}>
- English-translated
</option>
<option value="4_2" title="Live Action - Idol/PV" {% if search is defined and search["category"] == "4_2" %}selected{% endif %}>
- Idol/Promotional Video
</option>
<option value="4_3" title="Live Action - Non-English" {% if search is defined and search["category"] == "4_3" %}selected{% endif %}>
- Non-English-translated
</option>
<option value="4_4" title="Live Action - Raw" {% if search is defined and search["category"] == "4_4" %}selected{% endif %}>
- Raw
</option>
<option value="5_0" title="Pictures" {% if search is defined and search["category"] == "5_0" %}selected{% endif %}>
Pictures
</option>
<option value="5_1" title="Pictures - Graphics" {% if search is defined and search["category"] == "5_1" %}selected{% endif %}>
- Graphics
</option>
<option value="5_2" title="Pictures - Photos" {% if search is defined and search["category"] == "5_2" %}selected{% endif %}>
- Photos
</option>
<option value="6_0" title="Software" {% if search is defined and search["category"] == "6_0" %}selected{% endif %}>
Software
</option>
<option value="6_1" title="Software - Apps" {% if search is defined and search["category"] == "6_1" %}selected{% endif %}>
- Applications
</option>
<option value="6_2" title="Software - Games" {% if search is defined and search["category"] == "6_2" %}selected{% endif %}>
- Games
</option>
</select>
{% elif config.TABLE_PREFIX == 'sukebei_' %}
<select class="selectpicker show-tick" title="Category" data-width="170px" name="c">
<option value="0_0" title="Show all" {% if search is defined and search["category"] == "0_0" %}selected{% else %}selected{% endif %}>
Show all
</option>
<option value="1_0" title="Art" {% if search is defined and search["category"] == "1_0" %}selected{% endif %}>
Art
</option>
<option value="1_1" title="Art - Anime" {% if search is defined and search["category"] == "1_1" %}selected{% endif %}>
- Anime
</option>
<option value="1_2" title="Art - Doujinshi" {% if search is defined and search["category"] == "1_2" %}selected{% endif %}>
- Doujinshi
</option>
<option value="1_3" title="Art - Games" {% if search is defined and search["category"] == "1_3" %}selected{% endif %}>
- Games
</option>
<option value="1_4" title="Art - Manga" {% if search is defined and search["category"] == "1_4" %}selected{% endif %}>
- Manga
</option>
<option value="1_5" title="Art - Pictures" {% if search is defined and search["category"] == "1_5" %}selected{% endif %}>
- Pictures
</option>
<option value="2_0" title="Real Life" {% if search is defined and search["category"] == "2_0" %}selected{% endif %}>
Real Life
</option>
<option value="2_1" title="Real Life - Pictures" {% if search is defined and search["category"] == "2_1" %}selected{% endif %}>
- Photobooks and Pictures
</option>
<option value="2_2" title="Real Life - Videos" {% if search is defined and search["category"] == "2_2" %}selected{% endif %}>
- Videos
</option>
</select>
{% endif %} {% endif %}
<select class="selectpicker show-tick" title="Category" data-width="170px" name="c">
<option value="0_0" title="Show all" {% if search is defined and search["category"] == "0_0" %}selected{% else %}selected{% endif %}>
Show all
</option>
{% for cat_id, cat_name, cat_title in used_cats %}
<option value="{{ cat_id }}" title="{{ cat_title }}" {% if search is defined and search.category == cat_id %}selected{% endif %}>
{{ cat_name }}
</option>
{% endfor %}
</select>
</div> </div>
<div class="input-group-btn"> <div class="input-group-btn">
<button class="btn btn-primary" type="submit"> <button class="btn btn-primary" type="submit">

View file

@ -25,16 +25,19 @@
{% call render_column_header("width:100px;", center_text=True, sort_key="size") %} {% call render_column_header("width:100px;", center_text=True, sort_key="size") %}
<div>Size</div> <div>Size</div>
{% endcall %} {% endcall %}
{% call render_column_header("width:140px;", center_text=True, sort_key="id", header_title="In UTC") %}
<div>Date</div>
{% endcall %}
{% if config.ENABLE_SHOW_STATS %} {% if config.ENABLE_SHOW_STATS %}
{% call render_column_header("width:65px;", center_text=True, sort_key="seeders", header_title="Seeds") %} {% call render_column_header("width:50px;", center_text=True, sort_key="seeders", header_title="Seeds") %}
<i class="fa fa-arrow-up" aria-hidden="true"></i> <i class="fa fa-arrow-up" aria-hidden="true"></i>
{% endcall %} {% endcall %}
{% call render_column_header("width:65px;", center_text=True, sort_key="leechers", header_title="Leeches") %} {% call render_column_header("width:50px;", center_text=True, sort_key="leechers", header_title="Leeches") %}
<i class="fa fa-arrow-down" aria-hidden="true"></i> <i class="fa fa-arrow-down" aria-hidden="true"></i>
{% endcall %} {% endcall %}
{% call render_column_header("width:65px;", center_text=True, sort_key="downloads", header_title="Completed downloads") %} {% call render_column_header("width:50px;", center_text=True, sort_key="downloads", header_title="Completed downloads") %}
<i class="fa fa-check" aria-hidden="true"></i> <i class="fa fa-check" aria-hidden="true"></i>
{% endcall %} {% endcall %}
@ -44,23 +47,17 @@
<tbody> <tbody>
{% for torrent in torrent_query.items %} {% for torrent in torrent_query.items %}
<tr class="{% if torrent.deleted %}deleted{% elif torrent.hidden %}warning{% elif torrent.remake %}danger{% elif torrent.trusted %}success{% else %}default{% endif %}"> <tr class="{% if torrent.deleted %}deleted{% elif torrent.hidden %}warning{% elif torrent.remake %}danger{% elif torrent.trusted %}success{% else %}default{% endif %}">
{% if config.TABLE_PREFIX == 'nyaa_' %} {% set cat_id = (torrent.main_category.id|string) + '_' + (torrent.sub_category.id|string) %}
{% set icon_dir = config.SITE_FLAVOR %}
<td style="padding:0 4px;"> <td style="padding:0 4px;">
<a href="/?c={{ torrent.main_category.id }}_{{ torrent.sub_category.id }}"> <a href="/?c={{ cat_id }}">
<img src="/static/img/icons/nyaa/{{ torrent.main_category.id }}_{{ torrent.sub_category.id }}.png"> <img src="/static/img/icons/{{ icon_dir }}/{{ cat_id }}.png">
</a> </a>
</td> </td>
{% elif config.TABLE_PREFIX == 'sukebei_' %}
<td style="padding:0 4px;">
<a href="/?c={{ torrent.main_category.id }}_{{ torrent.sub_category.id }}">
<img src="/static/img/icons/sukebei/{{ torrent.main_category.id }}_{{ torrent.sub_category.id }}.png">
</a>
</td>
{% endif %}
<td><a href="/view/{{ torrent.id }}">{{ torrent.display_name | escape }}</a></td> <td><a href="/view/{{ torrent.id }}">{{ torrent.display_name | escape }}</a></td>
<td style="white-space: nowrap;text-align: center;">{% if torrent.has_torrent %}<a href="/view/{{ torrent.id }}/torrent"><i class="fa fa-fw fa-download"></i></a> {% endif %}<a href="{{ torrent.magnet_uri }}"><i class="fa fa-fw fa-magnet"></i></a></td> <td style="white-space: nowrap;text-align: center;">{% if torrent.has_torrent %}<a href="/view/{{ torrent.id }}/torrent"><i class="fa fa-fw fa-download"></i></a> {% endif %}<a href="{{ torrent.magnet_uri }}"><i class="fa fa-fw fa-magnet"></i></a></td>
<td>{{ torrent.filesize | filesizeformat(True) }}</td> <td>{{ torrent.filesize | filesizeformat(True) }}</td>
{# <td>{{ torrent.created_time.strftime('%Y-%m-%d %H:%M') }}</td> #} <td>{{ torrent.created_time.strftime('%Y-%m-%d %H:%M') }}</td>
{% if config.ENABLE_SHOW_STATS %} {% if config.ENABLE_SHOW_STATS %}
<td class="text-center" style="color: green;">{{ torrent.stats.seed_count }}</td> <td class="text-center" style="color: green;">{{ torrent.stats.seed_count }}</td>
<td class="text-center" style="color: red;">{{ torrent.stats.leech_count }}</td> <td class="text-center" style="color: red;">{{ torrent.stats.leech_count }}</td>