(url)
| 13 | * @param {String} [url] |
| 14 | */ |
| 15 | export default async function showFileInfo(url) { |
| 16 | if (!url) url = editorManager.activeFile.uri; |
| 17 | loader.showTitleLoader(); |
| 18 | try { |
| 19 | const fs = fsOperation(url); |
| 20 | const stats = await fs.stat(); |
| 21 | |
| 22 | let { name, lastModified, length, type } = stats; |
| 23 | length = filesize(length); |
| 24 | lastModified = new Date(lastModified).toLocaleString(); |
| 25 | |
| 26 | const protocol = Url.getProtocol(url); |
| 27 | const fileType = type.toLowerCase(); |
| 28 | const options = { |
| 29 | name: name.slice(0, name.length - Url.extname(name).length), |
| 30 | extension: Url.extname(name), |
| 31 | lastModified, |
| 32 | length, |
| 33 | type, |
| 34 | lang: strings, |
| 35 | showUri: helpers.getVirtualPath(url), |
| 36 | isEditor: |
| 37 | fileType === "text/plain" || editorManager.activeFile.type === "editor", |
| 38 | }; |
| 39 | |
| 40 | if (editorManager.activeFile.type === "editor") { |
| 41 | const value = await fs.readFile(settings.value.defaultFileEncoding); |
| 42 | options.lineCount = value.split(/\n+/).length; |
| 43 | options.wordCount = value.split(/\s+|\n+/).length; |
| 44 | |
| 45 | if (/s?ftp:/.test(protocol)) { |
| 46 | options.shareUri = Url.join(CACHE_STORAGE, name); |
| 47 | const fs = fsOperation(options.shareUri); |
| 48 | if (await fs.exists()) { |
| 49 | await fs.delete(); |
| 50 | } |
| 51 | await fsOperation(CACHE_STORAGE).createFile(name, value); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | dialog("", mustache.render($_fileInfo, options), true).onclick((e) => { |
| 56 | const $target = e.target; |
| 57 | if ($target instanceof HTMLElement) { |
| 58 | const action = $target.getAttribute("action"); |
| 59 | |
| 60 | if (action === "copy") { |
| 61 | cordova.plugins.clipboard.copy($target.textContent); |
| 62 | } |
| 63 | } |
| 64 | }); |
| 65 | } catch (err) { |
| 66 | helpers.error(err); |
| 67 | } |
| 68 | |
| 69 | loader.removeTitleLoader(); |
| 70 | } |
no test coverage detected