Commit 76ac7dd1 authored by Lukas Böhm's avatar Lukas Böhm 💬
Browse files

ready to deploy

parent 91782440
......@@ -16,6 +16,8 @@ app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['MAX_CONTENT_LENGTH'] = 5 * 1024 * 1024 # 5 MB
app.config['REDIS_URI'] = os.getenv('REDIS_URI') or 'redis://'
app.jinja_env.globals['len'] = len
db = SQLAlchemy(app)
redis = Redis.from_url(app.config['REDIS_URI'])
......
......@@ -20,7 +20,7 @@ class Share(db.Model):
def __repr__(self):
return f'<Share {self.id}>'
def __init__(self, name, timer, download_limit, is_public=False, password=None):
def __init__(self, name, expires, download_limit, is_public=False, password=None):
# create id
import uuid
share_id = str(uuid.uuid4())
......@@ -29,7 +29,7 @@ class Share(db.Model):
# set attributes
self.id = share_id
self.name = name
self.expires = datetime.now(timezone.utc) + timedelta(minutes=float(timer)) if timer > 0 else None
self.expires = expires
self.download_limit = download_limit if download_limit > 0 else 100000000
self.is_public = is_public
self.password = generate_password_hash(password) if password else None
......
import os
from datetime import timezone, datetime
from datetime import timezone, datetime, timedelta
from werkzeug.exceptions import HTTPException
from werkzeug.security import generate_password_hash, check_password_hash
from werkzeug.security import check_password_hash
from app import app, db
from flask import redirect, url_for, render_template, send_from_directory, current_app, session, flash
from app.models import Share, Attachment
......@@ -74,7 +74,8 @@ def upload():
if form.validate_on_submit():
# create share
share = Share(name=str(form.name.data),
timer=form.timer.data,
expires=datetime.now() + timedelta(minutes=form.timer.data)
if form.timer.data > 0 else None,
download_limit=form.download_limit.data,
is_public=form.is_public.data,
password=form.password.data
......@@ -92,7 +93,7 @@ def upload():
)
# put timer into scheduler queue
if share.expires:
que.enqueue_at(datetime=share.expires, f=delete_share, args=[share.id])
que.enqueue_in(time_delta=timedelta(minutes=form.timer.data), func=delete_share, args=[share.id])
# wrap it up
db.session.commit()
return render_template('Shared.html', share=share, url=url_for('download', share_id=share.id))
......@@ -125,8 +126,8 @@ def media(share_id, filename):
filename=filename, as_attachment=True)
@app.route('/zip/<string:share_id>')
def zip(share_id):
@app.route('/d/<string:share_id>zip')
def zip_attachments(share_id):
share = get_and_check_share(share_id)
if share is None: return redirect(url_for('expired'))
if share.password:
......@@ -151,6 +152,6 @@ def share_auth(share_id):
for field, error in form.errors.items():
from markupsafe import Markup
flash(Markup(f'<b>{field}:</b> {error}'), category='danger')
flash('Zugriff verweigert.', category='danger')
flash('Zugriff verweigert.', category='danger')
return render_template('DownloadAuth.html', form=form)
......@@ -30,7 +30,7 @@
</ul>
<div class="input-group">
<a href="{{ url_for('zip', share_id=up.id) }}" download class="btn btn-block btn-outline-primary">
<a href="{{ url_for('zip_attachments', share_id=up.id) }}" download class="btn btn-block btn-outline-primary">
Dateien gepackt herunterladen
</a>
</div>
......
......@@ -13,18 +13,21 @@
<input type="text" class="form-control" placeholder="Suche ..."/>
</div> #}
{% for row in shares|batch(3, '') %}
{% for row in shares|batch(3) %}
<div class="row">
{% for item in row %}
<div class="col md-4 my-4">
<div class="border rounded p-4 h-100">
<h3 class="mb-4 font-weight-normal">{{ item.name }}</h3>
<p class="lead">
ANZAHL Dateien (0 MB)
{{ len(item.files) }} Dateien
</p>
<p class="card-text">
<small class="text-muted">
Downloads verbleibend: {{ item.download_limit }},
</small>
<br>
<small class="text-muted">
Verfügbar bis: {{ item.expires }}
</small>
</p>
......
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