From 5200c39fca2d870b07c18b395619937b54d9d116 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Thu, 18 Nov 2021 20:50:11 +0100 Subject: implement redirections to resources --- src/pydrilla/pydrilla.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/pydrilla') 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//') +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) -- cgit v1.2.3