@cocreate/file 1.7.1 → 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 CHANGED
@@ -1,3 +1,19 @@
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
+
9
+ ## [1.7.2](https://github.com/CoCreate-app/CoCreate-file/compare/v1.7.1...v1.7.2) (2023-09-18)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * Add path and pathname ([8dda8ed](https://github.com/CoCreate-app/CoCreate-file/commit/8dda8edb80c4dca324d6250ef5eb2a8588aa73ab))
15
+ * Update CoCreate depndencies to latest versions ([955f3b2](https://github.com/CoCreate-app/CoCreate-file/commit/955f3b2567d6cbb288c25e93f4dd8fa9adc96a27))
16
+
1
17
  ## [1.7.1](https://github.com/CoCreate-app/CoCreate-file/compare/v1.7.0...v1.7.1) (2023-09-17)
2
18
 
3
19
 
@@ -8,17 +8,16 @@ module.exports = {
8
8
  "object": {
9
9
  "_id": "61a12db2a8b6b4001a9f5a2e",
10
10
  "name": "index.html",
11
- "path": "/docs/file/index.html",
11
+ "path": "/docs/file/",
12
+ "pathname": "/docs/file/index.html",
12
13
  "src": "{{./docs/index.html}}",
13
14
  "host": [
14
15
  "*",
15
16
  "general.cocreate.app"
16
17
  ],
17
- "directory": "/docs/file",
18
- "parentDirectory": "{{parentDirectory}}",
18
+ "directory": "file",
19
19
  "content-type": "{{content-type}}",
20
- "public": "true",
21
- "website_id": "644d4bff8036fb9d1d1fd69c"
20
+ "public": "true"
22
21
  }
23
22
  }
24
23
  ]
package/docs/index.html CHANGED
@@ -377,7 +377,6 @@
377
377
  src="/assets/svg/pencil-alt.svg"></i>
378
378
  </button>
379
379
  </main>
380
- <script src="/apikey.js"></script>
381
380
  <script src="https://CoCreate.app/dist/CoCreate.js"></script>
382
381
  </body>
383
382
  </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/file",
3
- "version": "1.7.1",
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.0",
63
- "@cocreate/config": "^1.5.0",
64
- "@cocreate/render": "^1.27.0",
65
- "@cocreate/utils": "^1.24.0"
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/client.js CHANGED
@@ -117,8 +117,8 @@ async function fileEvent(event) {
117
117
  files[i] = await readFile(files[i])
118
118
 
119
119
  files[i].directory = handle.directory || '/'
120
- files[i].parentDirectory = handle.parentDirectory || ''
121
- files[i].path = handle.path || '/' + handle.name
120
+ files[i].path = handle.path || '/'
121
+ files[i].pathname = handle.pathname || '/' + handle.name
122
122
  files[i]['content-type'] = files[i].type
123
123
  files[i].input = input
124
124
  files[i].id = await getFileId(files[i])
@@ -159,9 +159,9 @@ async function fileEvent(event) {
159
159
  async function getDirectoryHandles(handle, name) {
160
160
  let handles = [];
161
161
  for await (const entry of handle.values()) {
162
- entry.directory = '/' + name
163
- entry.parentDirectory = name.split("/").pop();
164
- entry.path = '/' + name + '/' + entry.name
162
+ entry.directory = name
163
+ entry.path = '/' + name + '/'
164
+ entry.pathname = '/' + name + '/' + entry.name
165
165
  if (!entry.webkitRelativePath)
166
166
  entry.webkitRelativePath = name
167
167
 
@@ -631,8 +631,8 @@ async function create(directory, type, name, src = "") {
631
631
  }
632
632
 
633
633
  if (directory.input) {
634
- file.directory = directory.path
635
- file.parentDirectory = directory.name
634
+ file.directory = directory.name
635
+ file.pathname = directory.path + '/' + file.name
636
636
  file.path = directory.path + '/' + file.name
637
637
  file.input = directory.input
638
638
  file.handle = handle
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.key\n2.Sign In\n',
98
+ prompt: 'Choose an authentication option: \n1.apikey\n2.Sign In\n',
99
99
  choices: {
100
100
  '1': {
101
- key: {
102
- prompt: 'Enter your key: '
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.host || !config.key && (!config.password || config.email)) {
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.broadcastSender = 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.socket.send(request)
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, parentDirectory = '') {
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,29 +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
- let parentDirectoryOnly = parentDirectory || '';
199
- let index = parentDirectoryOnly.lastIndexOf('/') + 1
200
- if (parentDirectoryOnly && index) {
201
- parentDirectoryOnly = parentDirectoryOnly.substring(index)
202
- }
193
+
203
194
  const fileExtension = path.extname(file);
204
195
  let mimeType = mimeTypes[fileExtension]
205
- let pathName = '';
206
196
 
207
- if (!directoryName && directory.object && directory.object.directory)
208
- directoryName = directory.object.directory.replace('{{directory}}', '').trim()
209
- else if (!directoryName)
210
- directoryName = '/'
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
+ }
211
207
 
212
208
  if (exclude && exclude.includes(directoryName)) continue
213
209
 
214
- if (directoryName.endsWith("/"))
215
- pathName = directoryName + name
216
- else if (directoryName)
217
- pathName = directoryName + '/' + name
210
+ if (!Path) {
211
+ if (directoryName === '/')
212
+ Path = directoryName
213
+ else
214
+ Path = '/' + directoryName
215
+ }
216
+
217
+ let pathname
218
+ if (Path === '/')
219
+ pathname = Path + name;
218
220
  else
219
- pathName = '/' + name
221
+ pathname = Path + '/' + name;
220
222
 
221
223
  if (isDirectory)
222
224
  mimeType = "text/directory"
@@ -224,12 +226,12 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
224
226
  source = getSource(`${entryPath}/${file}`, mimeType)
225
227
 
226
228
  let values = {
227
- '{{name}}': name,
228
- '{{source}}': source,
229
- '{{directory}}': directoryName,
230
- '{{parentDirectory}}': parentDirectoryOnly,
231
- '{{path}}': pathName,
232
- '{{content-type}}': mimeType
229
+ '{{name}}': name || '',
230
+ '{{source}}': source || '',
231
+ '{{directory}}': directoryName || '',
232
+ '{{path}}': Path || '',
233
+ '{{pathname}}': pathname,
234
+ '{{content-type}}': mimeType || ''
233
235
  }
234
236
 
235
237
  let object = { ...directory.object }
@@ -238,11 +240,11 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
238
240
  if (!object.src)
239
241
  object.src = "{{source}}"
240
242
  if (!object.directory)
241
- object.directory = "/{{directory}}"
242
- if (!object.parentDirectory)
243
- object.parentDirectory = "{{parentDirectory}}"
243
+ object.directory = "{{directory}}"
244
244
  if (!object.path)
245
245
  object.path = "{{path}}"
246
+ if (!object.pathname)
247
+ object.pathname = "{{pathname}}"
246
248
  if (!object["content-type"])
247
249
  object["content-type"] = '{{content-type}}'
248
250
  if (!object.public && object.public != false && object.public != 'false')
@@ -258,16 +260,7 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
258
260
  let variables = directory.object[key].match(/{{([A-Za-z0-9_.,\[\]\-\/ ]*)}}/g);
259
261
  if (variables) {
260
262
  for (let variable of variables) {
261
- if (variable == '{{directory}}') {
262
- if (parentDirectory)
263
- newObject.object[key] = values[variable]
264
- else
265
- newObject.object[key] = newObject.object[key].replace(variable, '');
266
- }
267
- else if (isDirectory && variable == '{{source}}')
268
- delete newObject.object[key]
269
- else
270
- newObject.object[key] = newObject.object[key].replace(variable, values[variable]);
263
+ newObject.object[key] = newObject.object[key].replace(variable, values[variable]);
271
264
  }
272
265
  }
273
266
 
@@ -276,21 +269,23 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
276
269
 
277
270
  if (!newObject.object._id)
278
271
  newObject.$filter = {
279
- query: [{ key: 'path', value: pathName, operator: '$or' }]
272
+ query: [{ key: 'pathname', value: pathname, operator: '$or' }]
280
273
  }
281
274
 
282
275
  response = await runStore(newObject);
276
+ console.log(`Uploaded: ${entryPath}/${file}`, `To: ${pathname}`)
277
+
283
278
  if (response.error)
284
279
  errorLog.push(response.error)
285
280
 
286
- if (isDirectory && pathName) {
281
+ if (isDirectory && pathname) {
287
282
  let newEntry
288
283
  if (entry.endsWith("/"))
289
284
  newEntry = entry + name
290
285
  else
291
286
  newEntry = entry + '/' + name
292
287
 
293
- await runFiles(directory, newEntry, exclude, pathName)
288
+ await runFiles(directory, newEntry, exclude, pathname, name)
294
289
  }
295
290
  }
296
291
  if (errorLog.length)
@@ -377,9 +372,9 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
377
372
  }
378
373
 
379
374
  let data = { array, object }
380
- if (!object._id && object.path)
375
+ if (!object._id && object.pathname)
381
376
  data.$filter = {
382
- query: [{ key: 'path', value: object.path, operator: '$or' }]
377
+ query: [{ key: 'pathname', value: object.pathname, operator: '$or' }]
383
378
  }
384
379
 
385
380
  if (match.length && isMatch)