* Gets virtual address by replacing root with name i.e. added in file explorer * @param {string} url
(url)
| 89 | * @param {string} url |
| 90 | */ |
| 91 | getVirtualAddress(url) { |
| 92 | try { |
| 93 | const storageList = parseStorageList(); |
| 94 | |
| 95 | const matches = []; |
| 96 | for (let storage of storageList) { |
| 97 | const regex = new RegExp( |
| 98 | "^" + escapeStringRegexp(storage.uri ?? storage.url), |
| 99 | ); |
| 100 | matches.push({ |
| 101 | regex, |
| 102 | charMatched: url.length - url.replace(regex, "").length, |
| 103 | storage, |
| 104 | }); |
| 105 | } |
| 106 | |
| 107 | const matched = matches.sort((a, b) => { |
| 108 | return b.charMatched - a.charMatched; |
| 109 | })[0]; |
| 110 | |
| 111 | if (matched) { |
| 112 | const { storage, regex } = matched; |
| 113 | const { name } = storage; |
| 114 | const [base, paths] = url.split("::"); |
| 115 | url = base + "/" + paths.split("/").slice(1).join("/"); |
| 116 | return url.replace(regex, name).replace(/\/+/g, "/"); |
| 117 | } |
| 118 | |
| 119 | return url; |
| 120 | } catch (e) { |
| 121 | return url; |
| 122 | } |
| 123 | }, |
| 124 | /** |
| 125 | * Gets primary address of a content url. |
| 126 | * @param {string} url |
nothing calls this directly
no test coverage detected