New project structure
Beta of extract.js for extracting english locale
This commit is contained in:
parent
e18d2b2f84
commit
2edbd67205
247 changed files with 6405 additions and 4237 deletions
59
server/routes/subscriptions.js
Normal file
59
server/routes/subscriptions.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
'use strict';
|
||||
|
||||
const passport = require('../lib/passport');
|
||||
const shares = require('../models/shares');
|
||||
const contextHelpers = require('../lib/context-helpers');
|
||||
const router = require('../lib/router-async').create();
|
||||
const subscriptions = require('../models/subscriptions');
|
||||
const {castToInteger} = require('../lib/helpers');
|
||||
const stringify = require('csv-stringify')
|
||||
const fields = require('../models/fields');
|
||||
const lists = require('../models/lists');
|
||||
const moment = require('moment');
|
||||
|
||||
router.getAsync('/export/:listId/:segmentId', passport.loggedIn, async (req, res) => {
|
||||
const listId = castToInteger(req.params.listId);
|
||||
const segmentId = castToInteger(req.params.segmentId);
|
||||
|
||||
const flds = await fields.list(req.context, listId);
|
||||
|
||||
const columns = [
|
||||
{key: 'cid', header: 'cid'},
|
||||
{key: 'hash_email', header: 'HASH_EMAIL'},
|
||||
{key: 'email', header: 'EMAIL'},
|
||||
];
|
||||
|
||||
for (const fld of flds) {
|
||||
if (fld.column) {
|
||||
columns.push({
|
||||
key: fld.column,
|
||||
header: fld.key
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const list = await lists.getById(req.context, listId);
|
||||
|
||||
const headers = {
|
||||
'Content-Disposition': `attachment;filename=subscriptions-${list.cid}-${segmentId}-${moment().toISOString()}.csv`,
|
||||
'Content-Type': 'text/csv'
|
||||
};
|
||||
|
||||
res.set(headers);
|
||||
|
||||
const stringifier = stringify({
|
||||
columns,
|
||||
header: true,
|
||||
delimiter: ','
|
||||
});
|
||||
|
||||
stringifier.pipe(res);
|
||||
|
||||
for await (const subscription of subscriptions.listIterator(req.context, listId, segmentId, false)) {
|
||||
stringifier.write(subscription);
|
||||
}
|
||||
|
||||
stringifier.end();
|
||||
});
|
||||
|
||||
module.exports = router;
|
Loading…
Add table
Add a link
Reference in a new issue