From cfe43bdb2d26e09ca11a1803b42656e1d05226e2 Mon Sep 17 00:00:00 2001 From: devinleighsmith <41091511+devinleighsmith@users.noreply.github.com> Date: Thu, 10 Oct 2024 08:40:41 -0700 Subject: [PATCH] psp-9316 correct stream route url, axios fileType. (#4388) --- source/backend/api/Pims.Api.csproj | 6 +++--- source/frontend/package.json | 2 +- .../src/features/documents/DocumentPreviewContainer.tsx | 8 +++----- .../src/features/documents/DownloadDocumentButton.tsx | 2 +- .../documents/documentDetail/DocumentDetailContainer.tsx | 5 ++--- source/frontend/src/hooks/pims-api/useApiDocuments.ts | 8 ++++++-- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/source/backend/api/Pims.Api.csproj b/source/backend/api/Pims.Api.csproj index 2f14335064..4d366cc541 100644 --- a/source/backend/api/Pims.Api.csproj +++ b/source/backend/api/Pims.Api.csproj @@ -2,9 +2,9 @@ 0ef6255f-9ea0-49ec-8c65-c172304b4926 - 5.5.1-88.19 - 5.5.1-88.19 - 5.5.1.88 + 5.5.2-88.19 + 5.5.2-88.19 + 5.5.2.88 true 16BC0468-78F6-4C91-87DA-7403C919E646 net8.0 diff --git a/source/frontend/package.json b/source/frontend/package.json index dee54183d9..ada85646cc 100644 --- a/source/frontend/package.json +++ b/source/frontend/package.json @@ -1,6 +1,6 @@ { "name": "frontend", - "version": "5.5.1-88.19", + "version": "5.5.2-88.19", "private": true, "dependencies": { "@bcgov/bc-sans": "1.0.1", diff --git a/source/frontend/src/features/documents/DocumentPreviewContainer.tsx b/source/frontend/src/features/documents/DocumentPreviewContainer.tsx index 46eb6843d6..3257f92142 100644 --- a/source/frontend/src/features/documents/DocumentPreviewContainer.tsx +++ b/source/frontend/src/features/documents/DocumentPreviewContainer.tsx @@ -8,7 +8,7 @@ import { ApiGen_System_HttpStatusCode } from '@/models/api/generated/ApiGen_Syst import { DocumentViewerContext } from './context/DocumentViewerContext'; import { IDocumentPreviewViewProps } from './DocumentPreviewView'; -import { createFileDownload } from './DownloadDocumentButton'; +import { showFile } from './DownloadDocumentButton'; import { useDocumentProvider } from './hooks/useDocumentProvider'; export interface LoadedPage { @@ -32,7 +32,7 @@ export const DocumentPreviewContainer: FC< retrieveDocumentDetail, downloadDocumentFilePageImage, getDocumentFilePageList, - downloadWrappedDocumentFileLatest, + streamDocumentFileLatest, retrieveDocumentDetailLoading, getDocumentFilePageListLoading, } = useDocumentProvider(); @@ -166,9 +166,7 @@ export const DocumentPreviewContainer: FC< pages={documentPages} resetDocumentPreview={resetDocumentPreview} handleDownload={() => { - downloadWrappedDocumentFileLatest(previewDocumentId).then(file => - createFileDownload(file), - ); + streamDocumentFileLatest(previewDocumentId).then(response => showFile(response)); }} /> diff --git a/source/frontend/src/features/documents/DownloadDocumentButton.tsx b/source/frontend/src/features/documents/DownloadDocumentButton.tsx index 0f0ac44d08..aecbc41d75 100644 --- a/source/frontend/src/features/documents/DownloadDocumentButton.tsx +++ b/source/frontend/src/features/documents/DownloadDocumentButton.tsx @@ -98,7 +98,7 @@ export const createFileDownload = async ( } }; -const showFile = async (response: AxiosResponse, fileName?: string) => { +export const showFile = async (response: AxiosResponse, fileName?: string) => { const groups = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/g.exec( response.headers['content-disposition'], ); diff --git a/source/frontend/src/features/documents/documentDetail/DocumentDetailContainer.tsx b/source/frontend/src/features/documents/documentDetail/DocumentDetailContainer.tsx index ce33983965..1c234b60d0 100644 --- a/source/frontend/src/features/documents/documentDetail/DocumentDetailContainer.tsx +++ b/source/frontend/src/features/documents/documentDetail/DocumentDetailContainer.tsx @@ -95,9 +95,8 @@ export const DocumentDetailContainer: React.FunctionComponent< const mayanMetadataResult = metadataResponse.payload?.results; let mayanFileId: number | undefined = undefined; - if (exists(mayanMetadataResult) && mayanMetadataResult.length > 0) { - const document = mayanMetadataResult[0].document; - mayanFileId = document?.file_latest?.id; + if (exists(detailResponse)) { + mayanFileId = detailResponse?.payload?.file_latest?.id; } setDocument(document => ({ diff --git a/source/frontend/src/hooks/pims-api/useApiDocuments.ts b/source/frontend/src/hooks/pims-api/useApiDocuments.ts index 43038a2330..150b148365 100644 --- a/source/frontend/src/hooks/pims-api/useApiDocuments.ts +++ b/source/frontend/src/hooks/pims-api/useApiDocuments.ts @@ -77,10 +77,14 @@ export const useApiDocuments = () => { ), streamDocumentFileApiCall: (mayanDocumentId: number, mayanFileId: number) => - api.get(`/documents/storage/${mayanDocumentId}/stream/${mayanFileId}`), + api.get(`/documents/storage/${mayanDocumentId}/files/${mayanFileId}/stream`, { + responseType: 'blob', + }), streamDocumentFileLatestApiCall: (mayanDocumentId: number) => - api.get(`/documents/storage/${mayanDocumentId}/stream`), + api.get(`/documents/storage/${mayanDocumentId}/stream`, { + responseType: 'blob', + }), uploadDocumentRelationshipApiCall: ( relationshipType: ApiGen_CodeTypes_DocumentRelationType,