Skip to content

Commit 252d804

Browse files
Shrmp 101/support receive logs (#36)
* receive logs at upload endpont * lint * label data sent to mgmt as result or log * lint * fix tests --------- Co-authored-by: Chris Bendel <[email protected]>
1 parent 2191b4b commit 252d804

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
lines changed

src/app/api/job/[jobId]/approve/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
1515
if (fs.existsSync(filePath)) {
1616
const fileBuffer = await fs.promises.readFile(filePath)
1717

18-
const response = await uploadResults(jobId, fileBuffer, 'text/csv')
18+
const response = await uploadResults(jobId, fileBuffer, 'text/csv', 'result')
1919

2020
if (!response.ok) {
2121
log(`BMA: Unable to post file for job ID ${jobId}`, 'error')

src/app/api/job/[jobId]/upload/route.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ daz67mcy8FIz1nBJ4z9P7ekCAwEAAQ==`),
190190

191191
const response = await POST(req, { params })
192192

193-
expect(mgmt.uploadResults).toHaveBeenCalledWith(mockJobId, expect.any(Blob), 'application/zip')
193+
expect(mgmt.uploadResults).toHaveBeenCalledWith(mockJobId, expect.any(Blob), 'application/zip', 'result')
194194
expect(response.status).toBe(200)
195195
})
196196

src/app/api/job/[jobId]/upload/route.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ export const POST = async (req: NextRequest, { params }: { params: Promise<{ job
6060
}
6161
} else {
6262
log('Encrypting results with public keys ...')
63+
const fileType = 'file' in body ? 'result' : 'log'
6364
const data: Blob = body.file ? ((await body.file) as Blob) : new Blob([body.logs])
6465
const resultsBuffer = await data.arrayBuffer()
6566
const encryptedResults = await encryptResults(jobId, resultsBuffer, publicKeys.keys)
66-
const response = await uploadResults(jobId, encryptedResults, 'application/zip')
67+
const response = await uploadResults(jobId, encryptedResults, 'application/zip', fileType)
6768
if (!response.ok) {
6869
errorMessage = `Failed to post encrypted results: ${response.status}`
6970
} else {

src/app/management-app-requests.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('uploadResults', () => {
4141
ok: true,
4242
})
4343

44-
const res = await uploadResults('123', new Blob(), 'application/zip')
44+
const res = await uploadResults('123', new Blob(), 'application/zip', 'result')
4545
expect(global.fetch).toHaveBeenCalledWith('http://bma/api/job/123/results', {
4646
method: 'POST',
4747
body: expect.any(FormData),

src/app/management-app-requests.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,14 @@ export const getPublicKeys = async (jobId: string): Promise<{ keys: ManagementAp
2828
return body
2929
}
3030

31-
export const uploadResults = async (jobId: string, results: Buffer | Blob, type: 'text/csv' | 'application/zip') => {
31+
export const uploadResults = async (
32+
jobId: string,
33+
results: Buffer | Blob,
34+
type: 'text/csv' | 'application/zip',
35+
fileType: 'result' | 'log',
36+
) => {
3237
const formData = new FormData()
33-
formData.append('file', new File([results], jobId, { type: type }))
38+
formData.append(fileType, new File([results], jobId, { type: type }))
3439

3540
const endpoint = `${process.env.MANAGEMENT_APP_API_URL}/api/job/${jobId}/results`
3641
log(`BMA: Uploading results ${endpoint}`)

0 commit comments

Comments
 (0)