Skip to content

Commit 595c3c9

Browse files
authored
Merge pull request #8171 from opencrvs/revert-8170-auto-pr-release-v1.6.2-8010-80
Revert "🍒 Merge changes from PR #8010 to release-v1.6.2"
2 parents 8c8b46b + 46b93f9 commit 595c3c9

File tree

5 files changed

+70
-40
lines changed

5 files changed

+70
-40
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
*
6+
* OpenCRVS is also distributed under the terms of the Civil Registration
7+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
8+
*
9+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
10+
*/
11+
import fetch from '@gateway/fetch'
12+
import { DOCUMENTS_URL } from '@gateway/constants'
13+
import { internal } from '@hapi/boom'
14+
import { logger, IAuthHeader } from '@opencrvs/commons'
15+
16+
export async function uploadSvg(fileData: string, authHeader: IAuthHeader) {
17+
const url = new URL('upload-svg', DOCUMENTS_URL).toString()
18+
const res = await fetch(url, {
19+
method: 'POST',
20+
headers: {
21+
...authHeader,
22+
'Content-Type': 'image/svg+xml'
23+
},
24+
body: Buffer.from(fileData)
25+
})
26+
if (!res.ok) {
27+
logger.error(await res.json())
28+
throw internal()
29+
}
30+
return (await res.json()).refUrl
31+
}

packages/workflow/src/documents.ts

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,36 @@ import {
1818
} from '@opencrvs/commons/types'
1919
import { CertifyInput, IssueInput } from './records/validations'
2020

