(url)
| 291 | */ |
| 292 | function fetchLocalOrRemote (mapper, serverUri) { |
| 293 | async function doFetch (url) { |
| 294 | // Convert the URL into a filename |
| 295 | let body, path, contentType |
| 296 | |
| 297 | if (Url.parse(url).host.includes(Url.parse(serverUri).host)) { |
| 298 | // Fetch the acl from local |
| 299 | try { |
| 300 | ({ path, contentType } = await mapper.mapUrlToFile({ url })) |
| 301 | } catch (err) { |
| 302 | // delete from cache |
| 303 | delete temporaryCache[url] |
| 304 | throw new HTTPError(404, err) |
| 305 | } |
| 306 | // Read the file from disk |
| 307 | body = await promisify(fs.readFile)(path, { encoding: 'utf8' }) |
| 308 | } else { |
| 309 | // Fetch the acl from the internet |
| 310 | const response = await fetch(url) |
| 311 | body = await response.text() |
| 312 | contentType = response.headers.get('content-type') |
| 313 | } |
| 314 | return { body, contentType } |
| 315 | } |
| 316 | return async function fetch (url, graph = rdf.graph()) { |
| 317 | graph.initPropertyActions(['sameAs']) // activate sameAs |
| 318 | if (!temporaryCache[url]) { |
no test coverage detected