@@ -5,13 +5,13 @@ import { browserHistory } from 'react-router'
55import { createAction , type ActionType } from 'redux-actions'
66
77import { createVoidPayloadAction , secureFetch } from '../../common/actions'
8- import { receiveProject } from './projects'
9- import { startJobMonitor } from './status'
108import fileDownload from '../../common/util/file-download'
11-
129import type { Deployment , Feed , SummarizedFeedVersion } from '../../types'
1310import type { dispatchFn , getStateFn } from '../../types/reducers'
1411
12+ import { startJobMonitor } from './status'
13+ import { receiveProject } from './projects'
14+
1515const 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 - z A - Z 0 - 9 ] / g, '' )
148+ return `${ zipBase } .zip`
149+ }
150+
135151export 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