Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions lib/ldp-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
2 changes: 1 addition & 1 deletion lib/ldp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions lib/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ function Metadata () {
this.isContainer = false
this.isBasicContainer = false
this.isDirectContainer = false
this.isStorage = false
}
24 changes: 24 additions & 0 deletions test/integration/http-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', /<http:\/\/www.w3.org\/ns\/ldp#BasicContainer>; rel="type"/)
.expect('Link', /<http:\/\/www.w3.org\/ns\/ldp#Container>; rel="type"/)
.expect('Link', /<http:\/\/www.w3.org\/ns\/pim\/space#Storage>; rel="type"/)
.expect(200, done)
})
})

describe('OPTIONS API', function () {
Expand Down