Commit 1b16e96d authored by Lukas Böhm's avatar Lukas Böhm
Browse files

zipping

parent 30839b9c
......@@ -6,7 +6,7 @@ from app import app, db
from flask import redirect, url_for, render_template, send_from_directory, current_app, abort
from app.models import Share, Attachment
from app.forms import UploadForm
from shutil import rmtree
from shutil import rmtree, make_archive
@app.route('/privacy')
......@@ -16,7 +16,7 @@ def privacy():
@app.route('/about')
def about():
return '<h1> :( </h1>'
return render_template('About.html')
@app.route('/')
......@@ -24,6 +24,12 @@ def index():
return redirect(url_for('upload'))
@app.route('/expired')
@app.errorhandler(404)
def expired(e=None):
return render_template('Expired.html')
@app.route('/upload', methods=['GET', 'POST'])
def upload():
form = UploadForm()
......@@ -48,6 +54,12 @@ def upload():
file.save(os.path.join(current_app.config['MEDIA_LOCATION'], share_id, fn))
att = Attachment(filename=fn, share_id=share_id)
db.session.add(att)
# create zip
make_archive(
os.path.join(current_app.config['MEDIA_LOCATION'], up.id),
'zip',
os.path.join(current_app.config['MEDIA_LOCATION'], up.id)
)
# wrap it up
db.session.commit()
return redirect(url_for('shared', share_id=share_id))
......@@ -92,14 +104,14 @@ def download(share_id):
@app.route('/media/<string:share_id>/<string:filename>', methods=['GET'])
def media(share_id, filename):
share = Share.query.get_or_404(share_id)
if check_expired(share):
return redirect(url_for('expired'))
else:
return send_from_directory(os.path.join(current_app.config['MEDIA_LOCATION'], share_id), filename=filename,
as_attachment=True)
check_expired(share)
return send_from_directory(os.path.join(current_app.config['MEDIA_LOCATION'], share_id), filename=filename,
as_attachment=True)
@app.route('/expired')
@app.errorhandler(404)
def expired(e=None):
return render_template('Expired.html')
@app.route('/zip/<string:share_id>')
def zip(share_id):
share = Share.query.get_or_404(share_id)
check_expired(share)
return send_from_directory(os.path.join(current_app.config['MEDIA_LOCATION']),
filename=str(share.id) + '.zip', as_attachment=True)
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