diff --git a/.env.dist b/.env.dist index f98f4e4..31af5ec 100644 --- a/.env.dist +++ b/.env.dist @@ -1,14 +1,9 @@ FLASK_APP=run.py FLASK_ENV=development FLASK_PORT=5000 -MYSQL_USER=nyaa -MYSQL_PASSWORD=nyaa -MYSQL_DATABASE=nyaa -MYSQL_SERVER=db REDIS_SERVER=redis ADMIN_USERNAME=admin ADMIN_PASSWORD=secret REQUESTS_TIMEOUT=5 CACHE_TIMEOUT=3600 -MYSQL_ROOT_PASSWORD=root BLACKLIST_WORDS=Chris44,Vol.,[zza],.ssa,.ass,Ref:rain diff --git a/README.md b/README.md index 483f2c6..e04d58b 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ After a good rewrite in Python, it's time to show it to the public, and here it All is managed by environment variables. Please look into the `.env.dist` file to list all possible environment variables. -You have to install MariaDB (or any MySQL server) to be able to access the admin panel. +You have to have a running database server to be able to access the admin panel. ## Links diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 97438fb..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,32 +0,0 @@ -version: "2.4" - -services: - app: - build: . - ports: - - "5000:5000" - entrypoint: python3 run.py - working_dir: /app - depends_on: - - db - - redis - env_file: - - .env.dist - - .env - volumes: - - .:/app - - db: - image: mariadb - ports: - - "3306:3306" - env_file: - - .env.dist - - .env - volumes: - - ./.db:/var/lib/mysql - - redis: - image: redis - ports: - - "6379:6379" diff --git a/pynyaata/__init__.py b/pynyaata/__init__.py index 52f345b..1195c68 100644 --- a/pynyaata/__init__.py +++ b/pynyaata/__init__.py @@ -5,12 +5,12 @@ from operator import attrgetter, itemgetter from flask import redirect, render_template, request, url_for, abort from . import utils -from .config import app, auth, ADMIN_USERNAME, ADMIN_PASSWORD, MYSQL_ENABLED, APP_PORT, IS_DEBUG, TRANSMISSION_ENABLED +from .config import app, auth, ADMIN_USERNAME, ADMIN_PASSWORD, DB_ENABLED, APP_PORT, IS_DEBUG, TRANSMISSION_ENABLED from .connectors import get_instance, run_all, Nyaa from .connectors.core import ConnectorLang, ConnectorReturn from .forms import SearchForm, DeleteForm, EditForm, FolderDeleteForm, FolderEditForm -if MYSQL_ENABLED: +if DB_ENABLED: from .config import db from .models import AnimeFolder, AnimeTitle, AnimeLink @@ -18,10 +18,10 @@ if TRANSMISSION_ENABLED: from .config import transmission -def mysql_required(f): +def db_required(f): @wraps(f) def decorated_function(*args, **kwargs): - if not MYSQL_ENABLED: + if not DB_ENABLED: return abort(404) return f(*args, **kwargs) @@ -50,7 +50,7 @@ def verify_password(username, password): def boldify(name): query = request.args.get('q', '') name = utils.boldify(name, query) - if MYSQL_ENABLED: + if DB_ENABLED: for keyword in db.session.query(AnimeTitle.keyword.distinct()).all(): if keyword[0].lower() != query.lower(): name = utils.boldify(name, keyword[0]) @@ -69,7 +69,7 @@ def colorify(model): @app.context_processor def inject_user(): - return dict(mysql_disabled=not MYSQL_ENABLED) + return dict(db_disabled=not DB_ENABLED) @app.route('/') @@ -108,7 +108,7 @@ def latest(page=1): @app.route('/list') @app.route('/list/') -@mysql_required +@db_required def list_animes(url_filters='nyaa,yggtorrent'): filters = None for i, to_filter in enumerate(url_filters.split(',')): @@ -131,7 +131,7 @@ def list_animes(url_filters='nyaa,yggtorrent'): @app.route('/admin', methods=['GET', 'POST']) -@mysql_required +@db_required @auth.login_required def admin(): form = DeleteForm(request.form) @@ -165,7 +165,7 @@ def admin(): @app.route('/admin/folder', methods=['GET', 'POST']) -@mysql_required +@db_required @auth.login_required def folder_list(): form = FolderDeleteForm(request.form) @@ -188,7 +188,7 @@ def folder_list(): @app.route('/admin/folder/edit', methods=['GET', 'POST']) @app.route('/admin/folder/edit/', methods=['GET', 'POST']) -@mysql_required +@db_required @auth.login_required def folder_edit(folder_id=None): folder = AnimeFolder.query.filter_by(id=folder_id).first() @@ -213,7 +213,7 @@ def folder_edit(folder_id=None): @app.route('/admin/edit', methods=['GET', 'POST']) @app.route('/admin/edit/', methods=['GET', 'POST']) -@mysql_required +@db_required @auth.login_required def admin_edit(link_id=None): link = AnimeLink.query.filter_by(id=link_id).first() diff --git a/pynyaata/config.py b/pynyaata/config.py index 959a724..62d0338 100644 --- a/pynyaata/config.py +++ b/pynyaata/config.py @@ -17,7 +17,7 @@ APP_PORT = int(environ.get('FLASK_PORT', 5000)) CACHE_TIMEOUT = int(environ.get('CACHE_TIMEOUT', 60 * 60)) REQUESTS_TIMEOUT = int(environ.get('REQUESTS_TIMEOUT', 5)) BLACKLIST_WORDS = environ.get('BLACKLIST_WORDS', '').split(',') if environ.get('BLACKLIST_WORDS', '') else [] -MYSQL_ENABLED = False +DB_ENABLED = False REDIS_ENABLED = False TRANSMISSION_ENABLED = False @@ -30,18 +30,10 @@ auth = HTTPBasicAuth() logging.basicConfig(level=(logging.DEBUG if IS_DEBUG else logging.INFO)) logger = logging.getLogger(app.name) -db_host = environ.get('MYSQL_SERVER') -if db_host: - MYSQL_ENABLED = True - db_user = environ.get('MYSQL_USER') - db_password = environ.get('MYSQL_PASSWORD') - db_name = environ.get('MYSQL_DATABASE') - if not db_user or not db_password or not db_name: - logger.error('Missing connection environment variables') - exit() - app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://%s:%s@%s/%s?charset=utf8mb4' % ( - db_user, db_password, db_host, db_name - ) +db_uri = environ.get('DATABASE_URI') +if db_uri: + DB_ENABLED = True + app.config['SQLALCHEMY_DATABASE_URI'] = db_uri app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True app.config['SQLALCHEMY_ECHO'] = IS_DEBUG app.config['SQLALCHEMY_ENGINE_OPTIONS'] = { diff --git a/pynyaata/templates/layout.html b/pynyaata/templates/layout.html index c55b070..7aefddb 100644 --- a/pynyaata/templates/layout.html +++ b/pynyaata/templates/layout.html @@ -24,7 +24,7 @@   Latest torrents - {% if not mysql_disabled %} + {% if not db_disabled %}   diff --git a/pynyaata/utils.py b/pynyaata/utils.py index 4ef82e8..55099a9 100644 --- a/pynyaata/utils.py +++ b/pynyaata/utils.py @@ -2,11 +2,11 @@ import re from datetime import datetime from dateparser import parse -from .config import MYSQL_ENABLED, BLACKLIST_WORDS +from .config import DB_ENABLED, BLACKLIST_WORDS def link_exist_in_db(href): - if MYSQL_ENABLED: + if DB_ENABLED: from .models import AnimeLink return AnimeLink.query.filter_by(link=href).first() return False