aboutsummaryrefslogtreecommitdiff
path: root/src/pydrilla
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2021-11-18 20:50:11 +0100
committerWojtek Kosior <koszko@koszko.org>2021-11-18 20:50:11 +0100
commit5200c39fca2d870b07c18b395619937b54d9d116 (patch)
treea2d227150729a765059a3ce0ffdb0766c4ad6211 /src/pydrilla
parenta6721b316fca0f7a460fa2e62ed679238f97a10e (diff)
downloadhaketilo-hydrilla-5200c39fca2d870b07c18b395619937b54d9d116.tar.gz
haketilo-hydrilla-5200c39fca2d870b07c18b395619937b54d9d116.zip
implement redirections to resources
Diffstat (limited to 'src/pydrilla')
-rw-r--r--src/pydrilla/pydrilla.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/pydrilla/pydrilla.py b/src/pydrilla/pydrilla.py
index af4ff1c..b0a5974 100644
--- a/src/pydrilla/pydrilla.py
+++ b/src/pydrilla/pydrilla.py
@@ -24,7 +24,8 @@
# file's license. Although I request that you do not make use this code
# in a proprietary program, I am not going to enforce this in court.
-from flask import Flask, Blueprint, current_app, url_for, abort, request
+from flask import Flask, Blueprint, current_app, url_for, abort, request, \
+ redirect
from jinja2 import Environment, PackageLoader
import re
#from hashlib import sha256
@@ -591,6 +592,8 @@ def create_app(config_path=(here / 'config.json'), flask_config={}):
raise ValueError(_('config_key_absent_{}').format(key))
app._pydrilla_static_resource_uri = config['static_resource_uri']
+ if app._pydrilla_static_resource_uri[-1] != '/':
+ app._pydrilla_static_resource_uri += '/'
app._pydrilla_hydrilla_sources_uri = config['hydrilla_sources_uri']
app._pydrilla_werror = config.get('werror', False)
if 'hydrilla_parent' in config:
@@ -698,3 +701,12 @@ def query():
url = request.args['url']
return json.dumps(content().query(url))
+
+@bp.route('/sources/<string:identifier>/<path:path>')
+def get_file(identifier, path):
+ if identifier not in content().indexes:
+ abort(404)
+
+ new_uri = f'{current_app._pydrilla_static_resource_uri}{identifier}/{path}'
+
+ return redirect(new_uri, code=301)