Toloka2WebV2/app/__init__.py

55 lines
1.2 KiB
Python

import os
from flask import (
Flask,
render_template,
request,
jsonify,
redirect,
url_for,
current_app,
send_file,
)
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
# from .api import api_bp
from .client import client_bp
from .api import *
from .db import db
# App
app = Flask(__name__, static_folder="../frontend/dist/assets")
app.register_blueprint(client_bp)
app.register_blueprint(api_bp)
# 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
app.logger.info(">>> {}".format(Config.FLASK_ENV))
@app.route("/")
def index_client():
dist_dir = current_app.config["DIST_DIR"]
entry = os.path.join(dist_dir, "index.html")
return send_file(entry)