@@ -132,18 +132,26 @@ async function handler (req, res, next) {
132132}
133133
134134async function globHandler ( req , res , next ) {
135- const ldp = req . app . locals . ldp
136- // TODO: This is a hack, that does not check if the target file exists, as this is quite complex with globbing.
137- // TODO: Proper support for this is not implemented, as globbing support might be removed in the future.
138- const filename = ldp . resourceMapper . getFilePath ( req )
135+ const { ldp } = req . app . locals
136+
137+ // Ensure this is a glob for all files in a single folder
138+ // https://github.com/solid/solid-spec/pull/148
139+ const requestUrl = await ldp . resourceMapper . getRequestUrl ( req )
140+ if ( ! / ^ [ ^ * ] + \/ \* $ / . test ( requestUrl ) ) {
141+ return next ( error ( 404 , 'Unsupported glob pattern' ) )
142+ }
143+
144+ // Extract the folder on the file system from the URL glob
145+ const folderUrl = requestUrl . substr ( 0 , requestUrl . length - 1 )
146+ const folderPath = ( await ldp . resourceMapper . mapUrlToFile ( { url : folderUrl } ) ) . path
139147
140148 const globOptions = {
141149 noext : true ,
142150 nobrace : true ,
143151 nodir : true
144152 }
145153
146- glob ( filename , globOptions , async ( err , matches ) => {
154+ glob ( ` ${ folderPath } *` , globOptions , async ( err , matches ) => {
147155 if ( err || matches . length === 0 ) {
148156 debugGlob ( 'No files matching the pattern' )
149157 return next ( error ( 404 , 'No files matching glob pattern' ) )
@@ -178,8 +186,7 @@ async function globHandler (req, res, next) {
178186 } )
179187 } ) ) )
180188
181- const requestUri = ldp . resourceMapper . getRequestUrl ( req )
182- const data = $rdf . serialize ( undefined , globGraph , requestUri , 'text/turtle' )
189+ const data = $rdf . serialize ( undefined , globGraph , requestUrl , 'text/turtle' )
183190 // TODO this should be added as a middleware in the routes
184191 res . setHeader ( 'Content-Type' , 'text/turtle' )
185192 debugGlob ( 'returning turtle' )
0 commit comments