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

Function saveFile

src/lib/saveFile.js:22–205  ·  view source on GitHub ↗

* Saves a file to it's location, if file is new, it will ask for location * @param {EditorFile} file * @param {boolean} [isSaveAs]

(file, isSaveAs = false)

Source from the content-addressed store, hash-verified

20 * @param {boolean} [isSaveAs]
21 */
22async function saveFile(file, isSaveAs = false) {
23 // If file is loading, return
24 if (file.loading) return;
25
26 /**
27 * If set, new file needs to be created
28 * @type {string}
29 */
30 let newUrl;
31 /**
32 * File operation object
33 * @type {fsOperation}
34 */
35 let fileOnDevice;
36 /**
37 * File name, can be changed by user
38 * @type {string}
39 */
40 let { filename } = file;
41 /**
42 * If file is new
43 * @type {boolean}
44 */
45 let isNewFile = false;
46
47 /**
48 * Encoding of file
49 * @type {string}
50 */
51 const { encoding } = file;
52 /**
53 * File tab bar text element, used to show saving status
54 * @type {HTMLElement}
55 */
56 const $text = file.tab.querySelector("span.text");
57
58 if (!file.uri) {
59 isNewFile = true;
60 } else {
61 isSaveAs = isSaveAs ?? file.readOnly;
62 }
63
64 if (isSaveAs || isNewFile) {
65 const option = await recents.select(
66 [[SELECT_FOLDER, strings["select folder"], "folder"]], // options
67 "dir", // type
68 strings["select folder"], // title
69 );
70
71 if (option === SELECT_FOLDER) {
72 newUrl = await selectFolder();
73 } else {
74 newUrl = option.val.url;
75 }
76
77 if (isSaveAs) {
78 filename = await getfilename(newUrl, file.filename);
79 } else {

Callers 1

editorFile.jsFile · 0.85

Calls 14

selectFolderFunction · 0.85
getfilenameFunction · 0.85
fsOperationFunction · 0.85
resetTextFunction · 0.85
checkFunction · 0.70
existsMethod · 0.65
createFileMethod · 0.65
getFileMethod · 0.65
execMethod · 0.65
selectMethod · 0.45
toStringMethod · 0.45
writeFileMethod · 0.45

Tested by

no test coverage detected