Commit cd6ad9a4 authored by Lukas Bhm's avatar Lukas Bhm
Browse files

timer with delete working

parent cf05fbad
- Upload per QR-Code teilen
- Passwort protection
- Drag n Drop upload
import os
from flask import current_app
from app import db, app
from app import db
class Share(db.Model):
__tablename__ = 'Share'
id = db.Column('ID', db.String(64), primary_key=True, unique=True)
name = db.Column('Name', db.String(32), nullable=True)
expires = db.Column('Expires', db.DATETIME, nullable=False)
download_limit = db.Column('DownloadLimit', db.INTEGER, nullable=False)
expires = db.Column('Expires', db.DateTime, nullable=False)
download_limit = db.Column('DownloadLimit', db.Integer, nullable=False)
files = db.relationship('Attachment', backref='share')
def __repr__(self):
......
......@@ -11,7 +11,7 @@ from app import task_queue as que
def delete_share(share_id):
with app.app_context():
share = Share.query.get_or_404(share_id)
share = Share.query.get_or_404(str(share_id))
# delete files
try:
from shutil import rmtree
......@@ -64,9 +64,9 @@ def upload():
if form.validate_on_submit():
# create share
share = Share(name=form.name.data,
share = Share(name=str(form.name.data),
expires=datetime.now() + timedelta(minutes=float(form.timer.data)),
download_limit=form.download_limit.data
download_limit=int(form.download_limit.data)
)
db.session.add(share)
db.session.flush()
......@@ -76,13 +76,15 @@ def upload():
# create zip
make_archive(
os.path.join(current_app.config['MEDIA_LOCATION'], share.id),
'zip',
'zip', # TODO MORE FILE FORMATS LIKE .tar and .tar.gz
os.path.join(current_app.config['MEDIA_LOCATION'], share.id)
)
# put timer into scheduler queue
# que.enqueue_at(share.expires, Share.delete, share)
if form.timer.data != 990000000:
que.enqueue_at(share.expires, delete_share, share.id)
# wrap it up
db.session.commit()
# TODO catch HTTP errors or else there will be HTML stuff in the URL
return url_for('shared', share_id=share.id)
return render_template('Upload.html', form=form)
......@@ -92,11 +94,9 @@ def get_and_check_share(share_id):
share = Share.query.get(share_id)
if share is None:
return None
if share.download_limit <= 0:
que.enqueue(delete_share, share.id)
return None
return share
......
Supports Markdown
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