2019-10-10 11:58:17 +01:00
|
|
|
from flask import Flask, render_template, redirect, session, flash, url_for
|
2022-11-29 21:13:26 +00:00
|
|
|
from google.cloud import secretmanager
|
2019-07-26 14:18:32 +01:00
|
|
|
|
2020-06-30 16:38:06 +01:00
|
|
|
import logging
|
2019-07-26 11:05:27 +01:00
|
|
|
import os
|
|
|
|
|
2019-10-19 17:14:11 +01:00
|
|
|
from music.auth import auth_blueprint
|
2019-10-20 21:07:13 +01:00
|
|
|
from music.api import api_blueprint, player_blueprint, fm_blueprint, \
|
2020-02-03 11:51:46 +00:00
|
|
|
spotfm_blueprint, spotify_blueprint, admin_blueprint, tag_blueprint
|
2023-09-07 18:03:22 +01:00
|
|
|
from music.magic_strings import COOKIE_SECRET_URI, STATIC_BUCKET
|
2019-07-29 11:44:10 +01:00
|
|
|
|
2020-06-30 16:38:06 +01:00
|
|
|
logger = logging.getLogger(__name__)
|
2022-11-29 21:13:26 +00:00
|
|
|
secret_client = secretmanager.SecretManagerServiceClient()
|
2019-07-26 11:05:27 +01:00
|
|
|
|
|
|
|
|
2020-06-30 16:38:06 +01:00
|
|
|
def create_app():
|
2021-03-23 22:26:59 +00:00
|
|
|
"""Generate and retrieve a ready-to-run flask app
|
|
|
|
|
|
|
|
Returns:
|
2022-08-07 13:27:59 +01:00
|
|
|
Flask App: Mixonomer app
|
2021-03-23 22:26:59 +00:00
|
|
|
"""
|
|
|
|
|
2020-06-30 16:38:06 +01:00
|
|
|
app = Flask(__name__, static_folder=os.path.join(os.path.dirname(__file__), '..', 'build'), template_folder="templates")
|
2019-07-26 11:05:27 +01:00
|
|
|
|
2022-11-29 21:13:26 +00:00
|
|
|
app.secret_key = secret_client.access_secret_version(request={"name": COOKIE_SECRET_URI}).payload.data.decode("UTF-8")
|
2020-06-30 16:38:06 +01:00
|
|
|
|
|
|
|
app.register_blueprint(auth_blueprint, url_prefix='/auth')
|
|
|
|
app.register_blueprint(api_blueprint, url_prefix='/api')
|
|
|
|
app.register_blueprint(player_blueprint, url_prefix='/api/player')
|
|
|
|
app.register_blueprint(fm_blueprint, url_prefix='/api/fm')
|
|
|
|
app.register_blueprint(spotfm_blueprint, url_prefix='/api/spotfm')
|
|
|
|
app.register_blueprint(spotify_blueprint, url_prefix='/api/spotify')
|
|
|
|
app.register_blueprint(admin_blueprint, url_prefix='/api/admin')
|
|
|
|
app.register_blueprint(tag_blueprint, url_prefix='/api')
|
|
|
|
|
|
|
|
@app.route('/')
|
|
|
|
def index():
|
|
|
|
|
|
|
|
if 'username' in session:
|
|
|
|
logged_in = True
|
|
|
|
return redirect(url_for('app_route'))
|
|
|
|
else:
|
|
|
|
logged_in = False
|
2019-08-03 21:35:08 +01:00
|
|
|
|
2023-09-07 18:03:22 +01:00
|
|
|
return render_template('login.html', logged_in=logged_in, bucket=STATIC_BUCKET)
|
2019-07-26 11:05:27 +01:00
|
|
|
|
2022-08-12 11:21:31 +01:00
|
|
|
@app.route('/privacy')
|
|
|
|
def privacy():
|
2023-09-07 18:03:22 +01:00
|
|
|
return render_template('privacy.html', bucket=STATIC_BUCKET)
|
2022-08-12 11:21:31 +01:00
|
|
|
|
2020-06-30 16:38:06 +01:00
|
|
|
@app.route('/app', defaults={'path': ''})
|
|
|
|
@app.route('/app/<path:path>')
|
|
|
|
def app_route(path):
|
2019-07-26 11:05:27 +01:00
|
|
|
|
2020-06-30 16:38:06 +01:00
|
|
|
if 'username' not in session:
|
|
|
|
flash('please log in')
|
|
|
|
return redirect(url_for('index'))
|
2019-07-29 11:44:10 +01:00
|
|
|
|
2023-09-07 18:03:22 +01:00
|
|
|
return render_template('app.html', bucket=STATIC_BUCKET)
|
2019-07-29 11:44:10 +01:00
|
|
|
|
2020-06-30 16:38:06 +01:00
|
|
|
return app
|
2019-07-26 11:05:27 +01:00
|
|
|
|
|
|
|
# [END gae_python37_app]
|