\n%s\n\n' \ - '
\n%s\n\n' \ - % (html_escape(repr(E)), html_escape(format_exc())) - environ['wsgi.errors'].write(err) - environ['wsgi.errors'].flush() - headers = [('Content-Type', 'text/html; charset=UTF-8')] - start_response('500 INTERNAL SERVER ERROR', headers, sys.exc_info()) - return [tob(err)] - - def __call__(self, environ, start_response): - """ Each instance of :class:'Bottle' is a WSGI application. """ - return self.wsgi(environ, start_response) - - def __enter__(self): - """ Use this application as default for all module-level shortcuts. """ - default_app.push(self) - return self - - def __exit__(self, exc_type, exc_value, traceback): - default_app.pop() - - def __setattr__(self, name, value): - if name in self.__dict__: - raise AttributeError("Attribute %s already defined. Plugin conflict?" % name) - self.__dict__[name] = value - - -############################################################################### -# HTTP and WSGI Tools ########################################################## -############################################################################### - - -class BaseRequest(object): - """ A wrapper for WSGI environment dictionaries that adds a lot of - convenient access methods and properties. Most of them are read-only. - - Adding new attributes to a request actually adds them to the environ - dictionary (as 'bottle.request.ext.
Sorry, the requested URL {{repr(request.url)}} - caused an error:
-{{e.body}}- %%if DEBUG and e.exception: -
{{exc}}- %%end - %%if DEBUG and e.traceback: -
{{e.traceback}}- %%end - - -%%except ImportError: - ImportError: Could not generate the error page. Please add bottle to - the import path. -%%end -""" % __name__ - -#: A thread-safe instance of :class:`LocalRequest`. If accessed from within a -#: request callback, this instance always refers to the *current* request -#: (even on a multi-threaded server). -request = LocalRequest() - -#: A thread-safe instance of :class:`LocalResponse`. It is used to change the -#: HTTP response for the *current* request. -response = LocalResponse() - -#: A thread-safe namespace. Not used by Bottle. -local = threading.local() - -# Initialize app stack (create first empty Bottle app now deferred until needed) -# BC: 0.6.4 and needed for run() -apps = app = default_app = AppStack() - -#: A virtual package that redirects import statements. -#: Example: ``import bottle.ext.sqlite`` actually imports `bottle_sqlite`. -ext = _ImportRedirect('bottle.ext' if __name__ == '__main__' else - __name__ + ".ext", 'bottle_%s').module - - -def _main(argv): # pragma: no coverage - args, parser = _cli_parse(argv) - - def _cli_error(cli_msg): - parser.print_help() - _stderr('\nError: %s\n' % cli_msg) - sys.exit(1) - - if args.version: - _stdout('Bottle %s\n' % __version__) - sys.exit(0) - if not args.app: - _cli_error("No application entry point specified.") - - sys.path.insert(0, '.') - sys.modules.setdefault('bottle', sys.modules['__main__']) - - host, port = (args.bind or 'localhost'), 8080 - if ':' in host and host.rfind(']') < host.rfind(':'): - host, port = host.rsplit(':', 1) - host = host.strip('[]') - - config = ConfigDict() - - for cfile in args.conf or []: - try: - if cfile.endswith('.json'): - with open(cfile, 'rb') as fp: - config.load_dict(json_loads(fp.read())) - else: - config.load_config(cfile) - except configparser.Error as parse_error: - _cli_error(parse_error) - except IOError: - _cli_error("Unable to read config file %r" % cfile) - except (UnicodeError, TypeError, ValueError) as error: - _cli_error("Unable to parse config file %r: %s" % (cfile, error)) - - for cval in args.param or []: - if '=' in cval: - config.update((cval.split('=', 1),)) - else: - config[cval] = True - - run(args.app, - host=host, - port=int(port), - server=args.server, - reloader=args.reload, - plugins=args.plugin, - debug=args.debug, - config=config) - - -if __name__ == '__main__': # pragma: no coverage - _main(sys.argv) diff --git a/conf.py b/conf.py new file mode 100644 index 0000000..cc64788 --- /dev/null +++ b/conf.py @@ -0,0 +1,29 @@ +BASE_HOSTS = [ + 'drop.bakatrouble.pw', + 'drop.bakatrouble.me', + '127.0.0.1.xip.io:8080', + 'localhost:8080', +] + +SORT_KEYS = { + 'name': lambda item: (not item.is_dir, item.name.lower()), + '-name': lambda item: (item.is_dir, item.name.lower()), + 'size': lambda item: (not item.is_dir, item.size), + '-size': lambda item: (item.is_dir, item.size), + 'created': lambda item: (not item.is_dir, item.created), + '-created': lambda item: (item.is_dir, item.created), +} + +ICONS = { + 'sort_asc': 'icon-up-dir', + 'sort_desc': 'icon-down-dir', + 'types': { + 'parent': 'icon-level-up', + 'dir': 'icon-folder', + 'file': 'icon-doc', + 'text': 'icon-doc-text', + 'image': 'icon-picture-outline', + 'music': 'icon-music-outline', + 'video': 'icon-video', + }, +} diff --git a/configs/nginx.conf b/configs/nginx.conf index aec4646..81a102d 100644 --- a/configs/nginx.conf +++ b/configs/nginx.conf @@ -1,65 +1,45 @@ -server { - server_name drop.bakatrouble.pw; - - location /_ { - alias /srv/apps/drop/files; - } - - location / { - include uwsgi_params; - uwsgi_pass unix:///tmp/drop.sock; - } - - listen 443 ssl; # managed by Certbot - ssl_certificate /etc/letsencrypt/live/bakatrouble.pw/fullchain.pem; # managed by Certbot - ssl_certificate_key /etc/letsencrypt/live/bakatrouble.pw/privkey.pem; # managed by Certbot - include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot - +location @drop_app { + proxy_pass unix:///tmp/drop.sock; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $remote_addr; +} - if ($scheme != "https") { - return 301 https://$host$request_uri; - } # managed by Certbot +server { + server_name ~^drop\.bakatrouble\.(pw|me)$; + root /srv/apps/drop/files; + location /~static/ { + alias /srv/apps/drop/~static; + } + location / { + try_files $uri @drop_app; + } + include /etc/nginx/letsencrypt-serv.conf; } server { - server_name ~^(?
- Name {{ !get_sort_icon('name', sort) }} + Name {{ get_sort_icon('name', sort) | safe }} | - Size {{ !get_sort_icon('size', sort) }} + Size {{ get_sort_icon('size', sort) | safe }} | - Created {{ !get_sort_icon('created', sort) }} + Created {{ get_sort_icon('created', sort) | safe }} | |||||
---|---|---|---|---|---|---|---|
- - - ../ + | + + {{ item.icon | safe }} {{ item.display_name }} | -- | - | ||||
- - - {{ item.name }}/ - - | -- | - % else: - | - - - {{ item.name }} [{{ guess_type(item.name)[0] }}] - - | -{{ format_size(item.size) }} | -{{ format_date(item.created) }} | - % end +{% if file %}{{ item.formatted_size }}{% endif %} | +{{ item.formatted_date }} |