| 123456789101112131415161718192021222324 |
- import os
- from werkzeug.utils import secure_filename
- from .tools import gen_alphanum
- UPLOAD_FOLDER = 'app/static/incoming'
- REPO_FOLDER = 'app/static/repository'
- PROFILEPIC_FOLDER = 'app/static/uploads'
- ALLOWED_EXT = {'png', 'jpg', 'jpeg'}
- # Checks file for allowed extension
- def allowed_file(filename):
- return '.' in filename and \
- filename.rsplit('.', 1)[1].lower() in ALLOWED_EXT
- # And sanitizes
- def sanitize(filename):
- sfn = secure_filename(filename) # strips any slashes
- ssfn, fx = os.path.splitext(sfn) # ensures that internal filenames are not
- rsfn = gen_alphanum() # known to users.
- ffn = f'{rsfn}{fx}'
- return ffn
|