webcrawler v0.1

This commit is contained in:
mkrieger 2024-11-13 18:40:55 +01:00
parent e2d9a197c0
commit 008e2bc274
18 changed files with 681 additions and 0 deletions

52
app/__init__.py Normal file
View file

@ -0,0 +1,52 @@
import os
from flask import Flask, redirect, url_for, request
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager, current_user
from .models import db, User
# Konfiguration für Upload- und Ergebnis-Ordner
UPLOAD_FOLDER = '/app/uploads'
RESULT_FOLDER = '/app/results'
def create_app():
app = Flask(__name__)
app.config['SECRET_KEY'] = '008e7369b075886d5f494c8813efdfb17155da6af12b3fe8ee'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///users.db'
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.config['RESULT_FOLDER'] = RESULT_FOLDER
db.init_app(app)
# Flask-Login Setup
login_manager = LoginManager()
login_manager.login_view = 'auth.login'
login_manager.init_app(app)
@login_manager.user_loader
def load_user(user_id):
return User.query.get(int(user_id))
# Umleitung nicht authentifizierter Benutzer, statische Dateien und bestimmte Routen ausnehmen
@app.before_request
def require_login():
allowed_routes = ['auth.login', 'auth.signup']
# Prüfen, ob der Benutzer authentifiziert ist oder eine erlaubte Route anfragt
if (not current_user.is_authenticated
and request.endpoint not in allowed_routes
and not request.path.startswith('/static/')):
return redirect(url_for('auth.login'))
# Erstellen Sie die Ordner, falls sie noch nicht existieren
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
os.makedirs(app.config['RESULT_FOLDER'], exist_ok=True)
# Registrieren der Routen
from . import routes
app.register_blueprint(routes.bp)
# Erstellen der Tabellen in der Datenbank
with app.app_context():
db.create_all()
return app