@@ -46,7 +46,12 @@ function * downloadArtifact (submissionId, fileName) {
46
46
if ( artifacts . Contents . length === 0 ) {
47
47
throw new errors . HttpStatusError ( 400 , `Artifact ${ fileName } doesn't exist for ${ submissionId } ` )
48
48
}
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
+
50
55
const downloadedFile = yield s3 . getObject ( { Bucket : config . aws . ARTIFACT_BUCKET , Key : key } ) . promise ( )
51
56
// Return the retrieved Artifact
52
57
logger . info ( `downloadArtifact: returning artifact ${ fileName } for Submission ID: ${ submissionId } ` )
@@ -90,20 +95,7 @@ function * createArtifact (files, submissionId, entity) {
90
95
if ( files && files . artifact ) {
91
96
const uFileType = fileTypeFinder ( files . artifact . data ) . ext // File type of uploaded file
92
97
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
- }
103
98
104
- if ( exist ) {
105
- throw new errors . HttpStatusError ( 409 , `Artifact ${ files . artifact . name } .${ uFileType } already exists for Submission ${ submissionId } ` )
106
- }
107
99
// Upload the artifact to S3
108
100
yield _uploadToS3 ( files . artifact , fileName )
109
101
} else {
0 commit comments