2012-10-13 09:29:48 +00:00
|
|
|
# coding: utf-8
|
|
|
|
|
2012-11-17 01:09:20 +00:00
|
|
|
from flask import Flask, request, session, flash, render_template, redirect, url_for
|
2013-12-29 19:30:12 +00:00
|
|
|
import db
|
2012-10-13 09:29:48 +00:00
|
|
|
|
2013-12-29 19:30:12 +00:00
|
|
|
def create_app():
|
|
|
|
app = Flask(__name__)
|
|
|
|
app.secret_key = '?9huDM\\H'
|
2012-10-13 09:29:48 +00:00
|
|
|
|
2013-12-29 19:30:12 +00:00
|
|
|
import config
|
|
|
|
if(config.get('base', 'accel-redirect')):
|
|
|
|
app.use_x_sendfile = True
|
2013-11-26 07:59:08 +00:00
|
|
|
|
2013-12-29 19:30:12 +00:00
|
|
|
if config.get('base', 'debug'):
|
|
|
|
app.debug = True
|
|
|
|
app.config['SQLALCHEMY_ECHO'] = True
|
2013-11-04 01:43:16 +00:00
|
|
|
|
2013-12-29 19:30:12 +00:00
|
|
|
if config.get('base', 'log_file'):
|
|
|
|
import logging
|
|
|
|
from logging.handlers import TimedRotatingFileHandler
|
|
|
|
handler = TimedRotatingFileHandler(config.get('base', 'log_file'), when = 'midnight', encoding = 'UTF-8')
|
|
|
|
handler.setLevel(logging.DEBUG)
|
|
|
|
app.logger.addHandler(handler)
|
2012-11-21 12:09:31 +00:00
|
|
|
|
2013-12-29 19:30:12 +00:00
|
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = config.get('base', 'database_uri')
|
2013-12-15 00:50:12 +00:00
|
|
|
|
2013-12-29 19:30:12 +00:00
|
|
|
db.database.init_app(app)
|
|
|
|
|
|
|
|
return app
|
|
|
|
|
|
|
|
app = create_app()
|
2013-12-15 00:50:12 +00:00
|
|
|
|
|
|
|
with app.app_context():
|
2013-12-29 19:30:12 +00:00
|
|
|
db.init_db()
|
2013-12-15 00:50:12 +00:00
|
|
|
|
2013-09-05 16:40:43 +00:00
|
|
|
from managers.user import UserManager
|
2012-10-13 09:29:48 +00:00
|
|
|
|
2012-11-16 15:59:09 +00:00
|
|
|
@app.before_request
|
2013-09-23 09:46:06 +00:00
|
|
|
def login_check():
|
2012-11-16 15:59:09 +00:00
|
|
|
if request.path.startswith('/rest/'):
|
|
|
|
return
|
|
|
|
|
2013-09-23 09:46:06 +00:00
|
|
|
if request.endpoint != 'login':
|
2012-11-17 17:09:35 +00:00
|
|
|
should_login = False
|
|
|
|
if not session.get('userid'):
|
|
|
|
should_login = True
|
|
|
|
elif UserManager.get(session.get('userid'))[0] != UserManager.SUCCESS:
|
|
|
|
session.clear()
|
|
|
|
should_login = True
|
|
|
|
|
|
|
|
if should_login:
|
|
|
|
flash('Please login')
|
2012-11-21 11:47:08 +00:00
|
|
|
return redirect(url_for('login', returnUrl = request.script_root + request.url[len(request.url_root)-1:]))
|
2012-11-17 01:09:20 +00:00
|
|
|
|
2013-06-27 17:41:06 +00:00
|
|
|
@app.template_filter('str')
|
|
|
|
def to_string(obj):
|
|
|
|
return str(obj)
|
|
|
|
|
2012-10-13 09:29:48 +00:00
|
|
|
@app.route('/')
|
|
|
|
def index():
|
2012-11-17 20:36:28 +00:00
|
|
|
stats = {
|
|
|
|
'artists': db.Artist.query.count(),
|
|
|
|
'albums': db.Album.query.count(),
|
|
|
|
'tracks': db.Track.query.count()
|
|
|
|
}
|
|
|
|
return render_template('home.html', stats = stats, admin = UserManager.get(session.get('userid'))[1].admin)
|
2012-10-13 10:29:37 +00:00
|
|
|
|
2012-11-16 15:59:09 +00:00
|
|
|
import user
|
2012-11-17 17:30:30 +00:00
|
|
|
import folder
|
2013-06-27 17:41:06 +00:00
|
|
|
import playlist
|
2012-11-16 15:59:09 +00:00
|
|
|
|
2012-10-13 09:29:48 +00:00
|
|
|
import api.system
|
|
|
|
import api.browse
|
2012-10-14 17:04:39 +00:00
|
|
|
import api.user
|
2012-10-20 16:05:37 +00:00
|
|
|
import api.albums_songs
|
2012-10-20 18:05:39 +00:00
|
|
|
import api.media
|
2013-06-12 19:29:42 +00:00
|
|
|
import api.annotation
|
2013-06-14 16:46:01 +00:00
|
|
|
import api.chat
|
2013-06-24 16:43:50 +00:00
|
|
|
import api.search
|
2013-06-25 20:07:49 +00:00
|
|
|
import api.playlists
|
2012-10-13 09:29:48 +00:00
|
|
|
|