Skip to content

Commit 4469ccc

Browse files
author
Dushyant Bhalgami
committed
fixed the issue with the internal artifact download
1 parent 9ccc0bb commit 4469ccc

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

src/services/ArtifactService.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ function * downloadArtifact (submissionId, fileName) {
4646
if (artifacts.Contents.length === 0) {
4747
throw new errors.HttpStatusError(400, `Artifact ${fileName} doesn't exist for ${submissionId}`)
4848
}
49-
const key = artifacts.Contents[0].Key
49+
50+
const key = submissionId + '/' + fileName + '.zip'
51+
if (!_.includes(_.map(artifacts.Contents, 'Key'), key)) {
52+
throw new errors.HttpStatusError(400, `Artifact ${fileName} doesn't exist for ${submissionId}`)
53+
}
54+
5055
const downloadedFile = yield s3.getObject({ Bucket: config.aws.ARTIFACT_BUCKET, Key: key }).promise()
5156
// Return the retrieved Artifact
5257
logger.info(`downloadArtifact: returning artifact ${fileName} for Submission ID: ${submissionId}`)
@@ -90,20 +95,7 @@ function * createArtifact (files, submissionId, entity) {
9095
if (files && files.artifact) {
9196
const uFileType = fileTypeFinder(files.artifact.data).ext // File type of uploaded file
9297
fileName = `${submissionId}/${files.artifact.name}.${uFileType}`
93-
let exist
94-
// Check the existence of file in S3 bucket
95-
try {
96-
exist = yield s3.headObject({
97-
Bucket: config.aws.ARTIFACT_BUCKET,
98-
Key: fileName
99-
}).promise()
100-
} catch (err) {
101-
if (err.statusCode !== 404) throw err
102-
}
10398

104-
if (exist) {
105-
throw new errors.HttpStatusError(409, `Artifact ${files.artifact.name}.${uFileType} already exists for Submission ${submissionId}`)
106-
}
10799
// Upload the artifact to S3
108100
yield _uploadToS3(files.artifact, fileName)
109101
} else {

0 commit comments

Comments
 (0)