MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / getVirtualPath

Function getVirtualPath

src/utils/helpers.js:237–267  ·  view source on GitHub ↗

* Replace matching part of url to alias name by which storage is added * @param {String} url * @returns {String}

(url)

Source from the content-addressed store, hash-verified

235 * @returns {String}
236 */
237 getVirtualPath(url) {
238 url = Url.parse(url).url;
239
240 if (/^content:/.test(url)) {
241 const primary = Uri.getPrimaryAddress(url);
242 if (primary) {
243 return primary;
244 }
245 }
246
247 /**@type {string[]} */
248 const storageList = this.parseJSON(localStorage.storageList);
249 if (!Array.isArray(storageList)) return url;
250 const storageListLen = storageList.length;
251
252 for (let i = 0; i < storageListLen; ++i) {
253 const uuid = storageList[i];
254 let storageUrl = Url.parse(uuid.uri || uuid.url || "").url;
255 if (!storageUrl) continue;
256 if (storageUrl.endsWith("/")) {
257 storageUrl = storageUrl.slice(0, -1);
258 }
259 const regex = new RegExp("^" + escapeStringRegexp(storageUrl));
260 if (regex.test(url)) {
261 url = url.replace(regex, uuid.name);
262 break;
263 }
264 }
265
266 return url;
267 },
268 /**
269 * Updates uri of all active which matches the oldUrl as location
270 * of the file

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected