@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/CHANGELOG.md +35 -0
- package/CoCreate.config.js +2 -2
- package/LICENSE +683 -21
- package/demo/index.html +33 -9
- package/docs/index.html +27 -27
- package/package.json +7 -7
- package/src/client.js +555 -156
- package/src/index.js +22 -0
- package/src/server.js +66 -62
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
|
-
|
|
129
|
+
method: 'signIn',
|
|
130
|
+
array: 'users',
|
|
130
131
|
filter: {
|
|
131
132
|
query: [
|
|
132
|
-
{
|
|
133
|
-
{
|
|
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(
|
|
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.
|
|
188
|
-
directoryName = directory.
|
|
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
|
|
218
|
-
if (!
|
|
219
|
-
|
|
220
|
-
if (!
|
|
221
|
-
|
|
222
|
-
if (!
|
|
223
|
-
|
|
224
|
-
if (!
|
|
225
|
-
|
|
226
|
-
if (!
|
|
227
|
-
|
|
228
|
-
if (!
|
|
229
|
-
|
|
230
|
-
if (!
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
let
|
|
234
|
-
|
|
235
|
-
|
|
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.
|
|
238
|
-
if (typeof directory.
|
|
238
|
+
for (const key of Object.keys(directory.object)) {
|
|
239
|
+
if (typeof directory.object[key] == 'string') {
|
|
239
240
|
|
|
240
|
-
let variables = directory.
|
|
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
|
|
246
|
+
newObject.object[key] = values[variable]
|
|
246
247
|
else
|
|
247
|
-
object
|
|
248
|
+
newObject.object[key] = newObject.object[key].replace(variable, '');
|
|
248
249
|
}
|
|
249
250
|
else if (isDirectory && variable == '{{source}}')
|
|
250
|
-
delete object
|
|
251
|
+
delete newObject.object[key]
|
|
251
252
|
else
|
|
252
|
-
object
|
|
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.
|
|
260
|
-
|
|
261
|
-
query: [{
|
|
260
|
+
if (!newObject.object._id)
|
|
261
|
+
newObject.filter = {
|
|
262
|
+
query: [{ key: 'path', value: pathName, operator: '$eq' }]
|
|
262
263
|
}
|
|
263
264
|
|
|
264
|
-
response = await runStore(
|
|
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 {
|
|
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 (
|
|
310
|
-
if (!
|
|
311
|
-
|
|
310
|
+
if (array) {
|
|
311
|
+
if (!object)
|
|
312
|
+
object = {};
|
|
312
313
|
else
|
|
313
|
-
for (const key of Object.keys(
|
|
314
|
-
if (typeof
|
|
314
|
+
for (const key of Object.keys(object)) {
|
|
315
|
+
if (typeof object[key] != 'string')
|
|
315
316
|
continue
|
|
316
317
|
|
|
317
|
-
let variables =
|
|
318
|
+
let variables = object[key].match(/{{([A-Za-z0-9_.,\[\]\-\/ ]*)}}/g);
|
|
318
319
|
if (variables) {
|
|
319
|
-
keys.set(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
|
-
//
|
|
341
|
+
// object[key] = object[key].replace(variable, content);
|
|
341
342
|
}
|
|
342
343
|
}
|
|
343
|
-
|
|
344
|
+
object[key] = value
|
|
344
345
|
}
|
|
345
346
|
|
|
346
347
|
}
|
|
347
348
|
|
|
348
|
-
let data = {
|
|
349
|
-
if (!
|
|
349
|
+
let data = { array, object }
|
|
350
|
+
if (!object._id && object.path)
|
|
350
351
|
data.filter = {
|
|
351
|
-
query: [{
|
|
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.
|
|
361
|
+
if (response.object && response.object[0] && response.object[0]._id) {
|
|
361
362
|
for (const [key, value] of keys) {
|
|
362
|
-
source.
|
|
363
|
+
source.object[key] = value
|
|
363
364
|
}
|
|
364
|
-
source.
|
|
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.
|
|
381
|
-
response = await crud.
|
|
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.
|
|
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
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
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
|
+
}
|