@galadrim/galadmin 0.1.225 → 0.1.227
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/README.md +25 -0
- package/dist/api.js +359 -172
- package/dist/api.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/config.d.ts +6 -0
- package/package.json +2 -1
- package/src/api.ts +1227 -913
- package/src/front/ckeditor5-build/node_modules/semver/bin/semver.js +0 -0
- package/src/front/yarn.lock +10795 -0
- package/src/types/config.ts +6 -0
- package/src/front/ckeditor5-build/node_modules/.bin/semver +0 -12
- package/src/front/ckeditor5-build/node_modules/.bin/semver.cmd +0 -17
- package/src/front/ckeditor5-build/node_modules/.bin/semver.ps1 +0 -28
package/dist/api.js
CHANGED
|
@@ -18,6 +18,7 @@ const path = require("path");
|
|
|
18
18
|
const crypto = require("crypto");
|
|
19
19
|
const mime = require("mime");
|
|
20
20
|
const aws_sdk_1 = require("aws-sdk");
|
|
21
|
+
const storage_1 = require("@google-cloud/storage");
|
|
21
22
|
const image_size_1 = require("image-size");
|
|
22
23
|
const serializeJs = require("serialize-javascript");
|
|
23
24
|
const SftpClient = require("ssh2-sftp-client");
|
|
@@ -28,7 +29,7 @@ const axios_1 = require("axios");
|
|
|
28
29
|
const uuid_1 = require("uuid");
|
|
29
30
|
function generateUniqueIdForObject(obj) {
|
|
30
31
|
const str = JSON.stringify(obj);
|
|
31
|
-
const hash = crypto.createHash(
|
|
32
|
+
const hash = crypto.createHash("sha256").update(str).digest("hex");
|
|
32
33
|
return hash;
|
|
33
34
|
}
|
|
34
35
|
exports.default = (db, config, user) => {
|
|
@@ -49,7 +50,8 @@ exports.default = (db, config, user) => {
|
|
|
49
50
|
const columns = params.columns;
|
|
50
51
|
let isNewCondition = true;
|
|
51
52
|
for (let i in columns) {
|
|
52
|
-
if (columns[i].searchable !== false &&
|
|
53
|
+
if (columns[i].searchable !== false &&
|
|
54
|
+
(columns[i].searchableName || columns[i].name)) {
|
|
53
55
|
if (queryString.length == 0) {
|
|
54
56
|
queryString += " WHERE (";
|
|
55
57
|
}
|
|
@@ -63,7 +65,10 @@ exports.default = (db, config, user) => {
|
|
|
63
65
|
queryString += columns[i].searchableName;
|
|
64
66
|
}
|
|
65
67
|
else if (columns[i].name) {
|
|
66
|
-
queryString += columns[i].name
|
|
68
|
+
queryString += columns[i].name
|
|
69
|
+
.split(".")
|
|
70
|
+
.map((x) => (db.dbType === "POSTGRESQL" ? x : "`" + x + "`"))
|
|
71
|
+
.join(".");
|
|
67
72
|
}
|
|
68
73
|
queryString += " LIKE '%" + params.query.replace(/'/g, "\\'") + "%'";
|
|
69
74
|
isNewCondition = false;
|
|
@@ -72,7 +77,8 @@ exports.default = (db, config, user) => {
|
|
|
72
77
|
queryString += ")";
|
|
73
78
|
}
|
|
74
79
|
const limit = params.allRecords ? 999999 : parseInt(params.limit);
|
|
75
|
-
const query = params.customQuery ||
|
|
80
|
+
const query = params.customQuery ||
|
|
81
|
+
`SELECT
|
|
76
82
|
${params.selectExpression || "*"}
|
|
77
83
|
FROM ${params.table}
|
|
78
84
|
${params.join || ""}
|
|
@@ -84,38 +90,41 @@ exports.default = (db, config, user) => {
|
|
|
84
90
|
if (err) {
|
|
85
91
|
console.error(err);
|
|
86
92
|
return {
|
|
87
|
-
error: err
|
|
93
|
+
error: err,
|
|
88
94
|
};
|
|
89
95
|
}
|
|
90
96
|
let count = undefined;
|
|
91
97
|
if (computeCount) {
|
|
92
98
|
const { err: countErr, rows: countRows } = await db.query(`SELECT COUNT(*) AS count FROM (${query}) s`);
|
|
93
99
|
if (countErr) {
|
|
94
|
-
|
|
100
|
+
const { rows: allRows } = await db.query(query);
|
|
101
|
+
count = allRows.length;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
count = ((_a = countRows === null || countRows === void 0 ? void 0 : countRows[0]) === null || _a === void 0 ? void 0 : _a.count) || 0;
|
|
95
105
|
}
|
|
96
|
-
count = ((_a = countRows === null || countRows === void 0 ? void 0 : countRows[0]) === null || _a === void 0 ? void 0 : _a.count) || 0;
|
|
97
106
|
}
|
|
98
107
|
return {
|
|
99
108
|
rows,
|
|
100
109
|
queryString,
|
|
101
110
|
input: {
|
|
102
111
|
query,
|
|
103
|
-
params
|
|
112
|
+
params,
|
|
104
113
|
},
|
|
105
|
-
count
|
|
114
|
+
count,
|
|
106
115
|
};
|
|
107
116
|
}
|
|
108
117
|
async function findRecordByPosition(params) {
|
|
109
118
|
return await getRecords(Object.assign(params, {
|
|
110
119
|
page: parseInt(params.position) + parseInt(params.offset),
|
|
111
|
-
limit: 1
|
|
120
|
+
limit: 1,
|
|
112
121
|
}));
|
|
113
122
|
}
|
|
114
|
-
app.get(
|
|
123
|
+
app.get("/config", async (req, res) => {
|
|
115
124
|
try {
|
|
116
125
|
const { mysql, auth, sessionSecret } = config, safeConfig = __rest(config, ["mysql", "auth", "sessionSecret"]);
|
|
117
126
|
res.send({
|
|
118
|
-
config: serializeJs(safeConfig)
|
|
127
|
+
config: serializeJs(safeConfig),
|
|
119
128
|
});
|
|
120
129
|
}
|
|
121
130
|
catch (e) {
|
|
@@ -125,7 +134,7 @@ exports.default = (db, config, user) => {
|
|
|
125
134
|
});
|
|
126
135
|
app.get("/customComponent", async (req, res) => {
|
|
127
136
|
try {
|
|
128
|
-
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname,
|
|
137
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, "../src/front/package.json"), "utf-8"));
|
|
129
138
|
const external = Object.keys(pkg.dependencies || {});
|
|
130
139
|
const bundle = await rollup.rollup({
|
|
131
140
|
input: path.join(__dirname, "../../", req.query.componentPath),
|
|
@@ -133,26 +142,29 @@ exports.default = (db, config, user) => {
|
|
|
133
142
|
(0, plugin_node_resolve_1.default)(),
|
|
134
143
|
(0, plugin_babel_1.default)({
|
|
135
144
|
configFile: path.join(__dirname, "../babel.config"),
|
|
136
|
-
babelHelpers: "bundled"
|
|
137
|
-
})
|
|
145
|
+
babelHelpers: "bundled",
|
|
146
|
+
}),
|
|
138
147
|
],
|
|
139
|
-
external
|
|
148
|
+
external,
|
|
149
|
+
});
|
|
150
|
+
const { output } = await bundle.generate({
|
|
151
|
+
format: "cjs",
|
|
152
|
+
exports: "auto",
|
|
140
153
|
});
|
|
141
|
-
const { output } = await bundle.generate({ format: 'cjs', exports: 'auto' });
|
|
142
154
|
res.send(output[0].code);
|
|
143
155
|
}
|
|
144
156
|
catch (err) {
|
|
145
157
|
console.error(err);
|
|
146
158
|
}
|
|
147
159
|
});
|
|
148
|
-
app.post(
|
|
160
|
+
app.post("/adjacentRecordId", async function (req, res, next) {
|
|
149
161
|
const { rows, error } = await findRecordByPosition(req.body);
|
|
150
162
|
if (error) {
|
|
151
163
|
return res.status(500).send(error);
|
|
152
164
|
}
|
|
153
165
|
const recordId = rows[0] ? rows[0][req.body.primaryId] : null;
|
|
154
166
|
res.send({
|
|
155
|
-
recordId: recordId
|
|
167
|
+
recordId: recordId,
|
|
156
168
|
});
|
|
157
169
|
});
|
|
158
170
|
const sqlAnd = (conditions) => {
|
|
@@ -176,26 +188,32 @@ exports.default = (db, config, user) => {
|
|
|
176
188
|
return result;
|
|
177
189
|
}
|
|
178
190
|
};
|
|
179
|
-
app.post(
|
|
191
|
+
app.post("/foreignSelectRecords", async (req, res, next) => {
|
|
180
192
|
var _a, _b, _c, _d, _e;
|
|
181
193
|
const view = config.views[req.body.viewIndex];
|
|
182
194
|
const column = [
|
|
183
195
|
...view.columns,
|
|
184
|
-
...(((_c = (_b = (_a = view.recordViewPanels) === null || _a === void 0 ? void 0 : _a.map(x => { var _a; return (_a = x === null || x === void 0 ? void 0 : x.createConfig) === null || _a === void 0 ? void 0 : _a.columns; })) === null || _b === void 0 ? void 0 : _b.filter(x => x)) === null || _c === void 0 ? void 0 : _c.flat()) || [])
|
|
185
|
-
].find(x => x.__id__ === req.body.columnId);
|
|
186
|
-
const queryEscaped = db.dbType === "POSTGRESQL"
|
|
196
|
+
...(((_c = (_b = (_a = view.recordViewPanels) === null || _a === void 0 ? void 0 : _a.map((x) => { var _a; return (_a = x === null || x === void 0 ? void 0 : x.createConfig) === null || _a === void 0 ? void 0 : _a.columns; })) === null || _b === void 0 ? void 0 : _b.filter((x) => x)) === null || _c === void 0 ? void 0 : _c.flat()) || []),
|
|
197
|
+
].find((x) => x.__id__ === req.body.columnId);
|
|
198
|
+
const queryEscaped = db.dbType === "POSTGRESQL"
|
|
199
|
+
? (_d = req.body.query) === null || _d === void 0 ? void 0 : _d.replace(/'/g, "''")
|
|
200
|
+
: (_e = req.body.query) === null || _e === void 0 ? void 0 : _e.replace(/'/g, "\\'");
|
|
187
201
|
const { rows: records, error } = await getRecords({
|
|
188
202
|
table: column.table,
|
|
189
203
|
page: 1,
|
|
190
204
|
filters: sqlAnd([
|
|
191
205
|
column.filters,
|
|
192
|
-
req.body.query
|
|
193
|
-
|
|
206
|
+
req.body.query
|
|
207
|
+
? `${column.searchableName} LIKE '${column.wholeSearch ? "%" : ""}${queryEscaped}%'`
|
|
208
|
+
: null,
|
|
209
|
+
column.filtersFromUser
|
|
210
|
+
? column.filtersFromUser(user.userId, user.role)
|
|
211
|
+
: null,
|
|
194
212
|
]),
|
|
195
213
|
join: column.join,
|
|
196
214
|
selectExpression: column.selectExpression,
|
|
197
215
|
orderBy: column.orderBy,
|
|
198
|
-
limit: column.limit || 1000
|
|
216
|
+
limit: column.limit || 1000,
|
|
199
217
|
});
|
|
200
218
|
if (error) {
|
|
201
219
|
return res.status(500).send(error);
|
|
@@ -215,32 +233,41 @@ exports.default = (db, config, user) => {
|
|
|
215
233
|
label = record[column.name];
|
|
216
234
|
}
|
|
217
235
|
const value = record[column.foreignName] || record[column.name];
|
|
218
|
-
return
|
|
236
|
+
return {
|
|
219
237
|
value,
|
|
220
|
-
label
|
|
221
|
-
}
|
|
238
|
+
label,
|
|
239
|
+
};
|
|
222
240
|
}));
|
|
223
241
|
res.send(options);
|
|
224
242
|
});
|
|
225
|
-
app.post(
|
|
243
|
+
app.post("/records", async function (req, res, next) {
|
|
226
244
|
const view = config.views[req.body.viewIndex];
|
|
227
245
|
const isDesc = req.body.isDesc === null ? view.isDesc : req.body.isDesc;
|
|
228
|
-
const subview = view.subviews && req.body.subviewIndex !== undefined
|
|
246
|
+
const subview = view.subviews && req.body.subviewIndex !== undefined
|
|
247
|
+
? view.subviews[req.body.subviewIndex]
|
|
248
|
+
: null;
|
|
229
249
|
const orderBy = req.body.orderBy || (subview === null || subview === void 0 ? void 0 : subview.orderBy) || view.orderBy;
|
|
230
|
-
const { rows: records, input, error, count } = await getRecords({
|
|
250
|
+
const { rows: records, input, error, count, } = await getRecords({
|
|
231
251
|
table: view.tableName,
|
|
232
252
|
page: req.body.page,
|
|
233
253
|
filters: sqlAnd([
|
|
234
254
|
view.filters,
|
|
235
255
|
subview === null || subview === void 0 ? void 0 : subview.filters,
|
|
236
256
|
...req.body.filters,
|
|
237
|
-
view.filtersFromUser
|
|
257
|
+
view.filtersFromUser
|
|
258
|
+
? view.filtersFromUser(user.userId, user.role)
|
|
259
|
+
: null,
|
|
238
260
|
]),
|
|
239
261
|
having: subview === null || subview === void 0 ? void 0 : subview.having,
|
|
240
262
|
customQuery: view.customQuery,
|
|
241
263
|
join: view.join,
|
|
242
264
|
selectExpression: view.selectExpression,
|
|
243
|
-
orderBy: [
|
|
265
|
+
orderBy: [
|
|
266
|
+
orderBy ? `${orderBy} ${isDesc ? "DESC" : "ASC"}` : null,
|
|
267
|
+
view.primaryId,
|
|
268
|
+
]
|
|
269
|
+
.filter((x) => x)
|
|
270
|
+
.join(", "),
|
|
244
271
|
primaryId: view.primaryId,
|
|
245
272
|
query: req.body.query,
|
|
246
273
|
groupBy: view.groupBy,
|
|
@@ -253,14 +280,15 @@ exports.default = (db, config, user) => {
|
|
|
253
280
|
for (const column of view.columns) {
|
|
254
281
|
if (column.formatValue) {
|
|
255
282
|
for (const record of records) {
|
|
256
|
-
record[`__formatValue-${column.__id__}__`] =
|
|
283
|
+
record[`__formatValue-${column.__id__}__`] =
|
|
284
|
+
await column.formatValue(record);
|
|
257
285
|
}
|
|
258
286
|
}
|
|
259
287
|
}
|
|
260
288
|
res.send({
|
|
261
289
|
records,
|
|
262
290
|
input,
|
|
263
|
-
count
|
|
291
|
+
count,
|
|
264
292
|
});
|
|
265
293
|
});
|
|
266
294
|
const formattedValueToFunction = {};
|
|
@@ -290,11 +318,25 @@ exports.default = (db, config, user) => {
|
|
|
290
318
|
}
|
|
291
319
|
}
|
|
292
320
|
function evalExpression(expression, data) {
|
|
293
|
-
let varString =
|
|
294
|
-
let statement =
|
|
321
|
+
let varString = "";
|
|
322
|
+
let statement = "";
|
|
295
323
|
try {
|
|
296
324
|
for (let key in data) {
|
|
297
|
-
statement =
|
|
325
|
+
statement =
|
|
326
|
+
"var " +
|
|
327
|
+
key +
|
|
328
|
+
" = " +
|
|
329
|
+
(typeof data[key] === "string"
|
|
330
|
+
? "'" +
|
|
331
|
+
data[key]
|
|
332
|
+
.replace(/'/g, "\\'")
|
|
333
|
+
.replace(/\n/g, "")
|
|
334
|
+
.replace(/\r/g, "") +
|
|
335
|
+
"'"
|
|
336
|
+
: typeof data[key] === "object"
|
|
337
|
+
? JSON.stringify(data[key])
|
|
338
|
+
: data[key]) +
|
|
339
|
+
";";
|
|
298
340
|
varString += statement;
|
|
299
341
|
}
|
|
300
342
|
const result = eval(varString + expression);
|
|
@@ -332,11 +374,13 @@ exports.default = (db, config, user) => {
|
|
|
332
374
|
}
|
|
333
375
|
return value;
|
|
334
376
|
}
|
|
335
|
-
app.post(
|
|
377
|
+
app.post("/recordsExport", async function (req, res) {
|
|
336
378
|
const view = config.views[req.body.viewIndex];
|
|
337
379
|
const orderBy = req.body.orderBy || view.orderBy;
|
|
338
380
|
const isDesc = req.body.isDesc === null ? view.isDesc : req.body.isDesc;
|
|
339
|
-
const subview = view.subviews && req.body.subviewIndex !== undefined
|
|
381
|
+
const subview = view.subviews && req.body.subviewIndex !== undefined
|
|
382
|
+
? view.subviews[req.body.subviewIndex]
|
|
383
|
+
: null;
|
|
340
384
|
const { rows: records, error } = await getRecords({
|
|
341
385
|
table: view.tableName,
|
|
342
386
|
page: 1,
|
|
@@ -372,21 +416,21 @@ exports.default = (db, config, user) => {
|
|
|
372
416
|
if (!columns[j].hideInTable || columns[j].includeInExport) {
|
|
373
417
|
if (j > 0)
|
|
374
418
|
output += ";";
|
|
375
|
-
if (columns[j].dataType ==
|
|
419
|
+
if (columns[j].dataType == "textarea") {
|
|
376
420
|
output += '"';
|
|
377
421
|
}
|
|
378
422
|
output += await getFormattedValue(columns[j], el);
|
|
379
|
-
if (columns[j].dataType ==
|
|
423
|
+
if (columns[j].dataType == "textarea") {
|
|
380
424
|
output += '"';
|
|
381
425
|
}
|
|
382
426
|
}
|
|
383
427
|
}
|
|
384
428
|
}
|
|
385
429
|
res.send({
|
|
386
|
-
content: output
|
|
430
|
+
content: output,
|
|
387
431
|
});
|
|
388
432
|
});
|
|
389
|
-
app.post(
|
|
433
|
+
app.post("/recordsImport", async function (req, res) {
|
|
390
434
|
const form = new multiparty.Form();
|
|
391
435
|
form.parse(req, async function (err, fields, files) {
|
|
392
436
|
if (err) {
|
|
@@ -394,13 +438,15 @@ exports.default = (db, config, user) => {
|
|
|
394
438
|
}
|
|
395
439
|
const view = config.views[fields.viewIndex[0]];
|
|
396
440
|
if (typeof view.parseImportFile !== "function") {
|
|
397
|
-
return res
|
|
441
|
+
return res
|
|
442
|
+
.status(500)
|
|
443
|
+
.send('"parseImportFile" doit être défini dans la configuration de la vue.');
|
|
398
444
|
}
|
|
399
445
|
const records = await view.parseImportFile(files.data[0]);
|
|
400
446
|
const columns = [];
|
|
401
447
|
if (records.length === 0) {
|
|
402
448
|
return res.send({
|
|
403
|
-
affectedRows: 0
|
|
449
|
+
affectedRows: 0,
|
|
404
450
|
});
|
|
405
451
|
}
|
|
406
452
|
try {
|
|
@@ -413,20 +459,32 @@ exports.default = (db, config, user) => {
|
|
|
413
459
|
}
|
|
414
460
|
let queryString;
|
|
415
461
|
if (db.dbType === "POSTGRESQL") {
|
|
416
|
-
queryString = `INSERT INTO ?? (${columns.map(x => `"${x}"`).join(", ")}) VALUES`;
|
|
462
|
+
queryString = `INSERT INTO ?? (${columns.map((x) => `"${x}"`).join(", ")}) VALUES`;
|
|
417
463
|
for (let record of records) {
|
|
418
|
-
const valuesList = columns
|
|
464
|
+
const valuesList = columns
|
|
465
|
+
.map((x) => formatValueForInsertion(record[x], db.dbType))
|
|
466
|
+
.join(", ");
|
|
419
467
|
queryString += ` (${valuesList}),`;
|
|
420
468
|
}
|
|
421
|
-
queryString =
|
|
469
|
+
queryString =
|
|
470
|
+
queryString.slice(0, -1) +
|
|
471
|
+
` ON CONFLICT (${view.importFileUniqueField}) DO UPDATE SET `;
|
|
422
472
|
for (let column of columns) {
|
|
423
473
|
queryString += `"${column}" = EXCLUDED."${column}",`;
|
|
424
474
|
}
|
|
425
475
|
}
|
|
426
476
|
else {
|
|
427
|
-
queryString =
|
|
477
|
+
queryString =
|
|
478
|
+
"INSERT INTO ?? (" +
|
|
479
|
+
columns.map((x) => "`" + x + "`").join(", ") +
|
|
480
|
+
") VALUES";
|
|
428
481
|
for (let record of records) {
|
|
429
|
-
queryString +=
|
|
482
|
+
queryString +=
|
|
483
|
+
" (" +
|
|
484
|
+
columns
|
|
485
|
+
.map((x) => formatValueForInsertion(record[x], db.dbType))
|
|
486
|
+
.join(", ") +
|
|
487
|
+
"),";
|
|
430
488
|
}
|
|
431
489
|
queryString = queryString.slice(0, -1) + " ON DUPLICATE KEY UPDATE";
|
|
432
490
|
for (let column of columns) {
|
|
@@ -439,23 +497,23 @@ exports.default = (db, config, user) => {
|
|
|
439
497
|
console.error(err);
|
|
440
498
|
return res.status(500).send({
|
|
441
499
|
err,
|
|
442
|
-
message: "Une erreur est survenue."
|
|
500
|
+
message: "Une erreur est survenue.",
|
|
443
501
|
});
|
|
444
502
|
}
|
|
445
503
|
res.send({
|
|
446
|
-
affectedRows: r.affectedRows
|
|
504
|
+
affectedRows: r.affectedRows,
|
|
447
505
|
});
|
|
448
506
|
}
|
|
449
507
|
catch (err) {
|
|
450
508
|
console.error(err);
|
|
451
509
|
res.status(500).send({
|
|
452
510
|
err,
|
|
453
|
-
message: "Une erreur est survenue."
|
|
511
|
+
message: "Une erreur est survenue.",
|
|
454
512
|
});
|
|
455
513
|
}
|
|
456
514
|
});
|
|
457
515
|
});
|
|
458
|
-
app.post(
|
|
516
|
+
app.post("/subrecordsImport", async function (req, res) {
|
|
459
517
|
const form = new multiparty.Form();
|
|
460
518
|
form.parse(req, async function (err, fields, files) {
|
|
461
519
|
if (err) {
|
|
@@ -464,16 +522,20 @@ exports.default = (db, config, user) => {
|
|
|
464
522
|
const view = config.views[fields.viewIndex[0]];
|
|
465
523
|
const panel = view.recordViewPanels[fields.panelIndex[0]];
|
|
466
524
|
if (typeof panel.parseImportFile !== "function") {
|
|
467
|
-
return res
|
|
525
|
+
return res
|
|
526
|
+
.status(500)
|
|
527
|
+
.send('"parseImportFile" doit être défini dans la configuration du panneau.');
|
|
468
528
|
}
|
|
469
529
|
if (!Boolean(panel.createConfig)) {
|
|
470
|
-
return res
|
|
530
|
+
return res
|
|
531
|
+
.status(500)
|
|
532
|
+
.send('"createConfig" doit être défini dans la configuration du panneau.');
|
|
471
533
|
}
|
|
472
534
|
const records = await panel.parseImportFile(files.data[0], fields.recordId[0]);
|
|
473
535
|
const columns = [];
|
|
474
536
|
if (records.length === 0) {
|
|
475
537
|
return res.send({
|
|
476
|
-
affectedRows: 0
|
|
538
|
+
affectedRows: 0,
|
|
477
539
|
});
|
|
478
540
|
}
|
|
479
541
|
try {
|
|
@@ -484,38 +546,59 @@ exports.default = (db, config, user) => {
|
|
|
484
546
|
}
|
|
485
547
|
}
|
|
486
548
|
}
|
|
487
|
-
let queryString = "INSERT IGNORE INTO ?? (`" +
|
|
549
|
+
let queryString = "INSERT IGNORE INTO ?? (`" +
|
|
550
|
+
panel.createConfig.recordIdKey +
|
|
551
|
+
"`, " +
|
|
552
|
+
columns.map((x) => "`" + x + "`").join(", ") +
|
|
553
|
+
") VALUES";
|
|
488
554
|
for (let record of records) {
|
|
489
|
-
queryString +=
|
|
555
|
+
queryString +=
|
|
556
|
+
" (" +
|
|
557
|
+
fields.recordId[0] +
|
|
558
|
+
", " +
|
|
559
|
+
columns
|
|
560
|
+
.map((x) => formatValueForInsertion(record[x], db.dbType))
|
|
561
|
+
.join(", ") +
|
|
562
|
+
"),";
|
|
490
563
|
}
|
|
491
564
|
queryString = queryString.slice(0, -1) + " ON DUPLICATE KEY UPDATE";
|
|
492
565
|
for (let column of columns) {
|
|
493
566
|
queryString += " `" + column + "` = VALUES(`" + column + "`),";
|
|
494
567
|
}
|
|
495
|
-
const { err, rows: r } = await db.query(queryString.slice(0, -1), [
|
|
568
|
+
const { err, rows: r } = await db.query(queryString.slice(0, -1), [
|
|
569
|
+
panel.tableName,
|
|
570
|
+
]);
|
|
496
571
|
if (err) {
|
|
497
572
|
console.error(err);
|
|
498
573
|
return res.status(500).send({
|
|
499
574
|
err,
|
|
500
|
-
message: "Une erreur est survenue."
|
|
575
|
+
message: "Une erreur est survenue.",
|
|
501
576
|
});
|
|
502
577
|
}
|
|
503
578
|
res.send({
|
|
504
|
-
affectedRows: r.affectedRows
|
|
579
|
+
affectedRows: r.affectedRows,
|
|
505
580
|
});
|
|
506
581
|
}
|
|
507
582
|
catch (err) {
|
|
508
583
|
console.error(err);
|
|
509
584
|
res.status(500).send({
|
|
510
585
|
err,
|
|
511
|
-
message: "Une erreur est survenue."
|
|
586
|
+
message: "Une erreur est survenue.",
|
|
512
587
|
});
|
|
513
588
|
}
|
|
514
589
|
});
|
|
515
590
|
});
|
|
516
|
-
app.get(
|
|
591
|
+
app.get("/record", async function (req, res) {
|
|
517
592
|
const view = config.views[req.query.viewIndex];
|
|
518
|
-
const { err, rows } = await db.query("SELECT " +
|
|
593
|
+
const { err, rows } = await db.query("SELECT " +
|
|
594
|
+
(view.selectExpression || "*") +
|
|
595
|
+
" FROM ?? " +
|
|
596
|
+
(view.join || "") +
|
|
597
|
+
" WHERE ?? = ?", [
|
|
598
|
+
view.tableName,
|
|
599
|
+
view.tableName + "." + view.primaryId,
|
|
600
|
+
req.query.recordId,
|
|
601
|
+
]);
|
|
519
602
|
if (err) {
|
|
520
603
|
return res.status(500).send(err);
|
|
521
604
|
}
|
|
@@ -523,7 +606,8 @@ exports.default = (db, config, user) => {
|
|
|
523
606
|
const record = rows[0];
|
|
524
607
|
for (const column of view.columns) {
|
|
525
608
|
if (column.formatValue) {
|
|
526
|
-
record[`__formatValue-${column.__id__}__`] =
|
|
609
|
+
record[`__formatValue-${column.__id__}__`] =
|
|
610
|
+
await column.formatValue(record);
|
|
527
611
|
}
|
|
528
612
|
}
|
|
529
613
|
res.send(record);
|
|
@@ -532,19 +616,28 @@ exports.default = (db, config, user) => {
|
|
|
532
616
|
res.sendStatus(404);
|
|
533
617
|
}
|
|
534
618
|
});
|
|
535
|
-
app.post(
|
|
619
|
+
app.post("/updateRecord", async function (req, res, next) {
|
|
536
620
|
const view = config.views[req.body.viewIndex];
|
|
537
621
|
for (let key in req.body.data) {
|
|
538
|
-
if (req.body.data[key] == "NULL" ||
|
|
622
|
+
if (req.body.data[key] == "NULL" ||
|
|
623
|
+
req.body.data[key] === "" ||
|
|
624
|
+
req.body.data[key] === "Invalid date") {
|
|
539
625
|
req.body.data[key] = null;
|
|
540
626
|
}
|
|
541
627
|
}
|
|
542
628
|
if (Object.keys(req.body.data).length === 0) {
|
|
543
629
|
return res.sendStatus(200);
|
|
544
630
|
}
|
|
545
|
-
const queryExpression = Object.keys(req.body.data)
|
|
546
|
-
|
|
547
|
-
|
|
631
|
+
const queryExpression = Object.keys(req.body.data)
|
|
632
|
+
.map((x) => `${x} = ?`)
|
|
633
|
+
.join(", ");
|
|
634
|
+
const queryParameters = Object.keys(req.body.data).map((x) => req.body.data[x]);
|
|
635
|
+
const { err } = await db.query(`UPDATE ?? SET ${queryExpression} WHERE ?? = ?`, [
|
|
636
|
+
view.tableName,
|
|
637
|
+
...queryParameters,
|
|
638
|
+
view.primaryId,
|
|
639
|
+
req.body.primaryValue,
|
|
640
|
+
]);
|
|
548
641
|
if (err) {
|
|
549
642
|
return res.status(500).send(err);
|
|
550
643
|
}
|
|
@@ -553,7 +646,7 @@ exports.default = (db, config, user) => {
|
|
|
553
646
|
await axios_1.default.post(view.editCallback, {
|
|
554
647
|
id: req.body.primaryValue,
|
|
555
648
|
data: req.body.data,
|
|
556
|
-
previousData: req.body.previousData
|
|
649
|
+
previousData: req.body.previousData,
|
|
557
650
|
});
|
|
558
651
|
}
|
|
559
652
|
catch (e) { }
|
|
@@ -561,23 +654,27 @@ exports.default = (db, config, user) => {
|
|
|
561
654
|
if (view.editCallbackFunction) {
|
|
562
655
|
await view.editCallbackFunction({
|
|
563
656
|
id: req.body.primaryValue,
|
|
564
|
-
data: req.body.data
|
|
657
|
+
data: req.body.data,
|
|
565
658
|
});
|
|
566
659
|
}
|
|
567
660
|
res.sendStatus(200);
|
|
568
661
|
});
|
|
569
|
-
app.post(
|
|
662
|
+
app.post("/customAction", async function (req, res, next) {
|
|
570
663
|
const view = config.views[req.body.viewIndex];
|
|
571
664
|
const action = view.customActions[req.body.actionIndex];
|
|
572
665
|
for (const recordId of req.body.selectedRecordIds) {
|
|
573
666
|
try {
|
|
574
|
-
const { rows } = await db.query("SELECT " +
|
|
667
|
+
const { rows } = await db.query("SELECT " +
|
|
668
|
+
(view.selectExpression || "*") +
|
|
669
|
+
" FROM ?? " +
|
|
670
|
+
(view.join || "") +
|
|
671
|
+
" WHERE ?? = ?", [view.tableName, view.tableName + "." + view.primaryId, recordId]);
|
|
575
672
|
const record = rows[0];
|
|
576
673
|
const actionResult = await action.action(record, user.userId);
|
|
577
674
|
if (actionResult) {
|
|
578
675
|
return res.send({
|
|
579
676
|
success: true,
|
|
580
|
-
message: actionResult
|
|
677
|
+
message: actionResult,
|
|
581
678
|
});
|
|
582
679
|
}
|
|
583
680
|
}
|
|
@@ -585,18 +682,26 @@ exports.default = (db, config, user) => {
|
|
|
585
682
|
console.error(err);
|
|
586
683
|
return res.send({
|
|
587
684
|
success: false,
|
|
588
|
-
error: err
|
|
685
|
+
error: err,
|
|
589
686
|
});
|
|
590
687
|
}
|
|
591
688
|
}
|
|
592
689
|
res.send({
|
|
593
690
|
success: true,
|
|
594
|
-
message: action.successMessage
|
|
691
|
+
message: action.successMessage,
|
|
595
692
|
});
|
|
596
693
|
});
|
|
597
|
-
app.post(
|
|
694
|
+
app.post("/deleteRecord", async function (req, res) {
|
|
598
695
|
const view = config.views[req.body.viewIndex];
|
|
599
|
-
const { rows, err: err2 } = await db.query("SELECT " +
|
|
696
|
+
const { rows, err: err2 } = await db.query("SELECT " +
|
|
697
|
+
(view.selectExpression || "*") +
|
|
698
|
+
" FROM ?? " +
|
|
699
|
+
(view.join || "") +
|
|
700
|
+
" WHERE ?? = ?", [
|
|
701
|
+
view.tableName,
|
|
702
|
+
view.tableName + "." + view.primaryId,
|
|
703
|
+
req.body.primaryValue,
|
|
704
|
+
]);
|
|
600
705
|
if (err2) {
|
|
601
706
|
return res.status(500).send(err2);
|
|
602
707
|
}
|
|
@@ -604,14 +709,18 @@ exports.default = (db, config, user) => {
|
|
|
604
709
|
if (!deletedRecord) {
|
|
605
710
|
return res.status(404).send("Record not found");
|
|
606
711
|
}
|
|
607
|
-
const { err } = await db.query("DELETE FROM ?? WHERE ?? = ?", [
|
|
712
|
+
const { err } = await db.query("DELETE FROM ?? WHERE ?? = ?", [
|
|
713
|
+
view.tableName,
|
|
714
|
+
view.primaryId,
|
|
715
|
+
req.body.primaryValue,
|
|
716
|
+
]);
|
|
608
717
|
if (err) {
|
|
609
718
|
return res.status(500).send(err);
|
|
610
719
|
}
|
|
611
720
|
if (view.deleteCallback) {
|
|
612
721
|
try {
|
|
613
722
|
await axios_1.default.post(view.deleteCallback, {
|
|
614
|
-
id: req.body.primaryValue
|
|
723
|
+
id: req.body.primaryValue,
|
|
615
724
|
});
|
|
616
725
|
}
|
|
617
726
|
catch (e) { }
|
|
@@ -619,27 +728,31 @@ exports.default = (db, config, user) => {
|
|
|
619
728
|
if (view.deleteCallbackFunction) {
|
|
620
729
|
await view.deleteCallbackFunction({
|
|
621
730
|
id: req.body.primaryValue,
|
|
622
|
-
deletedRecord
|
|
731
|
+
deletedRecord,
|
|
623
732
|
});
|
|
624
733
|
}
|
|
625
734
|
res.sendStatus(200);
|
|
626
735
|
});
|
|
627
|
-
app.post(
|
|
736
|
+
app.post("/deleteRecordFromPanel", async function (req, res) {
|
|
628
737
|
const view = config.views[req.body.viewIndex];
|
|
629
|
-
const panel = view.recordViewPanels.find(x => x.__id__ === req.body.panelId);
|
|
738
|
+
const panel = view.recordViewPanels.find((x) => x.__id__ === req.body.panelId);
|
|
630
739
|
const { rows, err: err2 } = await db.query("SELECT * FROM ?? WHERE ?? = ?", [panel.tableName, panel.primaryId, req.body.primaryValue]);
|
|
631
740
|
if (err2) {
|
|
632
741
|
return res.status(500).send(err2);
|
|
633
742
|
}
|
|
634
743
|
const deletedRecord = rows[0];
|
|
635
|
-
const { err } = await db.query("DELETE FROM ?? WHERE ?? = ?", [
|
|
744
|
+
const { err } = await db.query("DELETE FROM ?? WHERE ?? = ?", [
|
|
745
|
+
panel.tableName,
|
|
746
|
+
panel.primaryId,
|
|
747
|
+
req.body.primaryValue,
|
|
748
|
+
]);
|
|
636
749
|
if (err) {
|
|
637
750
|
return res.status(500).send(err);
|
|
638
751
|
}
|
|
639
752
|
if (panel.deleteCallback) {
|
|
640
753
|
try {
|
|
641
754
|
await axios_1.default.post(panel.deleteCallback, {
|
|
642
|
-
id: req.body.primaryValue
|
|
755
|
+
id: req.body.primaryValue,
|
|
643
756
|
});
|
|
644
757
|
}
|
|
645
758
|
catch (e) { }
|
|
@@ -647,20 +760,20 @@ exports.default = (db, config, user) => {
|
|
|
647
760
|
if (panel.deleteCallbackFunction) {
|
|
648
761
|
await panel.deleteCallbackFunction({
|
|
649
762
|
id: req.body.primaryValue,
|
|
650
|
-
deletedRecord
|
|
763
|
+
deletedRecord,
|
|
651
764
|
});
|
|
652
765
|
}
|
|
653
766
|
res.sendStatus(200);
|
|
654
767
|
});
|
|
655
|
-
app.post(
|
|
768
|
+
app.post("/deleteRecords", async function (req, res, next) {
|
|
656
769
|
const view = config.views[req.body.viewIndex];
|
|
657
|
-
const { err } = await db.query(`DELETE FROM ?? WHERE ?? IN(${req.body.primaryValues.map(x => "'" + x + "'").join(",")})`, [view.tableName, view.primaryId]);
|
|
770
|
+
const { err } = await db.query(`DELETE FROM ?? WHERE ?? IN(${req.body.primaryValues.map((x) => "'" + x + "'").join(",")})`, [view.tableName, view.primaryId]);
|
|
658
771
|
if (err) {
|
|
659
772
|
return res.status(500).send(err);
|
|
660
773
|
}
|
|
661
774
|
res.sendStatus(200);
|
|
662
775
|
});
|
|
663
|
-
app.get(
|
|
776
|
+
app.get("/notificationBadges", async function (req, res) {
|
|
664
777
|
const notificationBadges = {};
|
|
665
778
|
async function checkAndGetNotificationBadge(obj) {
|
|
666
779
|
if (obj.notificationBadge) {
|
|
@@ -668,9 +781,11 @@ exports.default = (db, config, user) => {
|
|
|
668
781
|
if (err) {
|
|
669
782
|
console.error(err);
|
|
670
783
|
}
|
|
671
|
-
else if (rows.length > 0 &&
|
|
784
|
+
else if (rows.length > 0 &&
|
|
785
|
+
rows[0][obj.notificationBadge.attribute]) {
|
|
672
786
|
const notificationBadge = rows[0][obj.notificationBadge.attribute];
|
|
673
|
-
if (!obj.notificationBadge.displayCondition ||
|
|
787
|
+
if (!obj.notificationBadge.displayCondition ||
|
|
788
|
+
obj.notificationBadge.displayCondition(notificationBadge)) {
|
|
674
789
|
notificationBadges[obj.__id__] = notificationBadge;
|
|
675
790
|
}
|
|
676
791
|
}
|
|
@@ -686,9 +801,13 @@ exports.default = (db, config, user) => {
|
|
|
686
801
|
}
|
|
687
802
|
res.send(notificationBadges);
|
|
688
803
|
});
|
|
689
|
-
app.post(
|
|
804
|
+
app.post("/duplicateRecord", async function (req, res, next) {
|
|
690
805
|
const primaryId = req.body.duplicateConfig.primaryId;
|
|
691
|
-
const { err, rows } = await db.query("SELECT * FROM ?? WHERE ?? = ?", [
|
|
806
|
+
const { err, rows } = await db.query("SELECT * FROM ?? WHERE ?? = ?", [
|
|
807
|
+
req.body.table,
|
|
808
|
+
primaryId,
|
|
809
|
+
req.body.primaryValue,
|
|
810
|
+
]);
|
|
692
811
|
if (err) {
|
|
693
812
|
return res.status(500).send(err);
|
|
694
813
|
}
|
|
@@ -703,7 +822,11 @@ exports.default = (db, config, user) => {
|
|
|
703
822
|
}
|
|
704
823
|
const newRecordId = r.insertId;
|
|
705
824
|
for (let foreignTable of req.body.duplicateConfig.foreignTables) {
|
|
706
|
-
const { err, rows } = await db.query("SELECT * FROM ?? WHERE ?? = ?", [
|
|
825
|
+
const { err, rows } = await db.query("SELECT * FROM ?? WHERE ?? = ?", [
|
|
826
|
+
foreignTable.table,
|
|
827
|
+
primaryId,
|
|
828
|
+
req.body.primaryValue,
|
|
829
|
+
]);
|
|
707
830
|
if (err)
|
|
708
831
|
console.log(err);
|
|
709
832
|
for (let record of rows) {
|
|
@@ -712,51 +835,62 @@ exports.default = (db, config, user) => {
|
|
|
712
835
|
for (let field of foreignTable.fields) {
|
|
713
836
|
data[field] = record[field];
|
|
714
837
|
}
|
|
715
|
-
await db.query("INSERT IGNORE INTO ?? SET ?", [
|
|
838
|
+
await db.query("INSERT IGNORE INTO ?? SET ?", [
|
|
839
|
+
foreignTable.table,
|
|
840
|
+
data,
|
|
841
|
+
]);
|
|
716
842
|
}
|
|
717
843
|
}
|
|
718
844
|
res.sendStatus(200);
|
|
719
845
|
});
|
|
720
|
-
app.post(
|
|
846
|
+
app.post("/createRecord", async function (req, res, next) {
|
|
721
847
|
var _a, _b, _c;
|
|
722
848
|
const view = config.views[req.body.viewIndex];
|
|
723
|
-
const panel = req.body.panelIndex
|
|
849
|
+
const panel = req.body.panelIndex
|
|
850
|
+
? view.recordViewPanels[req.body.panelIndex]
|
|
851
|
+
: null;
|
|
724
852
|
try {
|
|
725
853
|
for (let key in req.body.data) {
|
|
726
|
-
if (req.body.data[key] == "NULL" ||
|
|
854
|
+
if (req.body.data[key] == "NULL" ||
|
|
855
|
+
req.body.data[key] === "Invalid date") {
|
|
727
856
|
req.body.data[key] = null;
|
|
728
857
|
}
|
|
729
858
|
}
|
|
730
859
|
if (panel) {
|
|
731
860
|
req.body.data[panel.createConfig.recordIdKey] = req.body.recordId;
|
|
732
861
|
}
|
|
733
|
-
const primaryColumn = (_b = (_a = (view || panel)) === null || _a === void 0 ? void 0 : _a.columns) === null || _b === void 0 ? void 0 : _b.find(x => x.name === (view || panel).primaryId);
|
|
862
|
+
const primaryColumn = (_b = (_a = (view || panel)) === null || _a === void 0 ? void 0 : _a.columns) === null || _b === void 0 ? void 0 : _b.find((x) => x.name === (view || panel).primaryId);
|
|
734
863
|
if ((primaryColumn === null || primaryColumn === void 0 ? void 0 : primaryColumn.dataType) == "uuid") {
|
|
735
864
|
req.body.data[primaryColumn.name] = (0, uuid_1.v4)();
|
|
736
865
|
}
|
|
737
866
|
const createPayload = JSON.parse(JSON.stringify(req.body.data));
|
|
738
867
|
const columns = panel ? panel.createConfig.columns : view.columns;
|
|
739
868
|
for (let key in createPayload) {
|
|
740
|
-
if (((_c = columns === null || columns === void 0 ? void 0 : columns.find(x => x.name === key)) === null || _c === void 0 ? void 0 : _c.includedInCreatePayload) ===
|
|
869
|
+
if (((_c = columns === null || columns === void 0 ? void 0 : columns.find((x) => x.name === key)) === null || _c === void 0 ? void 0 : _c.includedInCreatePayload) ===
|
|
870
|
+
false) {
|
|
741
871
|
delete createPayload[key];
|
|
742
872
|
}
|
|
743
873
|
}
|
|
744
874
|
const queryExpression = Object.keys(createPayload).join(", ");
|
|
745
|
-
const queryPlaceholders = Object.keys(createPayload)
|
|
746
|
-
|
|
875
|
+
const queryPlaceholders = Object.keys(createPayload)
|
|
876
|
+
.map((x) => "?")
|
|
877
|
+
.join(", ");
|
|
878
|
+
const queryParameters = Object.keys(createPayload).map((x) => createPayload[x]);
|
|
747
879
|
const { err, rows: r } = await db.query(`INSERT INTO ?? (${queryExpression}) VALUES(${queryPlaceholders})`, [panel ? panel.tableName : view.tableName, ...queryParameters]);
|
|
748
880
|
if (err) {
|
|
749
881
|
console.error(err);
|
|
750
882
|
return res.status(500).send({
|
|
751
883
|
err,
|
|
752
|
-
message: err.code ===
|
|
884
|
+
message: err.code === "ER_DUP_ENTRY"
|
|
885
|
+
? "Cet élément existe déjà."
|
|
886
|
+
: "Une erreur est survenue.",
|
|
753
887
|
});
|
|
754
888
|
}
|
|
755
889
|
if (panel ? panel.createCallback : view.createCallback) {
|
|
756
890
|
try {
|
|
757
891
|
await axios_1.default.post(panel ? panel.createCallback : view.createCallback, {
|
|
758
892
|
id: r.insertId,
|
|
759
|
-
data: req.body.data
|
|
893
|
+
data: req.body.data,
|
|
760
894
|
});
|
|
761
895
|
}
|
|
762
896
|
catch (e) { }
|
|
@@ -764,22 +898,22 @@ exports.default = (db, config, user) => {
|
|
|
764
898
|
if (panel ? panel.createCallbackFunction : view.createCallbackFunction) {
|
|
765
899
|
await (panel ? panel.createCallbackFunction : view.createCallbackFunction)({
|
|
766
900
|
id: r.insertId,
|
|
767
|
-
data: req.body.data
|
|
901
|
+
data: req.body.data,
|
|
768
902
|
});
|
|
769
903
|
}
|
|
770
904
|
res.send({
|
|
771
|
-
id: r.insertId
|
|
905
|
+
id: r.insertId,
|
|
772
906
|
});
|
|
773
907
|
}
|
|
774
908
|
catch (err) {
|
|
775
909
|
console.error(err);
|
|
776
910
|
res.status(500).send({
|
|
777
911
|
err,
|
|
778
|
-
message: "Une erreur est survenue."
|
|
912
|
+
message: "Une erreur est survenue.",
|
|
779
913
|
});
|
|
780
914
|
}
|
|
781
915
|
});
|
|
782
|
-
app.get(
|
|
916
|
+
app.get("/customQuery", async function (req, res, next) {
|
|
783
917
|
const query = req.query.query.replace(/\?/g, req.query.primaryValue);
|
|
784
918
|
const { err, rows } = await db.query(query);
|
|
785
919
|
if (err) {
|
|
@@ -798,22 +932,14 @@ exports.default = (db, config, user) => {
|
|
|
798
932
|
res.send(rows);
|
|
799
933
|
});
|
|
800
934
|
function uploadFile(column, fileParamName, req, res) {
|
|
801
|
-
if (column.s3Config) {
|
|
802
|
-
const s3Config = column.s3Config;
|
|
935
|
+
if (column.s3Config || column.gcpConfig) {
|
|
803
936
|
const form = new multiparty.Form();
|
|
804
|
-
const s3 = new aws_sdk_1.S3({
|
|
805
|
-
endpoint: new aws_sdk_1.Endpoint(s3Config.host),
|
|
806
|
-
accessKeyId: s3Config.accessKeyId,
|
|
807
|
-
secretAccessKey: s3Config.secretAccessKey,
|
|
808
|
-
region: s3Config.region,
|
|
809
|
-
signatureVersion: "v4",
|
|
810
|
-
});
|
|
811
937
|
form.parse(req, function (err, fields, files) {
|
|
812
938
|
if (err) {
|
|
813
939
|
return res.status(500).send(err);
|
|
814
940
|
}
|
|
815
941
|
const originalFilename = files[fileParamName][0].originalFilename;
|
|
816
|
-
const contentType = mime.getType(originalFilename) ||
|
|
942
|
+
const contentType = mime.getType(originalFilename) || "application/octet-stream";
|
|
817
943
|
const extension = originalFilename.match(/(?:\.([^.]+))?$/)[1];
|
|
818
944
|
let aspectRatio = null;
|
|
819
945
|
if (["png", "jpeg", "jpg", "gif"].includes(extension)) {
|
|
@@ -821,55 +947,105 @@ exports.default = (db, config, user) => {
|
|
|
821
947
|
aspectRatio = dimensions.height / dimensions.width;
|
|
822
948
|
}
|
|
823
949
|
const originalFilenameWithoutExtension = originalFilename.replace("." + extension, "");
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
const
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
950
|
+
if (column.gcpConfig) {
|
|
951
|
+
const gcpConfig = column.gcpConfig;
|
|
952
|
+
const path = (gcpConfig.subfolder ? gcpConfig.subfolder + "/" : "") +
|
|
953
|
+
originalFilenameWithoutExtension +
|
|
954
|
+
"-" +
|
|
955
|
+
Math.random().toString().substr(2) +
|
|
956
|
+
"." +
|
|
957
|
+
extension;
|
|
958
|
+
const storage = new storage_1.Storage();
|
|
959
|
+
const bucketName = gcpConfig.bucket;
|
|
960
|
+
storage
|
|
961
|
+
.bucket(bucketName)
|
|
962
|
+
.upload(files[fileParamName][0].path, {
|
|
963
|
+
destination: path,
|
|
838
964
|
})
|
|
839
965
|
.then(() => {
|
|
840
966
|
res.status(200).send({
|
|
841
|
-
path:
|
|
967
|
+
path: gcpConfig.pathTransform
|
|
968
|
+
? gcpConfig.pathTransform(path)
|
|
969
|
+
: path,
|
|
842
970
|
aspectRatio,
|
|
843
971
|
originalFilename,
|
|
844
972
|
});
|
|
845
973
|
})
|
|
846
|
-
.catch(e => {
|
|
974
|
+
.catch((e) => {
|
|
847
975
|
res.status(500).send(e);
|
|
848
976
|
});
|
|
849
977
|
}
|
|
850
978
|
else {
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
originalFilename
|
|
865
|
-
});
|
|
979
|
+
const s3Config = column.s3Config;
|
|
980
|
+
const path = (s3Config.subfolder ? s3Config.subfolder + "/" : "") +
|
|
981
|
+
originalFilenameWithoutExtension +
|
|
982
|
+
"-" +
|
|
983
|
+
Math.random().toString().substr(2) +
|
|
984
|
+
"." +
|
|
985
|
+
extension;
|
|
986
|
+
const s3 = new aws_sdk_1.S3({
|
|
987
|
+
endpoint: new aws_sdk_1.Endpoint(s3Config.host),
|
|
988
|
+
accessKeyId: s3Config.accessKeyId,
|
|
989
|
+
secretAccessKey: s3Config.secretAccessKey,
|
|
990
|
+
region: s3Config.region,
|
|
991
|
+
signatureVersion: "v4",
|
|
866
992
|
});
|
|
993
|
+
if (s3Config.signedUrlNeeded) {
|
|
994
|
+
const signedUrl = s3.getSignedUrl("putObject", {
|
|
995
|
+
Bucket: s3Config.bucket,
|
|
996
|
+
Key: path,
|
|
997
|
+
ContentType: contentType,
|
|
998
|
+
Expires: 150,
|
|
999
|
+
});
|
|
1000
|
+
axios_1.default
|
|
1001
|
+
.put(signedUrl, fs.readFileSync(files[fileParamName][0].path), {
|
|
1002
|
+
maxContentLength: 100000000000,
|
|
1003
|
+
maxBodyLength: 100000000000,
|
|
1004
|
+
headers: {
|
|
1005
|
+
"Content-Type": contentType,
|
|
1006
|
+
},
|
|
1007
|
+
})
|
|
1008
|
+
.then(() => {
|
|
1009
|
+
res.status(200).send({
|
|
1010
|
+
path: s3Config.pathTransform
|
|
1011
|
+
? s3Config.pathTransform(path)
|
|
1012
|
+
: path,
|
|
1013
|
+
aspectRatio,
|
|
1014
|
+
originalFilename,
|
|
1015
|
+
});
|
|
1016
|
+
})
|
|
1017
|
+
.catch((e) => {
|
|
1018
|
+
res.status(500).send(e);
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
else {
|
|
1022
|
+
s3.putObject({
|
|
1023
|
+
Body: fs.readFileSync(files[fileParamName][0].path),
|
|
1024
|
+
Bucket: s3Config.bucket,
|
|
1025
|
+
ContentType: contentType,
|
|
1026
|
+
ACL: "public-read",
|
|
1027
|
+
Key: path,
|
|
1028
|
+
}, function (err, data) {
|
|
1029
|
+
if (err)
|
|
1030
|
+
return res.status(500).send(err);
|
|
1031
|
+
res.send({
|
|
1032
|
+
url: `https://${s3Config.host}/${s3Config.bucket}/${path}`,
|
|
1033
|
+
path: s3Config.pathTransform
|
|
1034
|
+
? s3Config.pathTransform(path)
|
|
1035
|
+
: path,
|
|
1036
|
+
aspectRatio,
|
|
1037
|
+
originalFilename,
|
|
1038
|
+
});
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
867
1041
|
}
|
|
868
1042
|
});
|
|
869
1043
|
}
|
|
870
1044
|
else if (column.sftpConfig) {
|
|
871
1045
|
if (!column.publicPath) {
|
|
872
|
-
return res
|
|
1046
|
+
return res
|
|
1047
|
+
.status(500)
|
|
1048
|
+
.send("You need to pass publicPath parameter when using sftpConfig");
|
|
873
1049
|
}
|
|
874
1050
|
const form = new multiparty.Form();
|
|
875
1051
|
form.parse(req, function (err, fields, files) {
|
|
@@ -884,13 +1060,16 @@ exports.default = (db, config, user) => {
|
|
|
884
1060
|
host: column.sftpConfig.host,
|
|
885
1061
|
port: 22,
|
|
886
1062
|
username: column.sftpConfig.user,
|
|
887
|
-
password: column.sftpConfig.password
|
|
1063
|
+
password: column.sftpConfig.password,
|
|
888
1064
|
});
|
|
889
|
-
await sftp.fastPut(files[fileParamName][0].path, column.publicPath +
|
|
1065
|
+
await sftp.fastPut(files[fileParamName][0].path, column.publicPath +
|
|
1066
|
+
(column.subdirectory ? "/" + column.subdirectory : "") +
|
|
1067
|
+
"/" +
|
|
1068
|
+
filename);
|
|
890
1069
|
await sftp.end();
|
|
891
1070
|
res.send({
|
|
892
1071
|
path: filename,
|
|
893
|
-
originalFilename: files[fileParamName][0].originalFilename
|
|
1072
|
+
originalFilename: files[fileParamName][0].originalFilename,
|
|
894
1073
|
});
|
|
895
1074
|
fs.unlinkSync(files[fileParamName][0].path);
|
|
896
1075
|
})();
|
|
@@ -898,7 +1077,7 @@ exports.default = (db, config, user) => {
|
|
|
898
1077
|
}
|
|
899
1078
|
else {
|
|
900
1079
|
const form = new multiparty.Form({
|
|
901
|
-
uploadDir: column.publicPath + column.subdirectory
|
|
1080
|
+
uploadDir: column.publicPath + column.subdirectory,
|
|
902
1081
|
});
|
|
903
1082
|
form.parse(req, function (err, fields, files) {
|
|
904
1083
|
if (err) {
|
|
@@ -906,32 +1085,32 @@ exports.default = (db, config, user) => {
|
|
|
906
1085
|
}
|
|
907
1086
|
res.send({
|
|
908
1087
|
path: files[fileParamName][0].path.replace(column.publicPath, ""),
|
|
909
|
-
originalFilename: files[fileParamName][0].originalFilename
|
|
1088
|
+
originalFilename: files[fileParamName][0].originalFilename,
|
|
910
1089
|
});
|
|
911
1090
|
});
|
|
912
1091
|
}
|
|
913
1092
|
}
|
|
914
|
-
app.post(
|
|
915
|
-
const fileUploadProperties = JSON.parse(req.headers[
|
|
1093
|
+
app.post("/uploadFileFromBetterRichTextInput", async function (req, res, next) {
|
|
1094
|
+
const fileUploadProperties = JSON.parse(req.headers["file-upload-properties"]);
|
|
916
1095
|
uploadFile(fileUploadProperties, "upload", req, res);
|
|
917
1096
|
});
|
|
918
|
-
app.post(
|
|
1097
|
+
app.post("/uploadFile", async function (req, res, next) {
|
|
919
1098
|
var _a, _b, _c;
|
|
920
1099
|
const view = config.views[req.query.viewIndex];
|
|
921
1100
|
const column = [
|
|
922
1101
|
...view.columns,
|
|
923
|
-
...(((_c = (_b = (_a = view.recordViewPanels) === null || _a === void 0 ? void 0 : _a.map(x => { var _a; return (_a = x === null || x === void 0 ? void 0 : x.createConfig) === null || _a === void 0 ? void 0 : _a.columns; })) === null || _b === void 0 ? void 0 : _b.filter(x => x)) === null || _c === void 0 ? void 0 : _c.flat()) || [])
|
|
924
|
-
].find(x => x.__id__ == req.query.columnId);
|
|
1102
|
+
...(((_c = (_b = (_a = view.recordViewPanels) === null || _a === void 0 ? void 0 : _a.map((x) => { var _a; return (_a = x === null || x === void 0 ? void 0 : x.createConfig) === null || _a === void 0 ? void 0 : _a.columns; })) === null || _b === void 0 ? void 0 : _b.filter((x) => x)) === null || _c === void 0 ? void 0 : _c.flat()) || []),
|
|
1103
|
+
].find((x) => x.__id__ == req.query.columnId);
|
|
925
1104
|
uploadFile(column, "file", req, res);
|
|
926
1105
|
});
|
|
927
|
-
app.get(
|
|
1106
|
+
app.get("/searchCompanies", async (req, res) => {
|
|
928
1107
|
const processedQuery = req.query.query.replaceAll(" ", "-");
|
|
929
1108
|
try {
|
|
930
1109
|
const response = await axios_1.default.get(`https://public.opendatasoft.com/api/explore/v2.1/catalog/datasets/economicref-france-sirene-v3/records`, {
|
|
931
1110
|
params: {
|
|
932
1111
|
where: `denominationunitelegale LIKE '${processedQuery}*' OR siret LIKE '${processedQuery}*'`,
|
|
933
|
-
limit: 100
|
|
934
|
-
}
|
|
1112
|
+
limit: 100,
|
|
1113
|
+
},
|
|
935
1114
|
});
|
|
936
1115
|
const results = response.data.results
|
|
937
1116
|
.filter((etablissement) => etablissement.etatadministratifetablissement === "Actif")
|
|
@@ -999,25 +1178,33 @@ async function enrichConfig(config, db) {
|
|
|
999
1178
|
config.enriched = true;
|
|
1000
1179
|
}
|
|
1001
1180
|
function enrichColumn(column, tableName, info) {
|
|
1181
|
+
var _a, _b, _c, _d;
|
|
1002
1182
|
if (!column.__id__) {
|
|
1003
1183
|
column.__id__ = generateUniqueIdForObject(column);
|
|
1004
1184
|
}
|
|
1005
|
-
const infoEl = info.find(x => x.TABLE_NAME == tableName && x.COLUMN_NAME == column.name);
|
|
1006
|
-
if ((infoEl === null || infoEl === void 0 ? void 0 : infoEl.IS_NULLABLE) == "NO" &&
|
|
1185
|
+
const infoEl = info.find((x) => x.TABLE_NAME == tableName && x.COLUMN_NAME == column.name);
|
|
1186
|
+
if ((infoEl === null || infoEl === void 0 ? void 0 : infoEl.IS_NULLABLE) == "NO" &&
|
|
1187
|
+
(infoEl === null || infoEl === void 0 ? void 0 : infoEl.DATA_TYPE) != "text" &&
|
|
1188
|
+
column.required !== true &&
|
|
1189
|
+
column.required !== false) {
|
|
1007
1190
|
column.required = true;
|
|
1008
1191
|
}
|
|
1009
1192
|
if (!column.dataType && infoEl) {
|
|
1010
1193
|
column.dataType = infoEl.DATA_TYPE;
|
|
1011
1194
|
if (column.dataType == "enum") {
|
|
1012
1195
|
column.dataType = "select";
|
|
1013
|
-
column.options = JSON.parse(infoEl.COLUMN_TYPE.replace("enum(", "[")
|
|
1196
|
+
column.options = JSON.parse(infoEl.COLUMN_TYPE.replace("enum(", "[")
|
|
1197
|
+
.replace(")", "]")
|
|
1198
|
+
.replace(/'/g, '"'));
|
|
1014
1199
|
}
|
|
1015
1200
|
}
|
|
1016
1201
|
if (column.dataType == "richText") {
|
|
1017
1202
|
column.name = column.contentField;
|
|
1018
1203
|
}
|
|
1019
|
-
if (column.dataType == "file" && column.s3Config) {
|
|
1020
|
-
|
|
1204
|
+
if (column.dataType == "file" && (column.s3Config || column.gcpConfig)) {
|
|
1205
|
+
const host = ((_a = column.s3Config) === null || _a === void 0 ? void 0 : _a.host) || ((_b = column.gcpConfig) === null || _b === void 0 ? void 0 : _b.host);
|
|
1206
|
+
const bucket = ((_c = column.s3Config) === null || _c === void 0 ? void 0 : _c.bucket) || ((_d = column.gcpConfig) === null || _d === void 0 ? void 0 : _d.bucket);
|
|
1207
|
+
column.baseUrl = `https://${host}/${bucket}/`;
|
|
1021
1208
|
}
|
|
1022
1209
|
}
|
|
1023
1210
|
//# sourceMappingURL=api.js.map
|