* Gets pathname from url eg. gets '/foo/bar' from 'ftp://myhost.com/foo/bar' * @param {string} url * @returns {string}
(url)
| 142 | * @returns {string} |
| 143 | */ |
| 144 | pathname(url) { |
| 145 | if (typeof url !== "string" || !this.PROTOCOL_PATTERN.test(url)) return url; |
| 146 | |
| 147 | url = url.split("?")[0]; |
| 148 | const protocol = (this.PROTOCOL_PATTERN.exec(url) || [])[0] || ""; |
| 149 | |
| 150 | if (protocol === "content://") { |
| 151 | try { |
| 152 | const { rootUri, docId, isFileUri } = Uri.parse(url); |
| 153 | if (isFileUri) return this.pathname(rootUri); |
| 154 | else return "/" + (docId.split(":")[1] || docId); |
| 155 | } catch (error) { |
| 156 | return null; |
| 157 | } |
| 158 | } else { |
| 159 | if (protocol) url = url.replace(new RegExp("^" + protocol), ""); |
| 160 | |
| 161 | if (protocol !== "file:///") |
| 162 | return "/" + url.split("/").slice(1).join("/"); |
| 163 | |
| 164 | return "/" + url; |
| 165 | } |
| 166 | }, |
| 167 | |
| 168 | /** |
| 169 | * Returns dirname from url eg. 'ftp://localhost/foo/' from 'ftp://localhost/foo/bar' |