feat: Export collection as direct download instead of emailing (#1001)

* feat: Export collection as zip instead of emailing

* Flow typing download.js
This commit is contained in:
Tom Moor
2019-07-29 22:35:34 -07:00
committed by GitHub
parent c9b86ec2e7
commit 92a18159b5
8 changed files with 192 additions and 17 deletions

View File

@ -1,7 +1,8 @@
// @flow
import { map } from 'lodash';
import { map, trim } from 'lodash';
import invariant from 'invariant';
import stores from 'stores';
import download from './download';
type Options = {
baseUrl?: string,
@ -65,7 +66,17 @@ class ApiClient {
}
}
if (response.status >= 200 && response.status < 300) {
const success = response.status >= 200 && response.status < 300;
if (options.download && success) {
const blob = await response.blob();
const fileName = (
response.headers.get('content-disposition') || ''
).split('filename=')[1];
download(blob, trim(fileName, '"'));
return;
} else if (success) {
return response.json();
}