Skip to content

Commit

Permalink
redirection: add legacy formats -> media-files URL redirect (#485)
Browse files Browse the repository at this point in the history
* redirector: add legacy formats -> media-files URL redirect

---------

Co-authored-by: Yash Lamba <[email protected]>
  • Loading branch information
yashlamba and Yash Lamba authored Sep 8, 2023
1 parent 9937eb9 commit bda3665
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions site/zenodo_rdm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -300,6 +301,10 @@
"source": "/record/<pid_value>/thumb<size>",
"target": redirect_record_thumbnail_view,
},
"redirect_formats_to_media_files": {
"source": "/record/<pid_value>/formats",
"target": redirect_formats_to_media_files_view,
},
}

EXPORT_REDIRECTS = {
Expand Down
17 changes: 17 additions & 0 deletions site/zenodo_rdm/redirector.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,20 @@ def redirect_record_thumbnail_view():
- /record/<pid_value>/thumb<size> -> /records/<pid_value>/thumb<size>
"""
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/<pid_value>/formats?mimetype=<filename> -> GET /records/<pid_value>/media-files/<filename>
: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

0 comments on commit bda3665

Please sign in to comment.