Skip to content

Commit b6b3436

Browse files
committed
Use ResourceMapper in get#globHandler
1 parent 81d42cd commit b6b3436

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

lib/handlers/get.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const glob = require('glob')
55
const _path = require('path')
66
const $rdf = require('rdflib')
77
const Negotiator = require('negotiator')
8-
const url = require('url')
98
const mime = require('mime-types')
109

1110
const debug = require('debug')('solid:get')
@@ -143,12 +142,10 @@ async function handler (req, res, next) {
143142
}
144143
}
145144

146-
function globHandler (req, res, next) {
145+
async function globHandler (req, res, next) {
147146
const ldp = req.app.locals.ldp
148-
const root = !ldp.multiuser ? ldp.root : ldp.root + req.hostname + '/'
149-
const filename = utils.uriToFilename(req.path, root)
150-
const uri = utils.getFullUri(req)
151-
const requestUri = url.resolve(uri, req.path)
147+
const { path: filename } = await ldp.resourceMapper.mapUrlToFile({ url: req })
148+
const requestUri = (await ldp.resourceMapper.mapFileToUrl({ path: filename, hostname: req.hostname })).url
152149

153150
const globOptions = {
154151
noext: true,
@@ -165,25 +162,23 @@ function globHandler (req, res, next) {
165162
// Matches found
166163
const globGraph = $rdf.graph()
167164

168-
let reqOrigin = utils.getBaseUri(req)
169-
170165
debugGlob('found matches ' + matches)
171-
Promise.all(matches.map(match => new Promise((resolve, reject) => {
172-
const baseUri = reqOrigin + '/' + match.substr(root.length)
166+
Promise.all(matches.map(match => new Promise(async (resolve, reject) => {
167+
const baseUri = await ldp.resourceMapper.mapFileToUrl({ path: match, hostname: req.hostname })
173168
fs.readFile(match, {encoding: 'utf8'}, function (err, fileData) {
174169
if (err) {
175170
debugGlob('error ' + err)
176171
return resolve()
177172
}
178173
// Files should have the .ttl extension or be extensionless (also Turtle)
179-
if (!/\.ttl$|\/[^.]+$/.test(match)) {
174+
if (baseUri.contentType !== 'text/turtle') {
180175
return resolve()
181176
}
182177
// The agent should have Read access to the file
183178
hasReadPermissions(match, req, res, function (allowed) {
184179
if (allowed) {
185180
try {
186-
$rdf.parse(fileData, globGraph, baseUri, 'text/turtle')
181+
$rdf.parse(fileData, globGraph, baseUri.url, 'text/turtle')
187182
} catch (parseErr) {
188183
debugGlob(`error parsing ${match}: ${parseErr}`)
189184
}

0 commit comments

Comments
 (0)