@cocreate/file 1.7.2 → 1.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/docs/index.html +0 -1
- package/package.json +5 -5
- package/src/server.js +38 -49
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## [1.7.3](https://github.com/CoCreate-app/CoCreate-file/compare/v1.7.2...v1.7.3) (2023-09-19)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* directory, path, pathname ([9fdad2d](https://github.com/CoCreate-app/CoCreate-file/commit/9fdad2d90d67b08b74d5027999fb1989ca67c853))
|
|
7
|
+
* removed crud.socket.create() as it is handeled automatically duing socket.send ([ca012d0](https://github.com/CoCreate-app/CoCreate-file/commit/ca012d0789b6e66af472de688979b8f21b4f73e7))
|
|
8
|
+
|
|
1
9
|
## [1.7.2](https://github.com/CoCreate-app/CoCreate-file/compare/v1.7.1...v1.7.2) (2023-09-18)
|
|
2
10
|
|
|
3
11
|
|
package/docs/index.html
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/file",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.3",
|
|
4
4
|
"description": "A headless file uploader that uses HTML5 attributes for customization. Allows easy upload of files to server.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"file",
|
|
@@ -59,9 +59,9 @@
|
|
|
59
59
|
"webpack-log": "^3.0.1"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@cocreate/actions": "^1.11.
|
|
63
|
-
"@cocreate/config": "^1.5.
|
|
64
|
-
"@cocreate/render": "^1.27.
|
|
65
|
-
"@cocreate/utils": "^1.24.
|
|
62
|
+
"@cocreate/actions": "^1.11.2",
|
|
63
|
+
"@cocreate/config": "^1.5.2",
|
|
64
|
+
"@cocreate/render": "^1.27.3",
|
|
65
|
+
"@cocreate/utils": "^1.24.2"
|
|
66
66
|
}
|
|
67
67
|
}
|
package/src/server.js
CHANGED
|
@@ -95,11 +95,11 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
|
|
|
95
95
|
prompt: 'Enter the host: '
|
|
96
96
|
},
|
|
97
97
|
prompt: {
|
|
98
|
-
prompt: 'Choose an authentication option: \n1.
|
|
98
|
+
prompt: 'Choose an authentication option: \n1.apikey\n2.Sign In\n',
|
|
99
99
|
choices: {
|
|
100
100
|
'1': {
|
|
101
|
-
|
|
102
|
-
prompt: 'Enter your
|
|
101
|
+
apikey: {
|
|
102
|
+
prompt: 'Enter your apikey: '
|
|
103
103
|
}
|
|
104
104
|
},
|
|
105
105
|
'2': {
|
|
@@ -114,15 +114,11 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
|
|
|
114
114
|
}
|
|
115
115
|
}, null, null, configPath)
|
|
116
116
|
|
|
117
|
-
if (!config.organization_id || !config.
|
|
117
|
+
if (!config.organization_id || !config.apikey && (!config.password || config.email)) {
|
|
118
118
|
console.log('One or more required config params could not be found')
|
|
119
119
|
process.exit()
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
|
|
123
|
-
crud.socket.create(config)
|
|
124
|
-
// config.broadcastBrowser = false
|
|
125
|
-
|
|
126
122
|
if (config.email && config.password) {
|
|
127
123
|
let request = {
|
|
128
124
|
method: 'signIn',
|
|
@@ -132,10 +128,11 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
|
|
|
132
128
|
{ key: 'email', value: config.email, operator: '$eq' },
|
|
133
129
|
{ key: 'password', value: config.password, operator: '$eq' }
|
|
134
130
|
]
|
|
135
|
-
}
|
|
131
|
+
},
|
|
132
|
+
...config
|
|
136
133
|
}
|
|
137
134
|
|
|
138
|
-
let response = await crud.
|
|
135
|
+
let response = await crud.send(request)
|
|
139
136
|
let { success, token } = response;
|
|
140
137
|
|
|
141
138
|
if (success) {
|
|
@@ -165,7 +162,7 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
|
|
|
165
162
|
return
|
|
166
163
|
}
|
|
167
164
|
|
|
168
|
-
async function runFiles(directory, entry, exclude,
|
|
165
|
+
async function runFiles(directory, entry, exclude, Path, directoryName) {
|
|
169
166
|
const entryPath = path.resolve(configDirectoryPath, entry)
|
|
170
167
|
let files = fs.readdirSync(entryPath);
|
|
171
168
|
|
|
@@ -184,7 +181,6 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
|
|
|
184
181
|
const filePath = path.resolve(entryPath, file);
|
|
185
182
|
if (filePath.startsWith(match[i])) {
|
|
186
183
|
skip = false
|
|
187
|
-
console.log('Uploaded: ', filePath)
|
|
188
184
|
break;
|
|
189
185
|
}
|
|
190
186
|
}
|
|
@@ -194,35 +190,35 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
|
|
|
194
190
|
let isDirectory = fs.existsSync(`${entryPath}/${file}`) && fs.lstatSync(`${entryPath}/${file}`).isDirectory();
|
|
195
191
|
let name = file
|
|
196
192
|
let source = ''
|
|
197
|
-
let directoryName = parentDirectory || '';
|
|
198
193
|
|
|
199
194
|
const fileExtension = path.extname(file);
|
|
200
195
|
let mimeType = mimeTypes[fileExtension]
|
|
201
196
|
|
|
202
|
-
if (!directoryName
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
197
|
+
if (!directoryName) {
|
|
198
|
+
if (directory.object && directory.object.directory) {
|
|
199
|
+
if (directory.object.directory === "{{directory}}") {
|
|
200
|
+
directoryName = entry.split('/')
|
|
201
|
+
directoryName = directoryName[directoryName.length - 1]
|
|
202
|
+
} else
|
|
203
|
+
directoryName = directory.object.directory
|
|
204
|
+
} else
|
|
205
|
+
directoryName = '/'
|
|
206
|
+
}
|
|
206
207
|
|
|
207
208
|
if (exclude && exclude.includes(directoryName)) continue
|
|
208
209
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
Path = '/'
|
|
216
|
-
|
|
217
|
-
let pathname = Path + name;
|
|
210
|
+
if (!Path) {
|
|
211
|
+
if (directoryName === '/')
|
|
212
|
+
Path = directoryName
|
|
213
|
+
else
|
|
214
|
+
Path = '/' + directoryName
|
|
215
|
+
}
|
|
218
216
|
|
|
219
|
-
let
|
|
217
|
+
let pathname
|
|
220
218
|
if (Path === '/')
|
|
221
|
-
|
|
222
|
-
else
|
|
223
|
-
|
|
224
|
-
folder = result[result.length - 2];
|
|
225
|
-
}
|
|
219
|
+
pathname = Path + name;
|
|
220
|
+
else
|
|
221
|
+
pathname = Path + '/' + name;
|
|
226
222
|
|
|
227
223
|
if (isDirectory)
|
|
228
224
|
mimeType = "text/directory"
|
|
@@ -230,12 +226,12 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
|
|
|
230
226
|
source = getSource(`${entryPath}/${file}`, mimeType)
|
|
231
227
|
|
|
232
228
|
let values = {
|
|
233
|
-
'{{name}}': name,
|
|
234
|
-
'{{source}}': source,
|
|
235
|
-
'{{directory}}':
|
|
236
|
-
'{{path}}': Path,
|
|
229
|
+
'{{name}}': name || '',
|
|
230
|
+
'{{source}}': source || '',
|
|
231
|
+
'{{directory}}': directoryName || '',
|
|
232
|
+
'{{path}}': Path || '',
|
|
237
233
|
'{{pathname}}': pathname,
|
|
238
|
-
'{{content-type}}': mimeType
|
|
234
|
+
'{{content-type}}': mimeType || ''
|
|
239
235
|
}
|
|
240
236
|
|
|
241
237
|
let object = { ...directory.object }
|
|
@@ -244,7 +240,7 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
|
|
|
244
240
|
if (!object.src)
|
|
245
241
|
object.src = "{{source}}"
|
|
246
242
|
if (!object.directory)
|
|
247
|
-
object.directory = "
|
|
243
|
+
object.directory = "{{directory}}"
|
|
248
244
|
if (!object.path)
|
|
249
245
|
object.path = "{{path}}"
|
|
250
246
|
if (!object.pathname)
|
|
@@ -264,16 +260,7 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
|
|
|
264
260
|
let variables = directory.object[key].match(/{{([A-Za-z0-9_.,\[\]\-\/ ]*)}}/g);
|
|
265
261
|
if (variables) {
|
|
266
262
|
for (let variable of variables) {
|
|
267
|
-
|
|
268
|
-
if (folder)
|
|
269
|
-
newObject.object[key] = values[variable]
|
|
270
|
-
else
|
|
271
|
-
newObject.object[key] = newObject.object[key].replace(variable, '');
|
|
272
|
-
}
|
|
273
|
-
else if (isDirectory && variable == '{{source}}')
|
|
274
|
-
delete newObject.object[key]
|
|
275
|
-
else
|
|
276
|
-
newObject.object[key] = newObject.object[key].replace(variable, values[variable]);
|
|
263
|
+
newObject.object[key] = newObject.object[key].replace(variable, values[variable]);
|
|
277
264
|
}
|
|
278
265
|
}
|
|
279
266
|
|
|
@@ -286,6 +273,8 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
|
|
|
286
273
|
}
|
|
287
274
|
|
|
288
275
|
response = await runStore(newObject);
|
|
276
|
+
console.log(`Uploaded: ${entryPath}/${file}`, `To: ${pathname}`)
|
|
277
|
+
|
|
289
278
|
if (response.error)
|
|
290
279
|
errorLog.push(response.error)
|
|
291
280
|
|
|
@@ -296,7 +285,7 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
|
|
|
296
285
|
else
|
|
297
286
|
newEntry = entry + '/' + name
|
|
298
287
|
|
|
299
|
-
await runFiles(directory, newEntry, exclude, pathname)
|
|
288
|
+
await runFiles(directory, newEntry, exclude, pathname, name)
|
|
300
289
|
}
|
|
301
290
|
}
|
|
302
291
|
if (errorLog.length)
|