Add API alias for dataset display

Since the `history_id` is really only used for consistency with other history contents routes, we can make it optional and create a route alias for the datasets API
This commit is contained in:
davelopez
2022-04-06 18:44:00 +02:00
parent 4c858252af
commit 4cb3300efd
2 changed files with 12 additions and 8 deletions
+12 -4
View File
@@ -194,10 +194,15 @@ class FastAPIDatasets:
):
return self.service.extra_files(trans, history_content_id)
@router.get(
"/api/datasets/{history_content_id}/display",
summary="Displays (preview) or downloads dataset content.",
response_class=StreamingResponse,
)
@router.get(
"/api/histories/{history_id}/contents/{history_content_id}/display",
name="history_contents_display",
summary="Displays dataset (preview) content.",
summary="Displays (preview) or downloads dataset content.",
tags=["histories"],
response_class=StreamingResponse,
)
@@ -205,7 +210,10 @@ class FastAPIDatasets:
self,
request: Request,
trans=DependsOnTrans,
history_id: EncodedDatabaseIdField = HistoryIDPathParam,
history_id: Optional[EncodedDatabaseIdField] = Query(
default=None,
description="The encoded database identifier of the History.",
),
history_content_id: EncodedDatabaseIdField = DatasetIDPathParam,
preview: bool = Query(
default=False,
@@ -234,10 +242,10 @@ class FastAPIDatasets:
),
),
):
"""Streams the preview contents of a dataset to be displayed in a browser."""
"""Streams the dataset for download or the contents preview to be displayed in a browser."""
extra_params = get_query_parameters_from_request_excluding(request, {"preview", "filename", "to_ext", "raw"})
display_data, headers = self.service.display(
trans, history_content_id, history_id, preview, filename, to_ext, raw, **extra_params
trans, history_content_id, preview, filename, to_ext, raw, **extra_params
)
return StreamingResponse(display_data, headers=headers)
@@ -411,7 +411,6 @@ class DatasetsService(ServiceBase, UsesVisualizationMixin):
self,
trans: ProvidesHistoryContext,
history_content_id: EncodedDatabaseIdField,
history_id: EncodedDatabaseIdField,
preview: bool = False,
filename: Optional[str] = None,
to_ext: Optional[str] = None,
@@ -443,9 +442,6 @@ class DatasetsService(ServiceBase, UsesVisualizationMixin):
except galaxy_exceptions.MessageException:
raise
except Exception as e:
log.exception(
"Server error getting display data for dataset (%s) from history (%s)", history_content_id, history_id
)
raise galaxy_exceptions.InternalServerError(f"Could not get display data for dataset: {util.unicodify(e)}")
return rval, headers