Skip to content

Commit c185b67

Browse files
RubenVerborghrubensworks
authored andcommitted
Use ResourceMapper in ldp#graph.
1 parent 7039759 commit c185b67

File tree

2 files changed

+12
-41
lines changed

2 files changed

+12
-41
lines changed

lib/ldp.js

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -361,42 +361,22 @@ class LDP {
361361
* @return {Promise<Graph>}
362362
*/
363363
getGraph (uri, contentType = DEFAULT_CONTENT_TYPE) {
364-
const parsedUri = url.parse(uri)
365-
const path = parsedUri.pathname
366-
const hostname = parsedUri.hostname
364+
const { path } = url.parse(uri)
365+
return this.graph(path, uri, contentType)
366+
}
367367

368+
async graph (url, baseUri, contentType = 'text/turtle') {
369+
const { path } = await this.resourceMapper.mapUrlToFile({ url })
368370
return new Promise((resolve, reject) => {
369-
this.graph(hostname, path, uri, contentType, (error, graph) => {
370-
if (error) { return reject(error) }
371-
372-
resolve(graph)
371+
this.readFile(path, (err, body) => {
372+
if (err) return reject(err)
373+
const graph = $rdf.graph()
374+
$rdf.parse(body, graph, baseUri, contentType,
375+
err => err ? reject(err) : resolve(graph))
373376
})
374377
})
375378
}
376379

377-
graph (host, reqPath, baseUri, contentType, callback) {
378-
const ldp = this
379-
380-
// overloading
381-
if (typeof contentType === 'function') {
382-
callback = contentType
383-
contentType = 'text/turtle'
384-
}
385-
386-
if (typeof baseUri === 'function') {
387-
callback = baseUri
388-
baseUri = undefined
389-
}
390-
391-
const root = ldp.multiuser ? ldp.root + host + '/' : ldp.root
392-
const filename = utils.uriToFilename(reqPath, root)
393-
394-
ldp.readFile(filename, (err, body) => {
395-
if (err) return callback(err)
396-
parse(body, baseUri, contentType, callback)
397-
})
398-
}
399-
400380
get (options, callback) {
401381
let host
402382
let reqPath

lib/utils.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ module.exports.getBaseUri = getBaseUri
44
module.exports.pathBasename = pathBasename
55
module.exports.getFullUri = getFullUri
66
module.exports.hasSuffix = hasSuffix
7-
module.exports.parse = parse
87
module.exports.serialize = serialize
98
module.exports.translate = translate
109
module.exports.stringToStream = stringToStream
@@ -144,15 +143,6 @@ function hasSuffix (path, suffixes) {
144143
return false
145144
}
146145

147-
function parse (data, baseUri, contentType, callback) {
148-
const graph = $rdf.graph()
149-
try {
150-
return $rdf.parse(data, graph, baseUri, contentType, callback)
151-
} catch (err) {
152-
return callback(err)
153-
}
154-
}
155-
156146
function serialize (graph, baseUri, contentType, callback) {
157147
try {
158148
// target, kb, base, contentType, callback
@@ -189,7 +179,8 @@ function translate (stream, baseUri, from, to, callback) {
189179
data += chunk
190180
})
191181
.on('end', function () {
192-
parse(data, baseUri, from, function (err, graph) {
182+
const graph = $rdf.graph()
183+
$rdf.parse(data, graph, baseUri, from, function (err) {
193184
if (err) return callback(err)
194185
serialize(graph, baseUri, to, function (err, data) {
195186
if (err) return callback(err)

0 commit comments

Comments
 (0)