diff options
author | VG <vg@devys.org> | 2017-09-18 09:51:25 +0200 |
---|---|---|
committer | VG <vg@devys.org> | 2017-09-18 09:51:25 +0200 |
commit | d1b0d0191962841c68100fe93a631b5936cb7f95 (patch) | |
tree | 1ff78e1f79a35816044f6193fe00457f49301a35 | |
parent | 0bbcda16e06a34376aa0800a92f8201c90f53692 (diff) | |
download | shareit-d1b0d0191962841c68100fe93a631b5936cb7f95.tar.gz shareit-d1b0d0191962841c68100fe93a631b5936cb7f95.tar.bz2 shareit-d1b0d0191962841c68100fe93a631b5936cb7f95.zip |
Simplify dir creation and add top spaces
-rwxr-xr-x | shareit/shareit.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/shareit/shareit.py b/shareit/shareit.py index c9aec98..d8d0525 100755 --- a/shareit/shareit.py +++ b/shareit/shareit.py @@ -2,27 +2,32 @@ import bottle import hashlib -import json import io -import os import jinja2 +import json +import os from pathlib import Path + DEV_FILES_DIR = '/tmp/files' PROD_FILES_DIR = '/files' FILES_DIR = PROD_FILES_DIR + templates = jinja2.Environment( loader=jinja2.FileSystemLoader('templates')) + #app = application = bottle.Bottle() # with line above, routing decorators then needs to be @app.route(...) # app is optional, but smaller. If you use default_app instead and call # bottle.route instead of application.route, app is not needed application = bottle.default_app() # defines application used for wsgi mode + CHUNK_SIZE = 1024*1024 + valid_languages = ['en', 'fr'] def get_language(): headlang = bottle.request.headers.get('accept-language', 'en')[:2].lower() @@ -30,12 +35,14 @@ def get_language(): return headlang return valid_languages[0] + @bottle.route('/') @bottle.route('/propose_upload/') def propose_upload(): lang = get_language() return templates.get_template('propose_upload.html').render(lang=lang) + @bottle.route('/upload/', method='POST') def upload_route(): lang = get_language() @@ -61,6 +68,7 @@ def upload_route(): return templates.get_template('upload.html').render( link=link, digest=digest, lang=lang) + @bottle.route('/download/<filename:re:[a-f0-9]{32}>') def download(filename): server_filename = Path(FILES_DIR, filename).as_posix() @@ -72,21 +80,21 @@ def download(filename): download=raw_filename, mimetype='binary') abort(404, 'Requested file might have expired') + @bottle.route('/favicon.ico') def favicon(): return bottle.static_file('favicon.ico', root='./static/') + @bottle.route('/robot.txt') def robot(): return bottle.static_file('robot.txt', root='./static/') + if __name__ == '__main__': print('I: Starting shareit application as development server') FILES_DIR = DEV_FILES_DIR - try: - os.mkdir(FILES_DIR) - except FileExistsError: - pass + os.makedirs(FILES_DIR, mode=0755) bottle.run(host='0.0.0.0', port=8080, debug=True) else: print('I: Starting shareit application as module or wsgi application') |