Skip to content

Commit 28e4055

Browse files
export nlp (#28)
* export nlp * enhanced download Co-authored-by: Jesus Rocha <[email protected]>
1 parent a09b734 commit 28e4055

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

.vscode/launch.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Launch Program",
9+
"program": "${workspaceFolder}/server.js",
10+
"request": "launch",
11+
"skipFiles": [
12+
"<node_internals>/**"
13+
],
14+
"type": "node"
15+
}
16+
17+
]
18+
}

server.js

+33-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,39 @@ app.post('/api/uploadflow', async (req, res) => {
141141
res.status(500).send({ message: 'File upload failed' });
142142
}
143143
});
144-
144+
app.get('/api/download/:workingId', (req, res) => {
145+
const { workingId } = req.params;
146+
const destinationPath = `${systemTdataFolder}/user-data-in/${workingId}.export-aql`;
147+
fs.writeFileSync(destinationPath, "");
148+
const resultFileName = `${workingId}.zip`;
149+
const file = `${systemTdataFolder}/run-aql-result/${resultFileName}`;
150+
const FIFTYSECONDSTIMEOUT = 100;
151+
let counter = 0;
152+
setInterval( () => {
153+
if( counter > FIFTYSECONDSTIMEOUT) {
154+
clearInterval(this);
155+
return res.status(400).send({ status: '' });
156+
}
157+
158+
if(fs.existsSync(file) ) {
159+
var stat = fs.statSync(file);
160+
161+
let fileContents = fs.createReadStream(file);
162+
const fileType = 'application/zip';
163+
res.writeHead(200, {
164+
'Content-Type': fileType,
165+
'Content-Length': stat.size
166+
})
167+
fileContents.on('close', () => {
168+
clearInterval(this);
169+
deleteFile(`${systemTdataFolder}/run-aql-result/${resultFileName}`, resultFileName);
170+
res.end();
171+
})
172+
fileContents.pipe(res);
173+
}
174+
counter += 1;
175+
}, 500);
176+
})
145177
app.post('/api/run', (req, res) => {
146178
console.log('executing pipeline');
147179
const { workingId, payload } = req.body;

src/nlp-visual-editor/nlp-visual-editor.jsx

+18
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,24 @@ class VisualEditor extends React.Component {
322322
</>
323323
),
324324
},
325+
{
326+
action: 'export',
327+
tooltip: 'Export',
328+
jsx: (
329+
<>
330+
<Button
331+
id={'btn-run'}
332+
size="field"
333+
kind="ghost"
334+
disabled={this.props.tabularResults === undefined}
335+
onClick={() => window.open(`/api/download/${this.props.pipelineId}`)}
336+
>
337+
Export
338+
</Button>
339+
</>
340+
),
341+
},
342+
325343
];
326344
};
327345

0 commit comments

Comments
 (0)