diff --git a/lib/header.js b/lib/header.js index 6f307dd51..9a9ef3dc9 100644 --- a/lib/header.js +++ b/lib/header.js @@ -39,6 +39,9 @@ function addLinks (res, fileMetadata) { if (fileMetadata.isDirectContainer) { addLink(res, 'http://www.w3.org/ns/ldp#DirectContainer', 'type') } + if (fileMetadata.isStorage) { + addLink(res, 'http://www.w3.org/ns/pim/space#Storage', 'type') + } } async function linksHandler (req, res, next) { @@ -64,6 +67,7 @@ async function linksHandler (req, res, next) { } const fileMetadata = new metadata.Metadata() if (filename.endsWith('/')) { + if (req.path === '/') fileMetadata.isStorage = true fileMetadata.isContainer = true fileMetadata.isBasicContainer = true } else { @@ -102,6 +106,8 @@ function parseMetadataFromHeader (linkHeader) { fileMetadata.isBasicContainer = true } else if (parsedLinks[rel] === 'http://www.w3.org/ns/ldp#DirectContainer') { fileMetadata.isDirectContainer = true + } else if (parsedLinks[rel] === 'http://www.w3.org/ns/pim/space#Storage') { + fileMetadata.isStorage = true } } } diff --git a/lib/ldp-container.js b/lib/ldp-container.js index b5e77e2f1..c99328008 100644 --- a/lib/ldp-container.js +++ b/lib/ldp-container.js @@ -14,6 +14,14 @@ const path = require('path') async function addContainerStats (ldp, reqUri, filename, resourceGraph) { const containerStats = await ldp.stat(filename) addStats(resourceGraph, reqUri, containerStats, filename) + const storage = new URL(reqUri) + if (reqUri === storage.origin + '/') { + resourceGraph.add( + resourceGraph.sym(reqUri), + ns.rdf('type'), + ns.space('Storage') + ) + } resourceGraph.add( resourceGraph.sym(reqUri), ns.rdf('type'), diff --git a/lib/ldp.js b/lib/ldp.js index 978229182..2720869f1 100644 --- a/lib/ldp.js +++ b/lib/ldp.js @@ -108,7 +108,7 @@ class LDP { $rdf.parse(containerData, resourceGraph, reqUri, 'text/turtle') } catch (err) { debug.handlers('GET -- Error parsing data: ' + err) - throw error(500, "Can't parse container") + throw error(500, "Can't parse container .meta") } try { diff --git a/lib/metadata.js b/lib/metadata.js index a232c2691..925904cef 100644 --- a/lib/metadata.js +++ b/lib/metadata.js @@ -7,4 +7,5 @@ function Metadata () { this.isContainer = false this.isBasicContainer = false this.isDirectContainer = false + this.isStorage = false } diff --git a/test/integration/http-test.js b/test/integration/http-test.js index 65c8b17a1..72af343d4 100644 --- a/test/integration/http-test.js +++ b/test/integration/http-test.js @@ -76,6 +76,30 @@ describe('HTTP APIs', function () { .expect('content-type', /text\/turtle/) .expect(200, done) }) + it('should contain space:Storage triple', function (done) { + server.get('/') + .expect('content-type', /text\/turtle/) + .expect(200, done) + .expect((res) => { + const turtle = res.text + assert.match(turtle, /space:Storage/) + const kb = rdf.graph() + rdf.parse(turtle, kb, 'https://localhost/', 'text/turtle') + + assert(kb.match(undefined, + rdf.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), + rdf.namedNode('http://www.w3.org/ns/pim/space#Storage') + ).length, 'Must contain a triple space:Storage') + }) + }) + it('should have set Link as Container/BasicContainer/Storage', function (done) { + server.get('/') + .expect('content-type', /text\/turtle/) + .expect('Link', /; rel="type"/) + .expect('Link', /; rel="type"/) + .expect('Link', /; rel="type"/) + .expect(200, done) + }) }) describe('OPTIONS API', function () {