forked from posm/OpenMapKitServer
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into build_dist
- Loading branch information
Showing
16 changed files
with
1,352 additions
and
849 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,47 @@ | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var mkdirp = require('mkdirp'); | ||
|
||
const { | ||
syncDataDir | ||
} = require('../helpers/aws-sync'); | ||
var settings = require('../../../settings.js'); | ||
|
||
module.exports = function (req, res, next) { | ||
var submission = req.submission; | ||
var ext = submission.geojson ? '.geojson' : '.json'; | ||
var json = JSON.stringify(submission.json, null, ' '); | ||
var xml = submission.xml; // Original XML for debug purposes is nice. | ||
|
||
var dir = settings.dataDir + '/submissions/' + submission.formId + '/' + submission.instanceId; | ||
var jsonFileName = dir + '/data' + ext; | ||
var xmlFileName = dir + '/data' + '.xml'; | ||
module.exports = function(req, res, next) { | ||
var submission = req.submission; | ||
var ext = submission.geojson ? '.geojson' : '.json'; | ||
var json = JSON.stringify(submission.json, null, ' '); | ||
var xml = submission.xml; // Original XML for debug purposes is nice. | ||
|
||
var dir = settings.dataDir + '/submissions/' + submission.formId + '/' + submission.instanceId; | ||
var jsonFileName = dir + '/data' + ext; | ||
var xmlFileName = dir + '/data' + '.xml'; | ||
|
||
mkdirp(path.dirname(jsonFileName), function (err) { | ||
if (err) { | ||
console.error(err); | ||
res.status(500).json({status: 500, err: err}); | ||
return; | ||
} | ||
fs.writeFile(xmlFileName, xml, function(err) { | ||
if (err) console.error(err); | ||
}); | ||
fs.writeFile(jsonFileName, json, function (err) { | ||
if (err) { | ||
console.error(err); | ||
res.status(500).json({status: 500, err: err}); | ||
return; | ||
} | ||
res.status(201).json({saved: jsonFileName}); | ||
}); | ||
mkdirp(path.dirname(jsonFileName), function(err) { | ||
if (err) { | ||
console.error(err); | ||
res.status(500).json({status: 500, err: err}); | ||
return; | ||
} | ||
fs.writeFile(xmlFileName, xml, function(err) { | ||
if (err) { | ||
console.error(err); | ||
} else { | ||
syncDataDir(); | ||
} | ||
}); | ||
fs.writeFile(jsonFileName, json, function(err) { | ||
if (err) { | ||
console.error(err); | ||
res.status(500).json({status: 500, err: err}); | ||
return; | ||
} else { | ||
syncDataDir(); | ||
} | ||
res.status(201).json({ | ||
saved: jsonFileName | ||
}); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
var s3 = require('@monolambda/s3'); | ||
var path = require('path'); | ||
|
||
var settings = require('../../../settings'); | ||
|
||
const AWSBUCKETPREFIX = process.env.AWSBUCKETPREFIX ? process.env.AWSBUCKETPREFIX : '/'; | ||
|
||
const syncDataDir = () => { | ||
if (process.env.ENABLES3SYNC) { | ||
var client = s3.createClient({ | ||
s3Options: { | ||
accessKeyId: process.env.AWSKEYID, | ||
secretAccessKey: process.env.AWSSECRETKEY | ||
} | ||
}); | ||
var params = { | ||
localDir: settings.dataDir, | ||
deleteRemoved: true, | ||
s3Params: { | ||
Bucket: process.env.AWSBUCKETNAME, | ||
Prefix: AWSBUCKETPREFIX | ||
} | ||
}; | ||
var uploader = client.uploadDir(params); | ||
uploader.on('error', function(err) { | ||
console.error("unable to sync:", err.stack); | ||
}); | ||
uploader.on('end', function() { | ||
console.log("done uploading"); | ||
}); | ||
} | ||
}; | ||
|
||
const downloadDataDir = () => { | ||
if (process.env.ENABLES3SYNC) { | ||
var client = s3.createClient({ | ||
s3Options: { | ||
accessKeyId: process.env.AWSKEYID, | ||
secretAccessKey: process.env.AWSSECRETKEY | ||
} | ||
}); | ||
var params = { | ||
localDir: settings.dataDir, | ||
deleteRemoved: true, | ||
s3Params: { | ||
Bucket: process.env.AWSBUCKETNAME, | ||
Prefix: AWSBUCKETPREFIX | ||
} | ||
}; | ||
var uploader = client.downloadDir(params); | ||
uploader.on('error', function(err) { | ||
console.error("unable to sync:", err.stack); | ||
}); | ||
uploader.on('end', function() { | ||
console.log("Download from AWS S3 done"); | ||
}); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
syncDataDir, | ||
downloadDataDir | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
const args = [ 'build' ]; | ||
var spawn = require('child_process').spawnSync; | ||
const opts = { stdio: 'inherit', cwd: 'frontend', shell: true }; | ||
require('child_process').spawn('yarn', args, opts); | ||
|
||
const install = spawn('yarn', [ 'install' ], opts); | ||
const build = spawn('yarn', [ 'build' ], opts); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.