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

Function showFileInfo

src/lib/showFileInfo.js:15–70  ·  view source on GitHub ↗
(url)

Source from the content-addressed store, hash-verified

13 * @param {String} [url]
14 */
15export 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}

Callers 1

"file-info"Function · 0.85

Calls 10

fsOperationFunction · 0.85
dialogFunction · 0.85
existsMethod · 0.65
deleteMethod · 0.65
createFileMethod · 0.65
copyMethod · 0.65
statMethod · 0.45
readFileMethod · 0.45
renderMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected