Comparing version 0.2.3 to 0.2.4
{ | ||
"name": "gpxload", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "SignalK Server plugin to import / export GPX files", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -43,7 +43,7 @@ # signalk-gpx-plugin | ||
- GPXLoad preserves the uuids of resources exported from Signal K server, so if these gpx files are edited and re-imported they will update the corresponding resource on the Signal K server. | ||
- GPXLoad preserves the uuids of resources exported from Signal K server in the GPX file, so if these GPX files are re-imported they will update the corresponding resource on the Signal K server rather than create a new resource. | ||
- GPX files not containing elements without Signal K UUID values will have UUIDs assigned each time the file is opened (or re-opened) in the WebUI. This will result in duplicate resources on the Signal K server if the same GPX file is: opened, resources imported, re-opened and the same resources imported. | ||
- GPX files containing elements without Signal K UUID values will have UUIDs assigned each time the file is opened (or re-opened) in the WebUI. This will result in duplicate resources on the Signal K server if a GPX file is: opened, resources imported, re-opened and the same resources imported. | ||
@@ -119,2 +119,7 @@ /* | ||
}) | ||
router.get('/resources/waypoints/*-*-*-*-*', (req, res) => { | ||
res.json( | ||
getPersistedResources('waypoint', req.path.substring(req.path.lastIndexOf('/')+1)) | ||
) | ||
}) | ||
router.get('/resources/routes', (req, res) => { | ||
@@ -125,2 +130,7 @@ res.json( | ||
}) | ||
router.get('/resources/routes/*-*-*-*-*', (req, res) => { | ||
res.json( | ||
getPersistedResources('route', req.path.substring(req.path.lastIndexOf('/')+1)) | ||
) | ||
}) | ||
router.get('/resources/tracks', (req, res) => { | ||
@@ -131,2 +141,7 @@ res.json( | ||
}) | ||
router.get('/resources/tracks/*-*-*-*-*', (req, res) => { | ||
res.json( | ||
getPersistedResources('track', req.path.substring(req.path.lastIndexOf('/')+1)) | ||
) | ||
}) | ||
router.get('/resources/locations', (req, res) => { | ||
@@ -137,2 +152,7 @@ res.json( | ||
}) | ||
router.get('/resources/locations/*-*-*-*-*', (req, res) => { | ||
res.json( | ||
getPersistedResources('location', req.path.substring(req.path.lastIndexOf('/')+1)) | ||
) | ||
}) | ||
@@ -204,16 +224,21 @@ return router | ||
//** return persisted resources | ||
function getPersistedResources(type=null) { | ||
app.debug('*** Retrieving saved Resources ***') | ||
function getPersistedResources(type=null, item=null) { | ||
app.debug('*** Retrieving saved Resource(s) ***') | ||
let result= {} | ||
let rTypes= Object.entries(resTypes); | ||
try{ | ||
rTypes.forEach(rt=> { | ||
if(!type || type==rt[0]) { | ||
result[rt[0] + 's']= {} | ||
let files= fs.readdirSync(rt[1].path) | ||
files.forEach( f=> { | ||
result[rt[0] + 's'][f]= JSON.parse(fs.readFileSync( path.join(rt[1].path, f) , 'utf8')) | ||
}) | ||
} | ||
}) | ||
if(item) { | ||
result= JSON.parse(fs.readFileSync( path.join(resTypes[type].path, item) , 'utf8')) | ||
} | ||
else { | ||
rTypes.forEach(rt=> { | ||
if(!type || type==rt[0]) { | ||
result[rt[0] + 's']= {} | ||
let files= fs.readdirSync(rt[1].path) | ||
files.forEach( f=> { | ||
result[rt[0] + 's'][f]= JSON.parse(fs.readFileSync( path.join(rt[1].path, f) , 'utf8')) | ||
}) | ||
} | ||
}) | ||
} | ||
return result | ||
@@ -220,0 +245,0 @@ } |
1590177
1056