Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions src/server/routes/api/document/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fetch from 'node-fetch';
import JSZip from 'jszip';
import _ from 'lodash';
import fs from 'fs';
import logger from '../../../logger';

import Document from '../../../../model/document';

Expand All @@ -13,8 +14,8 @@ import { convertDocumentToBiopax,
const DOCUMENT_STATUS_FIELDS = Document.statusFields();
const CHUNK_SIZE = 20;
const EXPORT_TYPES = Object.freeze({
'JS': 'js',
'BP': 'bp',
'JS': 'json',
'BP': 'biopax',
'SBGN': 'sbgn'
});

Expand Down Expand Up @@ -65,7 +66,13 @@ const exportToZip = (baseUrl, zipPath, types) => {
types = Object.keys( typeToConverter );
}

const idToFiles = id => types.map( t => typeToConverter[ t ]( id, baseUrl ) );
const idToFiles = id => types.map( t => {
return typeToConverter[ t ]( id, baseUrl )
.catch( () => {
logger.error(`Error in export: cannot convert the document ${id} into ${t}`);
return null;
} );
} );

let promises = ids.map( idToFiles );
promises = _.flatten( promises );
Expand All @@ -76,11 +83,13 @@ const exportToZip = (baseUrl, zipPath, types) => {
return Promise.all( promises )
.then( contents => {
contents.forEach( ( content, i ) => {
let id = ids[ Math.floor( i / s ) ];
let ext = fileExts[ i % s ];
let fileName = id + ext;
if ( content != null ) {
let id = ids[ Math.floor( i / s ) ];
let ext = fileExts[ i % s ];
let fileName = id + ext;

zip.file( fileName, content );
zip.file( fileName, content );
}
} );
} );
};
Expand Down
4 changes: 3 additions & 1 deletion src/util/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { checkHTTPStatus } from './fetch';
function convertDocumentToBiopax(docId, baseUrl = '') {
let SERVER_URL = baseUrl + `/api/document/biopax/${docId}`;
let makeRequest = () => fetch(SERVER_URL);
return tryPromise( makeRequest ).then( result => result.text() );
return tryPromise( makeRequest )
.then( checkHTTPStatus )
.then( result => result.text() );
}

function convertDocumentToTxt(docId, baseUrl = '') {
Expand Down