@@ -132,18 +132,26 @@ async function handler (req, res, next) {
132
132
}
133
133
134
134
async 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 . getPublicUrl ( 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
139
147
140
148
const globOptions = {
141
149
noext : true ,
142
150
nobrace : true ,
143
151
nodir : true
144
152
}
145
153
146
- glob ( filename , globOptions , async ( err , matches ) => {
154
+ glob ( ` ${ folderPath } *` , globOptions , async ( err , matches ) => {
147
155
if ( err || matches . length === 0 ) {
148
156
debugGlob ( 'No files matching the pattern' )
149
157
return next ( error ( 404 , 'No files matching glob pattern' ) )
@@ -178,8 +186,7 @@ async function globHandler (req, res, next) {
178
186
} )
179
187
} ) ) )
180
188
181
- const requestUri = await ldp . resourceMapper . getPublicUrl ( req )
182
- const data = $rdf . serialize ( undefined , globGraph , requestUri , 'text/turtle' )
189
+ const data = $rdf . serialize ( undefined , globGraph , requestUrl , 'text/turtle' )
183
190
// TODO this should be added as a middleware in the routes
184
191
res . setHeader ( 'Content-Type' , 'text/turtle' )
185
192
debugGlob ( 'returning turtle' )
0 commit comments