Toloka2WebV2/app/__init__.py

56 lines
1.2 KiB
Python
Raw Normal View History

2024-09-23 12:15:53 -04:00
import os
2024-09-23 12:17:25 -04:00
from flask import (
Flask,
render_template,
request,
jsonify,
redirect,
url_for,
current_app,
send_file,
)
2024-09-23 12:15:53 -04:00
from flask_caching import Cache
from toloka2MediaServer.main_logic import (
add_release_by_url,
update_release_by_name,
update_releases,
search_torrents,
get_torrent as get_torrent_external,
add_torrent as add_torrent_external,
)
from app.services.torrents import initiate_config, serialize_operation_result
2024-09-23 12:17:25 -04:00
# from .api import api_bp
2024-09-23 12:15:53 -04:00
from .client import client_bp
from .api import *
from .db import db
# App
2024-09-23 12:17:25 -04:00
app = Flask(__name__, static_folder="../frontend/dist/assets")
2024-09-23 12:15:53 -04:00
app.register_blueprint(client_bp)
2024-09-23 12:17:25 -04:00
app.register_blueprint(api_bp)
2024-09-23 12:15:53 -04:00
# Cache
cache = Cache(config={"CACHE_TYPE": "SimpleCache"})
cache.init_app(app)
# Database
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///t2w.db"
db.init_app(app)
with app.app_context():
db.create_all()
# Production route
from .config import Config
2024-09-23 12:17:25 -04:00
app.logger.info(">>> {}".format(Config.FLASK_ENV))
@app.route("/")
2024-09-23 12:15:53 -04:00
def index_client():
2024-09-23 12:17:25 -04:00
dist_dir = current_app.config["DIST_DIR"]
entry = os.path.join(dist_dir, "index.html")
2024-09-23 12:15:53 -04:00
return send_file(entry)