Skip to content

Commit 647a6a3

Browse files
Merge pull request #4397 from bcgov/test
psp-9316 correct stream route url, axios fileType. (#4388)
2 parents 87f50be + d525f8f commit 647a6a3

File tree

6 files changed

+16
-15
lines changed

6 files changed

+16
-15
lines changed

source/backend/api/Pims.Api.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<Project Sdk="Microsoft.NET.Sdk.Web">
33
<PropertyGroup>
44
<UserSecretsId>0ef6255f-9ea0-49ec-8c65-c172304b4926</UserSecretsId>
5-
<Version>5.5.1-88.19</Version>
6-
<Version>5.5.1-88.19</Version>
7-
<AssemblyVersion>5.5.1.88</AssemblyVersion>
5+
<Version>5.5.2-88.19</Version>
6+
<Version>5.5.2-88.19</Version>
7+
<AssemblyVersion>5.5.2.88</AssemblyVersion>
88
<GenerateDocumentationFile>true</GenerateDocumentationFile>
99
<ProjectGuid>16BC0468-78F6-4C91-87DA-7403C919E646</ProjectGuid>
1010
<TargetFramework>net8.0</TargetFramework>

source/frontend/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "frontend",
3-
"version": "5.5.1-88.19",
3+
"version": "5.5.2-88.19",
44
"private": true,
55
"dependencies": {
66
"@bcgov/bc-sans": "1.0.1",

source/frontend/src/features/documents/DocumentPreviewContainer.tsx

+3-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ApiGen_System_HttpStatusCode } from '@/models/api/generated/ApiGen_Syst
88

99
import { DocumentViewerContext } from './context/DocumentViewerContext';
1010
import { IDocumentPreviewViewProps } from './DocumentPreviewView';
11-
import { createFileDownload } from './DownloadDocumentButton';
11+
import { showFile } from './DownloadDocumentButton';
1212
import { useDocumentProvider } from './hooks/useDocumentProvider';
1313

1414
export interface LoadedPage {
@@ -32,7 +32,7 @@ export const DocumentPreviewContainer: FC<
3232
retrieveDocumentDetail,
3333
downloadDocumentFilePageImage,
3434
getDocumentFilePageList,
35-
downloadWrappedDocumentFileLatest,
35+
streamDocumentFileLatest,
3636
retrieveDocumentDetailLoading,
3737
getDocumentFilePageListLoading,
3838
} = useDocumentProvider();
@@ -166,9 +166,7 @@ export const DocumentPreviewContainer: FC<
166166
pages={documentPages}
167167
resetDocumentPreview={resetDocumentPreview}
168168
handleDownload={() => {
169-
downloadWrappedDocumentFileLatest(previewDocumentId).then(file =>
170-
createFileDownload(file),
171-
);
169+
streamDocumentFileLatest(previewDocumentId).then(response => showFile(response));
172170
}}
173171
/>
174172
</>

source/frontend/src/features/documents/DownloadDocumentButton.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export const createFileDownload = async (
9898
}
9999
};
100100

101-
const showFile = async (response: AxiosResponse<File, any>, fileName?: string) => {
101+
export const showFile = async (response: AxiosResponse<File, any>, fileName?: string) => {
102102
const groups = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/g.exec(
103103
response.headers['content-disposition'],
104104
);

source/frontend/src/features/documents/documentDetail/DocumentDetailContainer.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,8 @@ export const DocumentDetailContainer: React.FunctionComponent<
9595
const mayanMetadataResult = metadataResponse.payload?.results;
9696

9797
let mayanFileId: number | undefined = undefined;
98-
if (exists(mayanMetadataResult) && mayanMetadataResult.length > 0) {
99-
const document = mayanMetadataResult[0].document;
100-
mayanFileId = document?.file_latest?.id;
98+
if (exists(detailResponse)) {
99+
mayanFileId = detailResponse?.payload?.file_latest?.id;
101100
}
102101

103102
setDocument(document => ({

source/frontend/src/hooks/pims-api/useApiDocuments.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,14 @@ export const useApiDocuments = () => {
7777
),
7878

7979
streamDocumentFileApiCall: (mayanDocumentId: number, mayanFileId: number) =>
80-
api.get<File>(`/documents/storage/${mayanDocumentId}/stream/${mayanFileId}`),
80+
api.get<File>(`/documents/storage/${mayanDocumentId}/files/${mayanFileId}/stream`, {
81+
responseType: 'blob',
82+
}),
8183

8284
streamDocumentFileLatestApiCall: (mayanDocumentId: number) =>
83-
api.get<File>(`/documents/storage/${mayanDocumentId}/stream`),
85+
api.get<File>(`/documents/storage/${mayanDocumentId}/stream`, {
86+
responseType: 'blob',
87+
}),
8488

8589
uploadDocumentRelationshipApiCall: (
8690
relationshipType: ApiGen_CodeTypes_DocumentRelationType,

0 commit comments

Comments
 (0)