Files
SanctuaryCommander/sc_webserver.py
T

47 lines
1.7 KiB
Python

from flask import Flask, g, jsonify, render_template, request
from blueprints.home.home import home_bp
from blueprints.upload_photo.upload_photo import upload_photo_bp
from blueprints.upload_video.upload_video import upload_video_bp
from blueprints.configure_stream.configure_stream import configure_stream_bp
from blueprints.youtube_download.youtube_download import youtube_download_bp
from blueprints.media_library.media_library import media_library_bp
import os
import json
import sqlite3
with open("config.json", 'r') as config_file:
config_json = json.loads(config_file.read())
if not os.path.exists(config_json["upload_location"]):
os.makedirs(config_json["upload_location"])
app = Flask(__name__)
app.config["MAX_CONTENT_LENGTH"] = 3 * (1024 ** 3)
app.config["config"] = config_json
app.config["CONFIG_DIRECTORY"] = os.path.dirname(os.path.abspath("config.json"))
app.register_blueprint(home_bp)
app.register_blueprint(upload_photo_bp)
app.register_blueprint(upload_video_bp)
app.register_blueprint(configure_stream_bp)
app.register_blueprint(youtube_download_bp)
app.register_blueprint(media_library_bp)
@app.errorhandler(sqlite3.Error)
def database_error(error):
app.logger.exception('Database request failed')
message = 'The database is unavailable. Please try again or contact the administrator.'
if request.path.startswith('/upload/') or request.path == '/media/status':
return jsonify(status='FAILED', error=message), 503
return render_template('database_error.html', message=message), 503
@app.teardown_appcontext
def close_database(error):
db = g.pop('_database', None)
if db is not None:
db.close()
if __name__ == '__main__':
app.run(debug=True, host="0.0.0.0", port=2025)