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

clean up

parent 00d86df6
......@@ -22,3 +22,4 @@ errlog.txt
# montoring dashboard
flask_monitoringdashboard*
.htpasswd
chiefsend_testing.conf
......@@ -15,7 +15,7 @@ class Share(db.Model):
password = db.Column('Password', db.String, nullable=True)
is_zipped = db.Column('Zipped', db.Boolean, nullable=False, default=False)
files = db.relationship('Attachment', backref='share')
files = db.relationship('Attachment', cascade="all,delete", backref='share')
def __repr__(self):
return f'<Share {self.id}>'
......
......@@ -3,13 +3,16 @@ from datetime import timezone, datetime, timedelta
from werkzeug.exceptions import HTTPException
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 flask import redirect, url_for, render_template, send_from_directory, current_app, session, flash, request
from app.models import Share, Attachment
from app.forms import UploadForm, AuthForm
from app import task_queue as que
from shutil import make_archive, rmtree
#####################################################################
########################### FUNCTIONS ###############################
#####################################################################
def get_and_check_share(share_id, decrease_limit=False) -> Share:
share = Share.query.get(share_id)
if share is None:
......@@ -17,7 +20,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 is not None 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
......@@ -25,7 +28,6 @@ def get_and_check_share(share_id, decrease_limit=False) -> Share:
def delete_share(share_id):
print(f'delete share: {share_id}')
with app.app_context():
share = Share.query.get_or_404(str(share_id))
# delete files
......@@ -35,12 +37,15 @@ def delete_share(share_id):
except OSError as e:
print("Error: %s - %s." % (e.filename, e.strerror))
# delete from database
for att in share.files:
db.session.delete(att)
db.session.delete(share)
db.session.commit()
#####################################################################
############################ ROUTES #################################
#####################################################################
@app.route('/privacy')
def privacy():
return render_template('Privacy.html')
......@@ -90,7 +95,8 @@ def upload():
for file in form.files.data:
db.session.add(Attachment(share_id=share.id, file=file))
# create zip
if len(share.files) >= 3 or (len(share.files) >= 2 and sum([att.filesize for att in share.files]) > (25*1000*1000)):
if len(share.files) >= 3 or (
len(share.files) >= 2 and sum([att.filesize for att in share.files]) > (25 * 1000 * 1000)):
share.is_zipped = True
make_archive(
os.path.join(current_app.config['MEDIA_LOCATION'], share.id),
......
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