MCPcopy Index your code
hub / github.com/nodeSolidServer/node-solid-server / doFetch

Function doFetch

lib/acl-checker.mjs:293–315  ·  view source on GitHub ↗
(url)

Source from the content-addressed store, hash-verified

291 */
292function 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]) {

Callers 1

fetchLocalOrRemoteFunction · 0.70

Calls 2

mapUrlToFileMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected