68 lines
1.9 KiB
Python
68 lines
1.9 KiB
Python
import os
|
|
from flask import Flask, redirect, url_for, request, current_app
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
from flask_login import LoginManager, current_user
|
|
from flask_migrate import Migrate
|
|
|
|
# ✅ Docker-Pfade
|
|
UPLOAD_FOLDER = '/app/uploads'
|
|
RESULT_FOLDER = '/app/results'
|
|
|
|
db = SQLAlchemy()
|
|
login_manager = LoginManager()
|
|
migrate = Migrate()
|
|
|
|
def create_app():
|
|
app = Flask(__name__)
|
|
|
|
# 🔑 Configs
|
|
app.config['SECRET_KEY'] = '008e7369b075886d5f494c8813efdfb17155da6af12b3fe8ee'
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///users.db'
|
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
|
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
|
|
app.config['RESULT_FOLDER'] = RESULT_FOLDER
|
|
app.config['ALLOW_USER_SIGNUP'] = True # ✅ Aktiviert!
|
|
|
|
# DB + Tools
|
|
db.init_app(app)
|
|
migrate.init_app(app, db)
|
|
login_manager.init_app(app)
|
|
login_manager.login_view = 'auth.login'
|
|
|
|
# User Loader
|
|
@login_manager.user_loader
|
|
def load_user(user_id):
|
|
from .models import User
|
|
return User.query.get(int(user_id))
|
|
|
|
# Protected Routes
|
|
@app.before_request
|
|
def require_login():
|
|
allowed = ['auth.login', 'auth.signup', 'static']
|
|
if (not current_user.is_authenticated and
|
|
request.endpoint not in allowed and
|
|
not request.path.startswith('/static')):
|
|
return redirect(url_for('auth.login'))
|
|
|
|
# Ordner
|
|
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
|
|
os.makedirs(app.config['RESULT_FOLDER'], exist_ok=True)
|
|
|
|
# Routes
|
|
from . import routes
|
|
app.register_blueprint(routes.bp)
|
|
|
|
# Index Redirect
|
|
@app.route('/')
|
|
def index():
|
|
return redirect(url_for('auth.job_status'))
|
|
|
|
# DB Tables
|
|
with app.app_context():
|
|
db.create_all()
|
|
|
|
return app
|
|
|
|
if __name__ == '__main__':
|
|
app = create_app()
|
|
app.run(host='0.0.0.0', port=5000, debug=False)
|