Skip to content

Commit 0a4ec69

Browse files
authored
Merge pull request #60 from djedi/export-fix
Fix export permission error in docker
2 parents c322f27 + 8919f61 commit 0a4ec69

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

app/routes.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import os
12
import zipfile
3+
24
from app import app, db, argon2
35
from app.models import User, Note, Meta, aes_encrypt, aes_encrypt_old
46
from flask import render_template, request, jsonify, abort, send_file
@@ -406,15 +408,19 @@ def export():
406408
if not user:
407409
abort(400)
408410

409-
zf = zipfile.ZipFile('export.zip', mode='w')
411+
zip_location = app.config['EXPORT_FILE']
412+
zf = zipfile.ZipFile(zip_location, mode='w')
413+
os.chmod(zip_location, 0o755)
410414
notes = user.notes
411415
for note in notes:
412416
ret_note = note.serialize
413417
zf.writestr(ret_note['title'] + '.md', ret_note['data'], zipfile.ZIP_DEFLATED)
414418
print(ret_note)
415419
zf.close()
416420

417-
return send_file('../export.zip', as_attachment=True)
421+
rval = send_file(zip_location, as_attachment=True)
422+
os.remove(zip_location)
423+
return rval
418424

419425

420426
@app.route('/', defaults={'path': ''})

config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ class Config(object):
99
PREVENT_SIGNUPS = os.environ.get('PREVENT_SIGNUPS', False)
1010
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URI') or 'sqlite:///' + os.path.join(basedir + '/config', 'app.db')
1111
SQLALCHEMY_TRACK_MODIFICATIONS = False
12-
JWT_ACCESS_TOKEN_EXPIRES = datetime.timedelta(days=7)
12+
JWT_ACCESS_TOKEN_EXPIRES = datetime.timedelta(days=7)
13+
EXPORT_FILE = os.path.join(basedir, 'config', 'export.zip')

0 commit comments

Comments
 (0)