@cocreate/file 1.3.11 → 1.5.0

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/src/index.js CHANGED
@@ -1,3 +1,25 @@
1
+ /********************************************************************************
2
+ * Copyright (C) 2023 CoCreate and Contributors.
3
+ *
4
+ * This program is free software: you can redistribute it and/or modify
5
+ * it under the terms of the GNU Affero General Public License as published
6
+ * by the Free Software Foundation, either version 3 of the License, or
7
+ * (at your option) any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU Affero General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Affero General Public License
15
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
16
+ ********************************************************************************/
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.
22
+
1
23
  (function (root, factory) {
2
24
  if (typeof define === 'function' && define.amd) {
3
25
  define(["./client"], function (CoCreateFile) {
package/src/server.js CHANGED
@@ -126,16 +126,17 @@ module.exports = async function file(CoCreateConfig) {
126
126
 
127
127
  if (config.email && config.password) {
128
128
  let request = {
129
- collection: 'users',
129
+ method: 'signIn',
130
+ array: 'users',
130
131
  filter: {
131
132
  query: [
132
- { name: 'email', value: config.email, operator: '$eq' },
133
- { name: 'password', value: config.password, operator: '$eq' }
133
+ { key: 'email', value: config.email, operator: '$eq' },
134
+ { key: 'password', value: config.password, operator: '$eq' }
134
135
  ]
135
136
  }
136
137
  }
137
138
 
138
- let response = await crud.socket.send('signIn', request)
139
+ let response = await crud.socket.send(request)
139
140
  let { success, token } = response;
140
141
 
141
142
  if (success) {
@@ -184,8 +185,8 @@ module.exports = async function file(CoCreateConfig) {
184
185
  let mimeType = mimeTypes[fileExtension]
185
186
  let pathName = '';
186
187
 
187
- if (!directoryName && directory.document && directory.document.directory)
188
- directoryName = directory.document.directory.replace('{{directory}}', '').trim()
188
+ if (!directoryName && directory.object && directory.object.directory)
189
+ directoryName = directory.object.directory.replace('{{directory}}', '').trim()
189
190
  else if (!directoryName)
190
191
  directoryName = '/'
191
192
 
@@ -214,54 +215,54 @@ module.exports = async function file(CoCreateConfig) {
214
215
  '{{content-type}}': mimeType
215
216
  }
216
217
 
217
- let document = { ...directory.document }
218
- if (!document.name)
219
- document.name = "{{name}}"
220
- if (!document.src)
221
- document.src = "{{source}}"
222
- if (!document.directory)
223
- document.directory = "/{{directory}}"
224
- if (!document.parentDirectory)
225
- document.parentDirectory = "{{parentDirectory}}"
226
- if (!document.path)
227
- document.path = "{{path}}"
228
- if (!document["content-type"])
229
- document["content-type"] = '{{content-type}}'
230
- if (!document.public && document.public != false && document.public != 'false')
231
- document.public = 'true'
232
-
233
- let object = {
234
- collection: directory.collection || 'files',
235
- document
218
+ let object = { ...directory.object }
219
+ if (!object.name)
220
+ object.name = "{{name}}"
221
+ if (!object.src)
222
+ object.src = "{{source}}"
223
+ if (!object.directory)
224
+ object.directory = "/{{directory}}"
225
+ if (!object.parentDirectory)
226
+ object.parentDirectory = "{{parentDirectory}}"
227
+ if (!object.path)
228
+ object.path = "{{path}}"
229
+ if (!object["content-type"])
230
+ object["content-type"] = '{{content-type}}'
231
+ if (!object.public && object.public != false && object.public != 'false')
232
+ object.public = 'true'
233
+
234
+ let newObject = {
235
+ array: directory.array || 'files',
236
+ object
236
237
  }
237
- for (const key of Object.keys(directory.document)) {
238
- if (typeof directory.document[key] == 'string') {
238
+ for (const key of Object.keys(directory.object)) {
239
+ if (typeof directory.object[key] == 'string') {
239
240
 
240
- let variables = directory.document[key].match(/{{([A-Za-z0-9_.,\[\]\-\/ ]*)}}/g);
241
+ let variables = directory.object[key].match(/{{([A-Za-z0-9_.,\[\]\-\/ ]*)}}/g);
241
242
  if (variables) {
242
243
  for (let variable of variables) {
243
244
  if (variable == '{{directory}}') {
244
245
  if (parentDirectory)
245
- object.document[key] = values[variable]
246
+ newObject.object[key] = values[variable]
246
247
  else
247
- object.document[key] = object.document[key].replace(variable, '');
248
+ newObject.object[key] = newObject.object[key].replace(variable, '');
248
249
  }
249
250
  else if (isDirectory && variable == '{{source}}')
250
- delete object.document[key]
251
+ delete newObject.object[key]
251
252
  else
252
- object.document[key] = object.document[key].replace(variable, values[variable]);
253
+ newObject.object[key] = newObject.object[key].replace(variable, values[variable]);
253
254
  }
254
255
  }
255
256
 
256
257
  }
257
258
  }
258
259
 
259
- if (!object.document._id)
260
- object.filter = {
261
- query: [{ name: 'path', value: pathName, operator: '$eq' }]
260
+ if (!newObject.object._id)
261
+ newObject.filter = {
262
+ query: [{ key: 'path', value: pathName, operator: '$eq' }]
262
263
  }
263
264
 
264
- response = await runStore(object);
265
+ response = await runStore(newObject);
265
266
  if (response.error)
266
267
  errorLog.push(response.error)
267
268
 
@@ -299,24 +300,24 @@ module.exports = async function file(CoCreateConfig) {
299
300
  let updatedSources = [];
300
301
 
301
302
  for (let i = 0; i < sources.length; i++) {
302
- const { collection, document } = sources[i];
303
+ const { array, object } = sources[i];
303
304
 
304
305
  let source = { ...sources[i] };
305
306
  let keys = new Map()
306
307
  let response = {};
307
308
 
308
309
  try {
309
- if (collection) {
310
- if (!document)
311
- document = {};
310
+ if (array) {
311
+ if (!object)
312
+ object = {};
312
313
  else
313
- for (const key of Object.keys(document)) {
314
- if (typeof document[key] != 'string')
314
+ for (const key of Object.keys(object)) {
315
+ if (typeof object[key] != 'string')
315
316
  continue
316
317
 
317
- let variables = document[key].match(/{{([A-Za-z0-9_.,\[\]\-\/ ]*)}}/g);
318
+ let variables = object[key].match(/{{([A-Za-z0-9_.,\[\]\-\/ ]*)}}/g);
318
319
  if (variables) {
319
- keys.set(key, `${document[key]}`)
320
+ keys.set(key, `${object[key]}`)
320
321
  let value = ""
321
322
  for (let variable of variables) {
322
323
  let entry = /{{\s*([\w\W]+)\s*}}/g.exec(variable);
@@ -337,18 +338,18 @@ module.exports = async function file(CoCreateConfig) {
337
338
  let content = new Buffer.from(binary).toString(read_type);
338
339
  if (content)
339
340
  value += content
340
- // document[key] = document[key].replace(variable, content);
341
+ // object[key] = object[key].replace(variable, content);
341
342
  }
342
343
  }
343
- document[key] = value
344
+ object[key] = value
344
345
  }
345
346
 
346
347
  }
347
348
 
348
- let data = { collection, document }
349
- if (!document._id && document.path)
349
+ let data = { array, object }
350
+ if (!object._id && object.path)
350
351
  data.filter = {
351
- query: [{ name: 'path', value: document.path, operator: '$eq' }]
352
+ query: [{ key: 'path', value: object.path, operator: '$eq' }]
352
353
  }
353
354
 
354
355
  response = await runStore(data);
@@ -357,11 +358,11 @@ module.exports = async function file(CoCreateConfig) {
357
358
  console.log(err)
358
359
  process.exit()
359
360
  }
360
- if (response.document && response.document[0] && response.document[0]._id) {
361
+ if (response.object && response.object[0] && response.object[0]._id) {
361
362
  for (const [key, value] of keys) {
362
- source.document[key] = value
363
+ source.object[key] = value
363
364
  }
364
- source.document._id = response.document[0]._id
365
+ source.object._id = response.object[0]._id
365
366
  } else {
366
367
  console.log('_id could not be found')
367
368
  process.exit()
@@ -377,13 +378,15 @@ module.exports = async function file(CoCreateConfig) {
377
378
  async function runStore(data) {
378
379
  try {
379
380
  let response;
380
- if (!data.document._id && !data.filter) {
381
- response = await crud.createDocument({
381
+ if (!data.object._id && !data.filter) {
382
+ response = await crud.send({
383
+ method: 'create.object',
382
384
  ...config,
383
385
  ...data
384
386
  })
385
387
  } else {
386
- response = await crud.updateDocument({
388
+ response = await crud.send({
389
+ method: 'update.object',
387
390
  ...config,
388
391
  ...data,
389
392
  upsert: true
@@ -410,13 +413,14 @@ module.exports = async function file(CoCreateConfig) {
410
413
 
411
414
  newConfig.sources = sources
412
415
 
413
- newConfig.repositories.forEach(obj => {
414
- for (const key in obj) {
415
- if (!["path", "repo", "exclude"].includes(key)) {
416
- delete obj[key];
416
+ if (newConfig.repositories)
417
+ newConfig.repositories.forEach(obj => {
418
+ for (const key in obj) {
419
+ if (!["path", "repo", "exclude"].includes(key)) {
420
+ delete obj[key];
421
+ }
417
422
  }
418
- }
419
- });
423
+ });
420
424
 
421
425
  delete newConfig.url
422
426
  delete newConfig.broadcast
@@ -433,4 +437,4 @@ module.exports = async function file(CoCreateConfig) {
433
437
  }
434
438
 
435
439
  run()
436
- }
440
+ }