Skip to content

Commit ebefbbf

Browse files
fix(actions/manager/deployments): Suggest zip name based on deployment name.
1 parent 53c5933 commit ebefbbf

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

lib/manager/actions/deployments.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import { browserHistory } from 'react-router'
55
import { createAction, type ActionType } from 'redux-actions'
66

77
import { createVoidPayloadAction, secureFetch } from '../../common/actions'
8-
import { receiveProject } from './projects'
9-
import { startJobMonitor } from './status'
108
import fileDownload from '../../common/util/file-download'
11-
129
import type {Deployment, Feed, SummarizedFeedVersion} from '../../types'
1310
import type {dispatchFn, getStateFn} from '../../types/reducers'
1411

12+
import { startJobMonitor } from './status'
13+
import { receiveProject } from './projects'
14+
1515
const DEPLOYMENT_URL = `/api/manager/secure/deployments`
1616

1717
// Deployment Actions
@@ -132,11 +132,28 @@ export function downloadBuildArtifact (deployment: Deployment, filename: ?string
132132
}
133133
}
134134

135+
/**
136+
* Set a suggested file name for the given deployment.
137+
*
138+
* Note: Although a suggested file name is returned in the 'content-disposition' header of the 'download' endpoint,
139+
* it is still needed to set it here because we trigger the "Save As" dialog separately from the actual fetch.
140+
* Also, it is probably simpler to recompute the file name here instead of extracting it from the response.
141+
*
142+
* @param deployment The deployment object from which to derive the zip file name.
143+
* @returns The suggested zip file name ending in ".zip" for the browser "Save As" dialog.
144+
*/
145+
function getDeploymentZipFileName (deployment: Deployment): string {
146+
// Remove all spaces and special chars from deployment name.
147+
const zipBase = deployment.name.replace(/[^a-zA-Z0-9]/g, '')
148+
return `${zipBase}.zip`
149+
}
150+
135151
export function downloadDeployment (deployment: Deployment) {
136152
return function (dispatch: dispatchFn, getState: getStateFn) {
153+
const zipName = getDeploymentZipFileName(deployment)
137154
return dispatch(secureFetch(`${DEPLOYMENT_URL}/${deployment.id}/download`))
138155
.then(response => response.blob())
139-
.then(blob => fileDownload(blob, 'test.zip', 'application/zip'))
156+
.then(blob => fileDownload(blob, zipName, 'application/zip'))
140157
}
141158
}
142159

0 commit comments

Comments
 (0)