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:
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user