diff --git a/lib/app.js b/lib/app.js index a9ac5329..921b5be0 100644 --- a/lib/app.js +++ b/lib/app.js @@ -412,6 +412,7 @@ function App () { app.post('/user/:userId/:collectionId/:displayId/:version/addOwner', requireUser, views.addOwner) app.post('/user/:userId/:collectionId/:displayId/:version/removeOwner/:username', requireUser, actions.removeOwner) app.get('/user/:userId/:collectionId/:displayId/:version/shareLink', requireUser, api.shareLink) + app.get('/user/:userId/:collectionId/:displayId/:version/:hash/share/shareLink', requirePublicLogin, api.shareLink) app.get('/user/:userId/:collectionId/:displayId/:version/:hash/share/addOwner', requirePublicLogin, views.addOwner) app.post('/user/:userId/:collectionId/:displayId/:version/:hash/share/addOwner', requirePublicLogin, views.addOwner) diff --git a/lib/getUrisFromReq.js b/lib/getUrisFromReq.js index 5092be55..67d353db 100644 --- a/lib/getUrisFromReq.js +++ b/lib/getUrisFromReq.js @@ -17,6 +17,7 @@ function getUrisFromReq (req, res) { var share var baseUri var baseUrl + var collectionUri var edit = false if (req.params.userId) { @@ -28,11 +29,16 @@ function getUrisFromReq (req, res) { baseUrl = '/user/' + encodeURIComponent(req.params.userId) + '/' + req.params.collectionId baseUri = config.get('databasePrefix') + 'user/' + encodeURIComponent(req.params.userId) + '/' + req.params.collectionId uri = config.get('databasePrefix') + 'user/' + encodeURIComponent(req.params.userId) + '/' + designId + collectionUri = config.get('databasePrefix') + 'user/' + encodeURIComponent(req.params.userId) + '/' + req.params.collectionId var webOfRegistries = config.get('webOfRegistries') var prefix = config.get('databasePrefix') prefix = prefix.substring(0, prefix.length - 1) - share = config.get('databasePrefix') + 'user/' + encodeURIComponent(req.params.userId) + '/' + designId + '/' + sha1('synbiohub_' + sha1(uri) + config.get('shareLinkSalt')) + '/share' + if (req.url.endsWith('/shareLink')) { + share = config.get('databasePrefix') + 'user/' + encodeURIComponent(req.params.userId) + '/' + designId + '/' + sha1('synbiohub_' + sha1(collectionUri) + config.get('shareLinkSalt')) + '/share' + } else { + share = config.get('databasePrefix') + 'user/' + encodeURIComponent(req.params.userId) + '/' + designId + '/' + sha1('synbiohub_' + sha1(uri) + config.get('shareLinkSalt')) + '/share' + } if (webOfRegistries[prefix]) { share = share.replace(prefix, webOfRegistries[prefix]) } @@ -46,6 +52,9 @@ function getUrisFromReq (req, res) { if (sha1('synbiohub_' + sha1(uri) + config.get('shareLinkSalt')) === req.params.hash) { graphUri = config.get('databasePrefix') + util.createTriplestoreID(req.params.userId) url = share + } else if (sha1('synbiohub_' + sha1(collectionUri) + config.get('shareLinkSalt')) === req.params.hash) { + graphUri = config.get('databasePrefix') + util.createTriplestoreID(req.params.userId) + url = share } else if (sha1('synbiohub_' + sha1(uri + '/edit') + config.get('shareLinkSalt')) === req.params.hash) { graphUri = config.get('databasePrefix') + util.createTriplestoreID(req.params.userId) url = share