Commit 1450993c authored by Lukas Böhm's avatar Lukas Böhm 💬
Browse files

add flask admin and fix download_limit bug

parent 23c3a613
import os
from flask import Flask
from flask_admin import Admin
from flask_admin.contrib import rediscli
from flask_admin.contrib.fileadmin import FileAdmin
from flask_sqlalchemy import SQLAlchemy
from redis import Redis
from rq import Queue
from dotenv import load_dotenv
from flask_migrate import Migrate
import flask_monitoringdashboard as dashboard
from flask_admin.contrib.sqla import ModelView
load_dotenv()
......@@ -19,20 +23,29 @@ app.config['MEDIA_LOCATION'] = os.getenv('MEDIA_LOCATION') or os.path.join(datad
app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('DATABASE_URI') or 'sqlite:///' + os.path.join(datadir, 'home.db')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['REDIS_URI'] = os.getenv('REDIS_URI') or 'redis://'
app.config['MAX_CONTENT_LENGTH'] = 1000 * 1024 * 1024 # 1000 MB
app.jinja_env.globals['len'] = len
# init extensions
db = SQLAlchemy(app)
migrate = Migrate(app, db)
admin = Admin(app, name='ChiefSend-Admin')
from app.models import *
# configure dashboard
dashboard.config.init_from(file=os.path.join(basedir, 'flask_monitoringdashboard.cfg'))
dashboard.bind(app)
# configure rq
redis = Redis.from_url(app.config['REDIS_URI'])
task_queue = Queue(connection=redis)
from app.models import *
# configure admin
admin.add_view(ModelView(Share, db.session))
admin.add_view(ModelView(Attachment, db.session))
admin.add_view(FileAdmin(app.config['MEDIA_LOCATION'], name='Files'))
admin.add_view(rediscli.RedisCli(redis))
# db.create_all()
# db.session.commit()
from app import routes
......@@ -17,7 +17,7 @@ def get_and_check_share(share_id, decrease_limit=False) -> Share:
if share.download_limit and decrease_limit:
share.download_limit -= 1
db.session.commit()
if (share.download_limit and share.download_limit <= 0) or\
if (share.download_limit is not None and share.download_limit <= 0) or\
(share.expires is not None and datetime.now() > share.expires):
que.enqueue(delete_share, share.id)
return None
......@@ -74,8 +74,6 @@ def public():
@app.route('/upload', methods=['GET', 'POST'])
def upload():
from flask import request
req = request
form = UploadForm()
if form.validate_on_submit():
# create share
......
......@@ -43,6 +43,14 @@ server {
proxy_pass http://localhost:5000;
}
location /admin {
auth_basic "Administrator Login";
auth_basic_user_file /etc/nginx/.htpasswd;
include proxy_params;
proxy_pass http://localhost:5000/admin;
}
location /static {
alias /home/chief/chiefsend/app/static;
expires 30d;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment