Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function writeout_result(result, user, fileType) {
- var outData = JSON.stringify(result)
- ,downloadPath = null
- ,fileName = null
- ,extension = null;
- try {
- switch ( fileType ) {
- case 'json':
- extension = 'json';
- fileName = user.userid + '_' + Math.random() + '.' + extension;
- downloadPath = cfg.paths.outgoing + fileName;
- break;
- default:
- extension = (fileType === 'excel') ? 'csv' : 'txt';
- fileName = user.userid + '_' + Math.random() + '.' + extension;
- downloadPath = cfg.paths.outgoing + fileName;
- converter.json2csv(result, function (err, csv) {
- if (err) {
- send_error('error formating csv file');
- return;
- }
- outData = csv;
- });
- break;
- }
- fs.writeFile(downloadPath, outData,
- function(err) {
- if(err) {
- console.log(err);
- send_error('[csv] Had a problem creating the read file.');
- return;
- } else {
- res.send(JSON.stringify({'download': fileName + '&type=maj', 'data': result}));
- return;
- }
- });
- } catch (e) {
- console.log(e);
- send_error('Sorry but we experienced a problem writing out your result. Please try again.');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement