Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

For #11 and #12 #13

Merged
merged 2 commits into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions docs/SubmissionsApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,19 @@ await submissionApiM2MClient.downloadSubmission(submissionId)
await submissionApiUserCredentialsClient.downloadSubmission(submissionId)

await submissionApiJwtMethodArgClient.downloadSubmission(submissionId, config.JWT)

// Stream Model
const outputStream = fs.createWriteStream(filePath)
const req = await submissionApiM2MClient.downloadSubmission(submissionId, null, true)
req.pipe(outputStream)

const outputStream = fs.createWriteStream(filePath)
const req = await submissionApiUserCredentialsClient.downloadSubmission(submissionId, null, true)
req.pipe(outputStream)

const outputStream = fs.createWriteStream(filePath)
const req = await submissionApiJwtMethodArgClient.downloadSubmission(submissionId, config.JWT, true)
req.pipe(outputStream)
```

### Demo
Expand Down Expand Up @@ -716,6 +729,7 @@ Name | Type | Description
------------- | ------------- | -------------
**submissionId** | String | the submission id
**jwt** | String | the optional json web token
**streamed** | Boolean | the optional flag indicating whether or not to return a stream instead of a promise (default is promise)

### Return type

Expand Down Expand Up @@ -960,6 +974,19 @@ await submissionApiM2MClient.downloadArtifact(submissionId, artifactId)
await submissionApiUserCredentialsClient.downloadArtifact(submissionId, artifactId)

await submissionApiJwtMethodArgClient.downloadArtifact(submissionId, artifactId, config.JWT)

// Stream Model
const outputStream = fs.createWriteStream(filePath)
const req = await submissionApiM2MClient.downloadArtifact(submissionId, artifactId, null, true)
req.pipe(outputStream)

const outputStream = fs.createWriteStream(filePath)
const req = await submissionApiUserCredentialsClient.downloadArtifact(submissionId, artifactId, null, true)
req.pipe(outputStream)

const outputStream = fs.createWriteStream(filePath)
const req = await submissionApiJwtMethodArgClient.downloadArtifact(submissionId, artifactId, config.JWT, true)
req.pipe(outputStream)
```

### Demo
Expand Down Expand Up @@ -1008,6 +1035,7 @@ Name | Type | Description
**submissionId** | String | the submission id
**artifactId** | String | the artifact id
**jwt** | String | the optional json web token
**streamed** | Boolean | the optional flag indicating whether or not to return a stream instead of a promise (default is a promise)

### Return type

Expand Down
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ module.exports = (allConfig) => {
return require('./src/SubmissionsApi').deleteSubmission(config, submissionId, jwt)
},
// Download submission
downloadSubmission: (submissionId, jwt) => {
return require('./src/SubmissionsApi').downloadSubmission(config, submissionId, jwt)
downloadSubmission: (submissionId, jwt, streamed = false) => {
return require('./src/SubmissionsApi').downloadSubmission(config, submissionId, jwt, streamed)
},
// Create artifact for submission
createArtifact: (submissionId, reqFormData, jwt) => {
Expand All @@ -238,8 +238,8 @@ module.exports = (allConfig) => {
return require('./src/SubmissionsApi').listArtifacts(config, submissionId, jwt)
},
// Download artifact
downloadArtifact: (submissionId, artifactId, jwt) => {
return require('./src/SubmissionsApi').downloadArtifact(config, submissionId, artifactId, jwt)
downloadArtifact: (submissionId, artifactId, jwt, streamed = false) => {
return require('./src/SubmissionsApi').downloadArtifact(config, submissionId, artifactId, jwt, streamed)
},
// Delete artifact
deleteArtifact: (submissionId, artifactId, jwt) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@hapi/joi": "^15.0.3",
"lodash": "^4.17.15",
"superagent": "^3.8.3",
"tc-core-library-js": "appirio-tech/tc-core-library-js.git"
"tc-core-library-js": "github:appirio-tech/tc-core-library-js#v2.6.4"
},
"devDependencies": {
"chai": "^4.2.0",
Expand Down
10 changes: 6 additions & 4 deletions src/SubmissionsApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,11 @@ const deleteSubmission = (config, submissionId, jwt = null) => {
* Function to download submission by id.
* @param {Object} config Configuration object
* @param {String} submissionId the submission id
* @param {Boolean} streamed Whether a stream is to be returned (Default: false)
* @returns {Promise} the submission file content
*/
const downloadSubmission = (config, submissionId, jwt = null) => {
return helper.reqToV5APIDownload(config, jwt, `${config.SUBMISSION_API_URL}/submissions/${submissionId}/download`)
const downloadSubmission = (config, submissionId, jwt = null, streamed = false) => {
return helper.reqToV5APIDownload(config, jwt, `${config.SUBMISSION_API_URL}/submissions/${submissionId}/download`, streamed)
}

/**
Expand Down Expand Up @@ -149,10 +150,11 @@ const listArtifacts = (config, submissionId, jwt = null) => {
* @param {Object} config Configuration object
* @param {String} submissionId the submission id
* @param {String} artifactId the artifact id
* @param {Boolean} streamed Whether a stream is to be returned (Default: false)
* @returns {Promise} the artifact file content
*/
const downloadArtifact = (config, submissionId, artifactId, jwt = null) => {
return helper.reqToV5APIDownload(config, jwt, `${config.SUBMISSION_API_URL}/submissions/${submissionId}/artifacts/${artifactId}/download`)
const downloadArtifact = (config, submissionId, artifactId, jwt = null, streamed = false) => {
return helper.reqToV5APIDownload(config, jwt, `${config.SUBMISSION_API_URL}/submissions/${submissionId}/artifacts/${artifactId}/download`, streamed)
}

/**
Expand Down
15 changes: 12 additions & 3 deletions src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,23 @@ const reqToV5APIWithFile = async (config, jwt, path, formData, fileFieldName) =>
* Function to download file using V5 API
* @param {Object} config Configuration object
* @param {String} jwt The JWT
* @param (String) path Complete path of the API URL
* @param {String} path Complete path of the API URL
* @param {Boolean} streamed Whether a stream is to be returned (Default: false)
* @returns {Promise}
*/
const reqToV5APIDownload = async (config, jwt, path) => {
const reqToV5APIDownload = async (config, jwt, path, streamed = false) => {
const token = await getToken(config, jwt)
return request
let req = request
.get(path)
.set('Authorization', `Bearer ${token}`)
if (streamed) {
req = req.buffer(false)
req.then = undefined
req.catch = undefined
req.finally = undefined
return req
}
return req
.buffer(true)
.parse(function (res, callback) {
res.data = ''
Expand Down