From bda3665bc79af76efdec449eb17bd14104d44b44 Mon Sep 17 00:00:00 2001 From: Yash Lamba Date: Fri, 8 Sep 2023 10:54:14 +0200 Subject: [PATCH] redirection: add legacy formats -> media-files URL redirect (#485) * redirector: add legacy formats -> media-files URL redirect --------- Co-authored-by: Yash Lamba --- site/zenodo_rdm/config.py | 5 +++++ site/zenodo_rdm/redirector.py | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/site/zenodo_rdm/config.py b/site/zenodo_rdm/config.py index fa6c4664..31132b75 100644 --- a/site/zenodo_rdm/config.py +++ b/site/zenodo_rdm/config.py @@ -18,6 +18,7 @@ record_view_function, redirect_deposit_new_view, redirect_deposit_own_view, + redirect_formats_to_media_files_view, redirect_record_file_preview_view, redirect_record_thumbnail_view, search_view_function, @@ -300,6 +301,10 @@ "source": "/record//thumb", "target": redirect_record_thumbnail_view, }, + "redirect_formats_to_media_files": { + "source": "/record//formats", + "target": redirect_formats_to_media_files_view, + }, } EXPORT_REDIRECTS = { diff --git a/site/zenodo_rdm/redirector.py b/site/zenodo_rdm/redirector.py index 6bdc3cd9..2d65cd96 100644 --- a/site/zenodo_rdm/redirector.py +++ b/site/zenodo_rdm/redirector.py @@ -250,3 +250,20 @@ def redirect_record_thumbnail_view(): - /record//thumb -> /records//thumb """ return url_for("invenio_app_rdm_records.record_thumbnail", **request.view_args) + + +def redirect_formats_to_media_files_view(): + """Redirect formats to media files URLs. + + The following routes are redirected as follows: + - /record//formats?mimetype= -> GET /records//media-files/ + + :return: url for the view 'invenio_app_rdm_records.record_media_file_download' + :rtype: str + """ + values = request.view_args + filename = request.args.get("mimetype", None) + values["filename"] = filename + + target = url_for("invenio_app_rdm_records.record_media_file_download", **values) + return target