MCPcopy
hub / github.com/brunosimon/keppler / addFile

Method addFile

app/src/utils/FileTree.js:135–176  ·  view source on GitHub ↗

* Add a file * Will create folders if needed * @param {String} _path - Path to the folder (start with `./`) * @param {Object} _data - Properties to add to the file * @returns {Object} Created file

(_path = '', _data = {})

Source from the content-addressed store, hash-verified

133 * @returns {Object} Created file
134 */
135 addFile(_path = '', _data = {})
136 {
137 // Errors
138 if(typeof _path !== 'string')
139 {
140 console.warn('addFile: _path should be a string')
141 return false
142 }
143 if(typeof _data !== 'object')
144 {
145 console.warn('addFile: _data should be an object')
146 return false
147 }
148
149 // Set up
150 const path = this.cleanPath(_path)
151 const pathParts = path.split('/')
152 const filePart = pathParts.pop()
153
154 // Create folder
155 const folder = this.addFolder(pathParts.join('/'))
156
157 // Create file
158 const file = {
159 name: filePart
160 }
161
162 // Add data
163 for(const dataKey in _data)
164 {
165 const data = _data[dataKey]
166 file[dataKey] = data
167 }
168
169 // Save
170 folder.files.push(file)
171
172 // Update counts
173 this.updateCounts()
174
175 return file
176 }
177
178 /**
179 * Remove folder

Callers 2

updateFilesFunction · 0.80
createFileFunction · 0.80

Calls 3

cleanPathMethod · 0.95
addFolderMethod · 0.95
updateCountsMethod · 0.95

Tested by

no test coverage detected