@igea/oac_backend 1.0.40 → 1.0.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@igea/oac_backend",
3
- "version": "1.0.40",
3
+ "version": "1.0.41",
4
4
  "description": "Backend service for the OAC project",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -6,7 +6,6 @@ const ONTO_FOLDER = path.join(__dirname, '..', 'ontology');
6
6
  const Converter = require('../models/converter');
7
7
  const tmp = require('tmp');
8
8
 
9
-
10
9
  router.get('/schema/:format', (req, res) => {
11
10
  console.log(`Requesting SHACL schema in format: ${req.params.format}`);
12
11
  let format = req.params.format || 'ttl';
@@ -111,6 +110,7 @@ router.get('/schema-temp', (req, res) => {
111
110
  });
112
111
 
113
112
  router.post('/convert/:from/:to', (req, res) => {
113
+ console.log(req.headers['content-type']);
114
114
  const from = req.params.from;
115
115
  const to = req.params.to;
116
116
  console.log(`Requesting conversion from ${from} to ${to}`);
@@ -119,6 +119,8 @@ router.post('/convert/:from/:to', (req, res) => {
119
119
  conversionFunction = Converter.turtle2RdfXml
120
120
  }else if(from === 'xml' && to === 'ttl'){
121
121
  conversionFunction = Converter.rdfXml2Turtle
122
+ }else if(from === to){
123
+ conversionFunction = Converter.same
122
124
  }else{
123
125
  res.status(400).json({
124
126
  success: false,
@@ -127,13 +129,12 @@ router.post('/convert/:from/:to', (req, res) => {
127
129
  });
128
130
  return;
129
131
  }
130
-
131
132
  const inputFile = tmp.fileSync({ postfix: `.${from}` });
132
133
  const outputFile = tmp.fileSync({ postfix: `.${to}` });
133
-
134
- const content = req.body.file
135
-
136
- fs.writeFileSync(inputFile, content);
134
+
135
+ let content = req.body.file
136
+
137
+ fs.writeFileSync(inputFile.name, content);
137
138
 
138
139
  const removeFiles = function(_files){
139
140
  for(let i=0; i<_files.length; i++){
@@ -145,9 +146,12 @@ router.post('/convert/:from/:to', (req, res) => {
145
146
  }
146
147
  }
147
148
  }
148
- let files = [inputFile];
149
- conversionFunction(inputFile, outputFile).then(() => {
150
- res.sendFile(outputFile, (err) => {
149
+ let files = [inputFile.name];
150
+ conversionFunction(inputFile.name, outputFile.name).then(() => {
151
+ let dt = new Date();
152
+ let filename = `investigation-${dt.toISOString()}.${to}`;
153
+ res.setHeader('Content-Disposition', `attachment; filename="${filename}"`);
154
+ res.sendFile(outputFile.name, (err) => {
151
155
  if (err) {
152
156
  res.status(500).json({
153
157
  success: false,
@@ -156,7 +160,7 @@ router.post('/convert/:from/:to', (req, res) => {
156
160
  });
157
161
  files = [inputFile]
158
162
  }
159
- files.push(outputFile)
163
+ files.push(outputFile.name)
160
164
  removeFiles(files)
161
165
  });
162
166
  }).catch(err => {
package/src/index.js CHANGED
@@ -23,6 +23,7 @@ const app = express();
23
23
  app.use(cookieParser());
24
24
  app.use(express.json());
25
25
  app.use(jwtLib.middleware);
26
+ app.use(express.urlencoded({ extended: true }))
26
27
 
27
28
  let newPort = null
28
29
 
@@ -5,6 +5,18 @@ const { exec } = require('child_process');
5
5
 
6
6
  class Converter {
7
7
 
8
+ static async same(inPath, outPath) {
9
+ return new Promise((resolve, reject) => {
10
+ fs.copyFile(inPath, outPath, (err) => {
11
+ if (err) {
12
+ console.error(`Error during copying file: ${err.message}`);
13
+ reject(err);
14
+ }else
15
+ resolve();
16
+ });
17
+ })
18
+ }
19
+
8
20
  static async turtle2RdfXml(inTurtlePath, outRdfXmlPath) {
9
21
  return new Promise((resolve, reject) => {
10
22
  const command = `rapper -i turtle -o rdfxml "${inTurtlePath}" > "${outRdfXmlPath}"`;