From 43c2144aeda21f3a87cc41a948ce43c0d2673b5c Mon Sep 17 00:00:00 2001 From: Mike Cantelon Date: Thu, 7 Sep 2023 17:25:34 -0700 Subject: [PATCH] Add METS download link to AIP page. (#46) Adds a METS download link to the AIP detail page. --- AIPscan/Reporter/templates/aip.html | 2 ++ AIPscan/Reporter/views.py | 26 +++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/AIPscan/Reporter/templates/aip.html b/AIPscan/Reporter/templates/aip.html index 0141169a..826f8e75 100644 --- a/AIPscan/Reporter/templates/aip.html +++ b/AIPscan/Reporter/templates/aip.html @@ -22,6 +22,8 @@ Originals: {{ original_file_count }}
Preservation copies: {{ preservation_file_count }} +
+ Download METS

Original files

diff --git a/AIPscan/Reporter/views.py b/AIPscan/Reporter/views.py index fd7eaf5f..dfc78301 100644 --- a/AIPscan/Reporter/views.py +++ b/AIPscan/Reporter/views.py @@ -7,7 +7,8 @@ from datetime import datetime -from flask import jsonify, make_response, render_template, request, session +from flask import jsonify, make_response, render_template, request, session, Response +import requests from AIPscan.models import ( AIP, @@ -38,6 +39,7 @@ sort_puids, ) from AIPscan.Reporter.helpers import get_premis_xml_lines +from AIPscan.Aggregator.task_helpers import get_mets_url def _get_storage_service(storage_service_id): @@ -272,3 +274,25 @@ def update_dates(): req = request.get_json() session["end_date"] = request.json.get("end_date") return make_response(jsonify(req), 200) + + +@reporter.route("/download_mets/", methods=["GET"]) +def download_mets(aip_id): + aip = AIP.query.get(aip_id) + storage_service = StorageService.query.get(aip.storage_service_id) + + api_url = { + "baseUrl": storage_service.url, + "userName": storage_service.user_name, + "apiKey": storage_service.api_key, + } + + mets_response = requests.get( + get_mets_url(api_url, aip.uuid, f"{aip.transfer_name}-{aip.uuid}/data/METS.{aip.uuid}.xml") + ) + + headers = { + "Content-Disposition": f'attachment; filename="METS-{aip.uuid}.xml"', + "Content-length": len(mets_response.content) + } + return Response(mets_response.content, mets_response.status_code, headers)