21-
export async function uploadFileToMinio(
22-
fileData: string,
23-
authHeader: IAuthHeader
24-
): Promise<string> {
25-
const suffix = '/upload'
26-
const request = {
27-
method: 'POST',
21+
const fetchDocuments = async <T = any>(
22+
suffix: string,
23+
authHeader: IAuthHeader,
24+
method = 'GET',
25+
body: string | undefined = undefined
26+
): Promise<T> => {
27+
const result = await fetch(`${DOCUMENTS_URL}${suffix}`, {
28+
method,
2829
headers: {
2930
...authHeader,
3031
'Content-Type': 'application/json'
3132
},
32-
body: JSON.stringify({ fileData: fileData })
33-
}
34-
const result = await fetch(`${DOCUMENTS_URL}${suffix}`, request)
33+
body
34+
})
3535
const res = await result.json()
36-
return res.refUrl
36+
return res
3737
}
3838

39-
async function uploadSVGToMinio(
39+
export async function uploadBase64ToMinio(
4040
fileData: string,
4141
authHeader: IAuthHeader
4242
): Promise<string> {
43-
const suffix = '/upload-svg'
44-
const request = {
45-
method: 'POST',
46-
headers: {
47-
...authHeader,
48-
'Content-Type': 'image/svg+xml'
49-
},
50-
body: fileData
51-
}
52-
const result = await fetch(`${DOCUMENTS_URL}${suffix}`, request)
53-
const res = await result.json()
54-
return res.refUrl
43+
const docUploadResponse = await fetchDocuments(
44+
'/upload',
45+
authHeader,
46+
'POST',
47+
JSON.stringify({ fileData: fileData })
48+
)
49+
50+
return docUploadResponse.refUrl
5551
}
5652

5753
export async function uploadCertificateAttachmentsToDocumentsStore<
@@ -62,11 +58,11 @@ export async function uploadCertificateAttachmentsToDocumentsStore<
6258
certificateDetails.collector.affidavit
6359
) {
6460
for (const affidavit of certificateDetails.collector.affidavit) {
65-
affidavit.data = await uploadFileToMinio(affidavit.data, authHeader)
61+
affidavit.data = await uploadBase64ToMinio(affidavit.data, authHeader)
6662
}
6763
}
6864
if ('data' in certificateDetails) {
69-
certificateDetails.data = await uploadSVGToMinio(
65+
certificateDetails.data = await uploadBase64ToMinio(
7066
certificateDetails.data,
7167
authHeader
7268
)
@@ -90,7 +86,7 @@ function uploadOrNormaliseSignatureData(
9086
authHeader: IAuthHeader
9187
) {
9288
if (isBase64FileString(signature)) {
93-
return uploadFileToMinio(signature, authHeader)
89+
return uploadBase64ToMinio(signature, authHeader)
9490
}
9591

9692
if (isPresignedUrl(signature)) {
@@ -142,7 +138,7 @@ export async function uploadBase64AttachmentsToDocumentsStore(
142138
if (record.registration?.attachments) {
143139
for (const attachment of record.registration.attachments) {
144140
if (attachment.data && isBase64FileString(attachment.data)) {
145-
const fileUri = await uploadFileToMinio(attachment.data, authHeader)
141+
const fileUri = await uploadBase64ToMinio(attachment.data, authHeader)
146142
attachment.data = fileUri
147143
}
148144
}
@@ -155,15 +151,18 @@ export async function uploadBase64AttachmentsToDocumentsStore(
155151
if (certificate.collector.affidavit) {
156152
for (const affidavit of certificate.collector.affidavit) {
157153
if (affidavit.data && isBase64FileString(affidavit.data)) {
158-
const fileUri = await uploadFileToMinio(affidavit.data, authHeader)
154+
const fileUri = await uploadBase64ToMinio(
155+
affidavit.data,
156+
authHeader
157+
)
159158
affidavit.data = fileUri
160159
}
161160
}
162161
}
163162
if (certificate.collector.photo) {
164163
for (const photo of certificate.collector.photo) {
165164
if (photo.data && isBase64FileString(photo.data)) {
166-
const fileUri = await uploadFileToMinio(photo.data, authHeader)
165+
const fileUri = await uploadBase64ToMinio(photo.data, authHeader)
167166
photo.data = fileUri
168167
}
169168
}
@@ -173,13 +172,13 @@ export async function uploadBase64AttachmentsToDocumentsStore(
173172
if (record.registration?.correction?.attachments) {
174173
for (const attachment of record.registration.correction.attachments) {
175174
if (attachment.data && isBase64FileString(attachment.data)) {
176-
const fileUri = await uploadFileToMinio(attachment.data, authHeader)
175+
const fileUri = await uploadBase64ToMinio(attachment.data, authHeader)
177176
attachment.data = fileUri
178177
}
179178
}
180179
}
181180
if (record.registration?.correction?.payment?.attachmentData) {
182-
const fileUri = await uploadFileToMinio(
181+
const fileUri = await uploadBase64ToMinio(
183182
record.registration.correction.payment.attachmentData,
184183
authHeader
185184
)

packages/workflow/src/records/handler/certify.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('Certify record endpoint', () => {
5757

5858
// Upload certificate to minio
5959
mswServer.use(
60-
rest.post('http://localhost:9050/upload-svg', (_, res, ctx) => {
60+
rest.post('http://localhost:9050/upload', (_, res, ctx) => {
6161
return res(
6262
ctx.json({ refUrl: '/ocrvs/6e964d7a-25d0-4524-bdc2-b1f29d1e816c' })
6363
)
@@ -153,7 +153,7 @@ describe('Certify record endpoint', () => {
153153

154154
// Upload certificate to minio
155155
mswServer.use(
156-
rest.post('http://localhost:9050/upload-svg', (_, res, ctx) => {
156+
rest.post('http://localhost:9050/upload', (_, res, ctx) => {
157157
return res(
158158
ctx.json({ refUrl: '/ocrvs/6e964d7a-25d0-4524-bdc2-b1f29d1e816c' })
159159
)

packages/workflow/src/records/handler/correction/request.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import { conflict } from '@hapi/boom'
1313
import { getAuthHeader } from '@opencrvs/commons/http'
1414
import { CorrectionRequestedRecord } from '@opencrvs/commons/types'
15-
import { uploadFileToMinio } from '@workflow/documents'
15+
import { uploadBase64ToMinio } from '@workflow/documents'
1616
import {
1717
getLoggedInPractitionerResource,
1818
getPractitionerOfficeId
@@ -51,15 +51,15 @@ export const requestCorrectionRoute = createRoute({
5151

5252
const paymentAttachmentUrl =
5353
correctionDetails.payment?.attachmentData &&
54-
(await uploadFileToMinio(
54+
(await uploadBase64ToMinio(
5555
correctionDetails.payment.attachmentData,
5656
getAuthHeader(request)
5757
))
5858

5959
const proofOfLegalCorrectionAttachments = await Promise.all(
6060
correctionDetails.attachments.map(async (attachment) => ({
6161
type: attachment.type,
62-
url: await uploadFileToMinio(attachment.data, getAuthHeader(request))
62+
url: await uploadBase64ToMinio(attachment.data, getAuthHeader(request))
6363
}))
6464
)
6565

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23937,9 +23937,9 @@ [email protected], typescript@^4.5:
2393723937
integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==
2393823938

2393923939
"typescript@>=3 < 6":
23940-
version "5.6.3"
23941-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.6.3.tgz#5f3449e31c9d94febb17de03cc081dd56d81db5b"
23942-
integrity sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==
23940+
version "5.4.5"
23941+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.5.tgz#42ccef2c571fdbd0f6718b1d1f5e6e5ef006f611"
23942+
integrity sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==
2394323943

2394423944
typical@^2.6.1:
2394523945
version "2.6.1"

0 commit comments

Comments
 (0)