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,11 +1,13 @@
// @flow
import fs from 'fs';
import Router from 'koa-router';
import auth from '../middlewares/authentication';
import pagination from './middlewares/pagination';
import { presentCollection, presentUser } from '../presenters';
import { Collection, CollectionUser, Team, User } from '../models';
import { ValidationError, InvalidRequestError } from '../errors';
import { exportCollection, exportCollections } from '../logistics';
import { exportCollections } from '../logistics';
import { archiveCollection } from '../utils/zip';
import policy from '../policies';
import events from '../events';
@@ -144,12 +146,11 @@ router.post('collections.export', auth(), async ctx => {
const collection = await Collection.findByPk(id);
authorize(user, 'export', collection);
// async operation to create zip archive and email user
exportCollection(id, user.email);
const filePath = await archiveCollection(collection);
ctx.body = {
success: true,
};
ctx.attachment(`${collection.name}.zip`);
ctx.set('Content-Type', 'application/force-download');
ctx.body = fs.createReadStream(filePath);
});
router.post('collections.exportAll', auth(), async ctx => {