@cocreate/file 1.7.0 → 1.7.2

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,20 @@
1
+ ## [1.7.2](https://github.com/CoCreate-app/CoCreate-file/compare/v1.7.1...v1.7.2) (2023-09-18)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Add path and pathname ([8dda8ed](https://github.com/CoCreate-app/CoCreate-file/commit/8dda8edb80c4dca324d6250ef5eb2a8588aa73ab))
7
+ * Update CoCreate depndencies to latest versions ([955f3b2](https://github.com/CoCreate-app/CoCreate-file/commit/955f3b2567d6cbb288c25e93f4dd8fa9adc96a27))
8
+
9
+ ## [1.7.1](https://github.com/CoCreate-app/CoCreate-file/compare/v1.7.0...v1.7.1) (2023-09-17)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * renamed filter to $filter ([c8e8390](https://github.com/CoCreate-app/CoCreate-file/commit/c8e83901429d2c370b327449a9f7f0081b03e6fd))
15
+ * update broadcast to broadcastSender false ([b93ca93](https://github.com/CoCreate-app/CoCreate-file/commit/b93ca93f6b1bff1b1052c841f63919f4156e551e))
16
+ * update data.filter to data.$filter, supports data.object.$filter to ad filters per object ([7ccb455](https://github.com/CoCreate-app/CoCreate-file/commit/7ccb45521a8af3c67587c756c905d7ed4a557a60))
17
+
1
18
  # [1.7.0](https://github.com/CoCreate-app/CoCreate-file/compare/v1.6.3...v1.7.0) (2023-09-07)
2
19
 
3
20
 
@@ -8,18 +8,17 @@ 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
  ]
25
- }
24
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/file",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
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.1",
63
+ "@cocreate/config": "^1.5.1",
64
+ "@cocreate/render": "^1.27.2",
65
+ "@cocreate/utils": "^1.24.1"
66
66
  }
67
67
  }
package/src/client.js CHANGED
@@ -15,10 +15,12 @@
15
15
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16
16
  ********************************************************************************/
17
17
 
18
- // Commercial Licensing Information:
19
- // For commercial use of this software without the copyleft provisions of the AGPLv3,
20
- // you must obtain a commercial license from CoCreate LLC.
21
- // For details, visit <https://cocreate.app/licenses/> or contact us at sales@cocreate.app.
18
+ /**
19
+ * Commercial Licensing Information:
20
+ * For commercial use of this software without the copyleft provisions of the AGPLv3,
21
+ * you must obtain a commercial license from CoCreate LLC.
22
+ * For details, visit <https://cocreate.app/licenses/> or contact us at sales@cocreate.app.
23
+ */
22
24
 
23
25
  import Observer from '@cocreate/observer';
24
26
  import Crud from '@cocreate/crud-client';
@@ -115,8 +117,8 @@ async function fileEvent(event) {
115
117
  files[i] = await readFile(files[i])
116
118
 
117
119
  files[i].directory = handle.directory || '/'
118
- files[i].parentDirectory = handle.parentDirectory || ''
119
- files[i].path = handle.path || '/' + handle.name
120
+ files[i].path = handle.path || '/'
121
+ files[i].pathname = handle.pathname || '/' + handle.name
120
122
  files[i]['content-type'] = files[i].type
121
123
  files[i].input = input
122
124
  files[i].id = await getFileId(files[i])
@@ -157,9 +159,9 @@ async function fileEvent(event) {
157
159
  async function getDirectoryHandles(handle, name) {
158
160
  let handles = [];
159
161
  for await (const entry of handle.values()) {
160
- entry.directory = '/' + name
161
- entry.parentDirectory = name.split("/").pop();
162
- entry.path = '/' + name + '/' + entry.name
162
+ entry.directory = name
163
+ entry.path = '/' + name + '/'
164
+ entry.pathname = '/' + name + '/' + entry.name
163
165
  if (!entry.webkitRelativePath)
164
166
  entry.webkitRelativePath = name
165
167
 
@@ -389,7 +391,7 @@ async function upload(element, data) {
389
391
  let Data = Elements.getObject(input);
390
392
  if (Data.type) {
391
393
  if (input.getFilter)
392
- Data.filter = input.getFilter()
394
+ Data.$filter = input.getFilter()
393
395
 
394
396
  let files = await getFiles(input)
395
397
 
@@ -406,18 +408,16 @@ async function upload(element, data) {
406
408
  }
407
409
  }
408
410
 
409
- let action = 'update' + Data.type.charAt(0).toUpperCase() + Data.type.slice(1)
410
- if (Crud[action]) {
411
- let response = await Crud[action](Data)({
412
- array,
413
- object,
414
- upsert: true
415
- });
416
-
417
- data.push(response)
418
- if (response && (!object || object !== response.object)) {
419
- Elements.setTypeValue(element, response);
420
- }
411
+ Data.method = 'update.' + Data.type
412
+ let response = await Crud.send(Data)({
413
+ array,
414
+ object,
415
+ upsert: true
416
+ });
417
+
418
+ data.push(response)
419
+ if (response && (!object || object !== response.object)) {
420
+ Elements.setTypeValue(element, response);
421
421
  }
422
422
  }
423
423
  }
@@ -471,7 +471,7 @@ async function Import(element, data) {
471
471
  let Data = Elements.getObject(element[i]);
472
472
  if (Data.type) {
473
473
  if (element[i].getFilter)
474
- Data.filter = element[i].getFilter()
474
+ Data.$filter = element[i].getFilter()
475
475
 
476
476
  if (Data.type === 'key')
477
477
  Data.type = 'object'
@@ -482,10 +482,8 @@ async function Import(element, data) {
482
482
 
483
483
  if (data.length) {
484
484
  for (let i = 0; i < data.length; i++) {
485
- let action = 'create' + data[i].type.charAt(0).toUpperCase() + data[i].type.slice(1)
486
- if (Crud[action]) {
487
- data[i] = await Crud[action](data[i])
488
- }
485
+ data[i].method = 'create.' + data[i].type
486
+ data[i] = await Crud.send(data[i])
489
487
  }
490
488
  }
491
489
 
@@ -523,15 +521,14 @@ async function Export(element, data) {
523
521
  let Data = Elements.getObject(element[i]);
524
522
  if (Data.type) {
525
523
  if (element[i].getFilter)
526
- Data.filter = element[i].getFilter()
524
+ Data.$filter = element[i].getFilter()
527
525
 
528
526
  if (Data.type === 'key')
529
527
  Data.type = 'object'
530
- let action = 'read' + Data.type.charAt(0).toUpperCase() + Data.type.slice(1)
531
- if (Crud[action]) {
532
- Data = await Crud[action](Data)
533
- data.push(...Data[Data.type])
534
- }
528
+ Data.method = 'read.' + Data.type
529
+ Data = await Crud.send(Data)
530
+ data.push(...Data[Data.type])
531
+
535
532
  }
536
533
 
537
534
  let queriedElements = queryElements({ element: element[i], prefix: 'export' })
@@ -634,8 +631,8 @@ async function create(directory, type, name, src = "") {
634
631
  }
635
632
 
636
633
  if (directory.input) {
637
- file.directory = directory.path
638
- file.parentDirectory = directory.name
634
+ file.directory = directory.name
635
+ file.pathname = directory.path + '/' + file.name
639
636
  file.path = directory.path + '/' + file.name
640
637
  file.input = directory.input
641
638
  file.handle = handle
package/src/index.js CHANGED
@@ -15,10 +15,12 @@
15
15
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16
16
  ********************************************************************************/
17
17
 
18
- // Commercial Licensing Information:
19
- // For commercial use of this software without the copyleft provisions of the AGPLv3,
20
- // you must obtain a commercial license from CoCreate LLC.
21
- // For details, visit <https://cocreate.app/licenses/> or contact us at sales@cocreate.app.
18
+ /**
19
+ * Commercial Licensing Information:
20
+ * For commercial use of this software without the copyleft provisions of the AGPLv3,
21
+ * you must obtain a commercial license from CoCreate LLC.
22
+ * For details, visit <https://cocreate.app/licenses/> or contact us at sales@cocreate.app.
23
+ */
22
24
 
23
25
  (function (root, factory) {
24
26
  if (typeof define === 'function' && define.amd) {
package/src/server.js CHANGED
@@ -121,13 +121,13 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
121
121
 
122
122
 
123
123
  crud.socket.create(config)
124
- config.broadcast = false
124
+ // config.broadcastBrowser = false
125
125
 
126
126
  if (config.email && config.password) {
127
127
  let request = {
128
128
  method: 'signIn',
129
129
  array: 'users',
130
- filter: {
130
+ $filter: {
131
131
  query: [
132
132
  { key: 'email', value: config.email, operator: '$eq' },
133
133
  { key: 'password', value: config.password, operator: '$eq' }
@@ -195,14 +195,9 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
195
195
  let name = file
196
196
  let source = ''
197
197
  let directoryName = parentDirectory || '';
198
- let parentDirectoryOnly = parentDirectory || '';
199
- let index = parentDirectoryOnly.lastIndexOf('/') + 1
200
- if (parentDirectoryOnly && index) {
201
- parentDirectoryOnly = parentDirectoryOnly.substring(index)
202
- }
198
+
203
199
  const fileExtension = path.extname(file);
204
200
  let mimeType = mimeTypes[fileExtension]
205
- let pathName = '';
206
201
 
207
202
  if (!directoryName && directory.object && directory.object.directory)
208
203
  directoryName = directory.object.directory.replace('{{directory}}', '').trim()
@@ -211,12 +206,23 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
211
206
 
212
207
  if (exclude && exclude.includes(directoryName)) continue
213
208
 
209
+ let Path = '';
214
210
  if (directoryName.endsWith("/"))
215
- pathName = directoryName + name
211
+ Path = directoryName
216
212
  else if (directoryName)
217
- pathName = directoryName + '/' + name
213
+ Path = directoryName + '/'
218
214
  else
219
- pathName = '/' + name
215
+ Path = '/'
216
+
217
+ let pathname = Path + name;
218
+
219
+ let folder = ''
220
+ if (Path === '/')
221
+ folder = Path
222
+ else {
223
+ let result = Path.split('/');
224
+ folder = result[result.length - 2];
225
+ }
220
226
 
221
227
  if (isDirectory)
222
228
  mimeType = "text/directory"
@@ -226,9 +232,9 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
226
232
  let values = {
227
233
  '{{name}}': name,
228
234
  '{{source}}': source,
229
- '{{directory}}': directoryName,
230
- '{{parentDirectory}}': parentDirectoryOnly,
231
- '{{path}}': pathName,
235
+ '{{directory}}': folder,
236
+ '{{path}}': Path,
237
+ '{{pathname}}': pathname,
232
238
  '{{content-type}}': mimeType
233
239
  }
234
240
 
@@ -239,10 +245,10 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
239
245
  object.src = "{{source}}"
240
246
  if (!object.directory)
241
247
  object.directory = "/{{directory}}"
242
- if (!object.parentDirectory)
243
- object.parentDirectory = "{{parentDirectory}}"
244
248
  if (!object.path)
245
249
  object.path = "{{path}}"
250
+ if (!object.pathname)
251
+ object.pathname = "{{pathname}}"
246
252
  if (!object["content-type"])
247
253
  object["content-type"] = '{{content-type}}'
248
254
  if (!object.public && object.public != false && object.public != 'false')
@@ -259,7 +265,7 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
259
265
  if (variables) {
260
266
  for (let variable of variables) {
261
267
  if (variable == '{{directory}}') {
262
- if (parentDirectory)
268
+ if (folder)
263
269
  newObject.object[key] = values[variable]
264
270
  else
265
271
  newObject.object[key] = newObject.object[key].replace(variable, '');
@@ -275,22 +281,22 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
275
281
  }
276
282
 
277
283
  if (!newObject.object._id)
278
- newObject.filter = {
279
- query: [{ key: 'path', value: pathName, operator: '$eq' }]
284
+ newObject.$filter = {
285
+ query: [{ key: 'pathname', value: pathname, operator: '$or' }]
280
286
  }
281
287
 
282
288
  response = await runStore(newObject);
283
289
  if (response.error)
284
290
  errorLog.push(response.error)
285
291
 
286
- if (isDirectory && pathName) {
292
+ if (isDirectory && pathname) {
287
293
  let newEntry
288
294
  if (entry.endsWith("/"))
289
295
  newEntry = entry + name
290
296
  else
291
297
  newEntry = entry + '/' + name
292
298
 
293
- await runFiles(directory, newEntry, exclude, pathName)
299
+ await runFiles(directory, newEntry, exclude, pathname)
294
300
  }
295
301
  }
296
302
  if (errorLog.length)
@@ -377,9 +383,9 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
377
383
  }
378
384
 
379
385
  let data = { array, object }
380
- if (!object._id && object.path)
381
- data.filter = {
382
- query: [{ key: 'path', value: object.path, operator: '$eq' }]
386
+ if (!object._id && object.pathname)
387
+ data.$filter = {
388
+ query: [{ key: 'pathname', value: object.pathname, operator: '$or' }]
383
389
  }
384
390
 
385
391
  if (match.length && isMatch)
@@ -408,7 +414,7 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
408
414
  async function runStore(data) {
409
415
  try {
410
416
  let response;
411
- if (!data.object._id && !data.filter) {
417
+ if (!data.object._id && !data.$filter) {
412
418
  response = await crud.send({
413
419
  method: 'create.object',
414
420
  ...config,