diff --git a/src/infrastructure/BaseService.js b/src/infrastructure/BaseService.js index 7b4d28a7..524dafaa 100644 --- a/src/infrastructure/BaseService.js +++ b/src/infrastructure/BaseService.js @@ -1,5 +1,6 @@ import URLJoin from 'url-join'; import Request from 'request-promise'; +import StreamableRequest from 'request'; import XMLHttpRequester from './XMLHttpRequester'; class BaseModel { @@ -7,6 +8,7 @@ class BaseModel { this.url = URLJoin(url, 'api', 'v4'); this.headers = {}; this.requester = useXMLHttpRequest ? XMLHttpRequester : Request; + this.streamRequester = StreamableRequest; this.useXMLHttpRequest = useXMLHttpRequest; if (oauthToken) { diff --git a/src/infrastructure/RequestHelper.js b/src/infrastructure/RequestHelper.js index 5a30aa3e..b43fa194 100644 --- a/src/infrastructure/RequestHelper.js +++ b/src/infrastructure/RequestHelper.js @@ -50,6 +50,13 @@ class RequestHelper { return response.body; } + static streamGet(service, endpoint, options = {}) { + return service.streamRequester.get(defaultRequest(service, endpoint, { + headers: service.headers, + qs: options, + })); + } + static post(service, endpoint, options = {}, form = false) { const body = form ? 'fromData' : 'body'; diff --git a/src/services/Jobs.js b/src/services/Jobs.js index 68f39476..9463b705 100644 --- a/src/services/Jobs.js +++ b/src/services/Jobs.js @@ -12,6 +12,12 @@ class Jobs extends BaseService { return RequestHelper.get(this, `projects/${pId}/jobs/${jobId}/artifacts/${artifactPath}`); } + + downloadSingleArtifactFileStream(projectId, jobId, artifactPath) { + const pId = encodeURIComponent(projectId); + + return RequestHelper.streamGet(this, `projects/${pId}/jobs/${jobId}/artifacts/${artifactPath}`); + } } export default Jobs;