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

Method mapFileToUrl

lib/resource-mapper.mjs:71–88  ·  view source on GitHub ↗
({ path, hostname })

Source from the content-addressed store, hash-verified

69
70 // Maps a given server file to a URL
71 async mapFileToUrl ({ path, hostname }) {
72 // Remove the root path if specified
73 path = path.replace(/\\/g, '/')
74 if (path.startsWith(this._rootPath)) {
75 path = path.substring(this._rootPath.length)
76 }
77 if (this._includeHost) {
78 if (!path.startsWith(`/${hostname}/`)) {
79 throw new Error(`Path must start with hostname (/${hostname})`)
80 }
81 path = path.substring(hostname.length + 1)
82 }
83
84 // Determine the URL by chopping off everything after the dollar sign
85 const pathname = this._removeDollarExtension(path)
86 const url = `${this.resolveUrl(hostname)}${this._encodePath(pathname)}`
87 return { url, contentType: this._getContentTypeFromExtension(path) }
88 }
89
90 // Maps the request for a given resource and representation format to a server file
91 // Will look for an index file if a folder is given and searchIndex is true

Callers 9

listContainerMethod · 0.80
putMethod · 0.80
createDirectoryMethod · 0.80
getMethod · 0.80
globHandlerFunction · 0.80
patchHandlerFunction · 0.80
multiFunction · 0.80
mapsFileFunction · 0.80

Calls 4

resolveUrlMethod · 0.95
_encodePathMethod · 0.95

Tested by

no test coverage detected