@opengis/fastify-table 1.2.42 → 1.2.44
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 +86 -86
- package/package.json +1 -1
- package/server/migrations/cls.sql +39 -39
- package/server/plugins/cron/funcs/addCron.js +130 -130
- package/server/plugins/cron/index.js +6 -6
- package/server/plugins/crud/funcs/dataDelete.js +7 -1
- package/server/plugins/crud/funcs/dataInsert.js +7 -0
- package/server/plugins/crud/funcs/dataUpdate.js +4 -1
- package/server/plugins/crud/funcs/getOpt.js +13 -13
- package/server/plugins/crud/funcs/setOpt.js +21 -21
- package/server/plugins/crud/funcs/setToken.js +44 -44
- package/server/plugins/crud/funcs/utils/getFolder.js +10 -10
- package/server/plugins/crud/index.js +23 -23
- package/server/plugins/extra/extraData.js +51 -28
- package/server/plugins/extra/extraDataGet.js +18 -4
- package/server/plugins/hook/index.js +8 -8
- package/server/plugins/logger/errorStatus.js +19 -19
- package/server/plugins/logger/index.js +21 -21
- package/server/plugins/migration/index.js +7 -7
- package/server/plugins/pg/pgClients.js +21 -21
- package/server/plugins/policy/sqlInjection.js +33 -33
- package/server/plugins/redis/client.js +8 -8
- package/server/plugins/redis/funcs/redisClients.js +3 -3
- package/server/plugins/redis/index.js +17 -17
- package/server/plugins/table/funcs/getFilterSQL/index.js +126 -96
- package/server/plugins/table/funcs/getFilterSQL/util/formatValue.js +37 -16
- package/server/plugins/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
- package/server/plugins/table/funcs/getFilterSQL/util/getOptimizedQuery.js +12 -12
- package/server/plugins/table/funcs/getFilterSQL/util/getTableSql.js +34 -34
- package/server/plugins/table/funcs/getTemplates.js +19 -19
- package/server/plugins/table/funcs/gisIRColumn.js +82 -82
- package/server/plugins/table/funcs/loadTemplate.js +1 -1
- package/server/plugins/table/funcs/loadTemplatePath.js +1 -1
- package/server/plugins/table/funcs/metaFormat/index.js +3 -2
- package/server/plugins/table/funcs/userTemplateDir.js +1 -1
- package/server/plugins/table/index.js +13 -13
- package/server/plugins/util/index.js +7 -7
- package/server/routes/cron/index.js +14 -14
- package/server/routes/crud/controllers/table.js +88 -88
- package/server/routes/logger/controllers/logger.file.js +92 -92
- package/server/routes/logger/controllers/utils/checkUserAccess.js +19 -19
- package/server/routes/logger/controllers/utils/getRootDir.js +26 -26
- package/server/routes/logger/index.js +17 -17
- package/server/routes/properties/controllers/properties.add.js +55 -55
- package/server/routes/properties/controllers/properties.get.js +17 -17
- package/server/routes/properties/index.js +16 -16
- package/server/routes/table/controllers/data.js +24 -3
- package/server/routes/table/controllers/filter.js +3 -1
- package/server/routes/table/controllers/form.js +42 -42
- package/server/routes/table/controllers/search.js +74 -74
- package/server/routes/table/index.js +29 -29
- package/server/routes/table/schema.js +64 -64
- package/server/routes/util/controllers/status.monitor.js +8 -8
- package/server/routes/util/index.js +11 -11
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { createHash, randomUUID } from 'crypto';
|
|
2
|
-
|
|
3
|
-
const random = randomUUID();
|
|
4
|
-
|
|
5
|
-
import getRedis from '../../redis/funcs/getRedis.js';
|
|
6
|
-
|
|
7
|
-
// import { getRedis } from '../../../../utils.js';
|
|
8
|
-
|
|
9
|
-
function md5(string) {
|
|
10
|
-
return createHash('md5').update(string).digest('hex');
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export default function setOpt(params, uid = 0) {
|
|
14
|
-
const token = Buffer.from(md5(typeof params === 'object' ? JSON.stringify(params) : params) + random, 'hex').toString('base64').replace(/[+-=]+/g, '');
|
|
15
|
-
// const token = md5(params);
|
|
16
|
-
const key = `opt:${uid}:${token}`;
|
|
17
|
-
|
|
18
|
-
const rclient = getRedis({ db: 0 });
|
|
19
|
-
rclient.set(key, JSON.stringify(params), 'EX', 60 * 60);
|
|
20
|
-
return token;
|
|
21
|
-
}
|
|
1
|
+
import { createHash, randomUUID } from 'crypto';
|
|
2
|
+
|
|
3
|
+
const random = randomUUID();
|
|
4
|
+
|
|
5
|
+
import getRedis from '../../redis/funcs/getRedis.js';
|
|
6
|
+
|
|
7
|
+
// import { getRedis } from '../../../../utils.js';
|
|
8
|
+
|
|
9
|
+
function md5(string) {
|
|
10
|
+
return createHash('md5').update(string).digest('hex');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default function setOpt(params, uid = 0) {
|
|
14
|
+
const token = Buffer.from(md5(typeof params === 'object' ? JSON.stringify(params) : params) + random, 'hex').toString('base64').replace(/[+-=]+/g, '');
|
|
15
|
+
// const token = md5(params);
|
|
16
|
+
const key = `opt:${uid}:${token}`;
|
|
17
|
+
|
|
18
|
+
const rclient = getRedis({ db: 0 });
|
|
19
|
+
rclient.set(key, JSON.stringify(params), 'EX', 60 * 60);
|
|
20
|
+
return token;
|
|
21
|
+
}
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import { createHash, randomUUID } from 'crypto';
|
|
2
|
-
|
|
3
|
-
import config from '../../../../config.js';
|
|
4
|
-
|
|
5
|
-
import getRedis from '../../redis/funcs/getRedis.js';
|
|
6
|
-
|
|
7
|
-
const rclient = getRedis({ db: 0 });
|
|
8
|
-
|
|
9
|
-
// import { config, getRedis } from '../../../../utils.js';
|
|
10
|
-
|
|
11
|
-
const generateCodes = (ids, userToken) => {
|
|
12
|
-
const token = userToken || randomUUID();
|
|
13
|
-
const notNullIds = ids.filter((el) => el);
|
|
14
|
-
const obj = {};
|
|
15
|
-
const codes = notNullIds.reduce((acc, id) => {
|
|
16
|
-
const newToken = createHash('sha1').update(token + id).digest('base64url').replace(/-/g, '');
|
|
17
|
-
acc[newToken] = id; obj[id] = newToken;
|
|
18
|
-
return acc;
|
|
19
|
-
}, {});
|
|
20
|
-
return { codes, obj };
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
function setToken({
|
|
24
|
-
ids: idsOrigin, uid, array,
|
|
25
|
-
}) {
|
|
26
|
-
// const rclient5 = getRedis({ db: 0, funcs });
|
|
27
|
-
|
|
28
|
-
if (!uid) return { user: 'empty' };
|
|
29
|
-
if (!Object.keys(idsOrigin).length) return { ids: 'empty' };
|
|
30
|
-
|
|
31
|
-
const ids = idsOrigin.map((el) => (typeof el === 'object' ? JSON.stringify(el) : el));
|
|
32
|
-
|
|
33
|
-
// TODO generate salt
|
|
34
|
-
const { codes, obj } = generateCodes(ids, uid);
|
|
35
|
-
|
|
36
|
-
if (!Object.keys(codes).length) return { ids: 'empty' };
|
|
37
|
-
|
|
38
|
-
rclient.hmset(`${config.pg.database}:token:edit:${uid}`, codes);
|
|
39
|
-
// console.log(`${config.pg.database}:token:edit:${uid}`, idsOrigin, Object.values(obj));
|
|
40
|
-
// TODO дополнительно писать в hset token -> uid
|
|
41
|
-
return array ? Object.values(obj) : obj;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export default setToken;
|
|
1
|
+
import { createHash, randomUUID } from 'crypto';
|
|
2
|
+
|
|
3
|
+
import config from '../../../../config.js';
|
|
4
|
+
|
|
5
|
+
import getRedis from '../../redis/funcs/getRedis.js';
|
|
6
|
+
|
|
7
|
+
const rclient = getRedis({ db: 0 });
|
|
8
|
+
|
|
9
|
+
// import { config, getRedis } from '../../../../utils.js';
|
|
10
|
+
|
|
11
|
+
const generateCodes = (ids, userToken) => {
|
|
12
|
+
const token = userToken || randomUUID();
|
|
13
|
+
const notNullIds = ids.filter((el) => el);
|
|
14
|
+
const obj = {};
|
|
15
|
+
const codes = notNullIds.reduce((acc, id) => {
|
|
16
|
+
const newToken = createHash('sha1').update(token + id).digest('base64url').replace(/-/g, '');
|
|
17
|
+
acc[newToken] = id; obj[id] = newToken;
|
|
18
|
+
return acc;
|
|
19
|
+
}, {});
|
|
20
|
+
return { codes, obj };
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function setToken({
|
|
24
|
+
ids: idsOrigin, uid, array,
|
|
25
|
+
}) {
|
|
26
|
+
// const rclient5 = getRedis({ db: 0, funcs });
|
|
27
|
+
|
|
28
|
+
if (!uid) return { user: 'empty' };
|
|
29
|
+
if (!Object.keys(idsOrigin).length) return { ids: 'empty' };
|
|
30
|
+
|
|
31
|
+
const ids = idsOrigin.map((el) => (typeof el === 'object' ? JSON.stringify(el) : el));
|
|
32
|
+
|
|
33
|
+
// TODO generate salt
|
|
34
|
+
const { codes, obj } = generateCodes(ids, uid);
|
|
35
|
+
|
|
36
|
+
if (!Object.keys(codes).length) return { ids: 'empty' };
|
|
37
|
+
|
|
38
|
+
rclient.hmset(`${config.pg.database}:token:edit:${uid}`, codes);
|
|
39
|
+
// console.log(`${config.pg.database}:token:edit:${uid}`, idsOrigin, Object.values(obj));
|
|
40
|
+
// TODO дополнительно писать в hset token -> uid
|
|
41
|
+
return array ? Object.values(obj) : obj;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export default setToken;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
|
|
3
|
-
import config from '../../../../../config.js';
|
|
4
|
-
|
|
5
|
-
export default function getFolder(req, type = 'server') {
|
|
6
|
-
if (!['server', 'local'].includes(type)) throw new Error('params type is invalid');
|
|
7
|
-
const types = { local: req.root || config.root, server: req.mapServerRoot || config.mapServerRoot };
|
|
8
|
-
const filepath = path.posix.join(types[type] || `/data/local/${req.pg?.options?.database || ''}`, req.folder || config.folder || '');
|
|
9
|
-
return filepath;
|
|
10
|
-
}
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
|
|
3
|
+
import config from '../../../../../config.js';
|
|
4
|
+
|
|
5
|
+
export default function getFolder(req, type = 'server') {
|
|
6
|
+
if (!['server', 'local'].includes(type)) throw new Error('params type is invalid');
|
|
7
|
+
const types = { local: req.root || config.root, server: req.mapServerRoot || config.mapServerRoot };
|
|
8
|
+
const filepath = path.posix.join(types[type] || `/data/local/${req.pg?.options?.database || ''}`, req.folder || config.folder || '');
|
|
9
|
+
return filepath;
|
|
10
|
+
}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
// import getOpt from './funcs/getOpt.js';
|
|
2
|
-
// import setOpt from './funcs/setOpt.js';
|
|
3
|
-
|
|
4
|
-
// import isFileExists from './funcs/isFileExists.js';
|
|
5
|
-
|
|
6
|
-
// import dataUpdate from './funcs/dataUpdate.js';
|
|
7
|
-
// import dataInsert from './funcs/dataInsert.js';
|
|
8
|
-
|
|
9
|
-
// import getAccessFunc from './funcs/getAccess.js';
|
|
10
|
-
|
|
11
|
-
async function plugin(fastify) {
|
|
12
|
-
// fastify.decorate('setOpt', setOpt);
|
|
13
|
-
// fastify.decorate('getOpt', getOpt);
|
|
14
|
-
|
|
15
|
-
// fastify.decorate('dataUpdate', dataUpdate);
|
|
16
|
-
// fastify.decorate('dataInsert', dataInsert);
|
|
17
|
-
|
|
18
|
-
// fastify.decorate('getAccess', getAccessFunc);
|
|
19
|
-
|
|
20
|
-
// fastify.decorate('isFileExists', isFileExists);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export default plugin;
|
|
1
|
+
// import getOpt from './funcs/getOpt.js';
|
|
2
|
+
// import setOpt from './funcs/setOpt.js';
|
|
3
|
+
|
|
4
|
+
// import isFileExists from './funcs/isFileExists.js';
|
|
5
|
+
|
|
6
|
+
// import dataUpdate from './funcs/dataUpdate.js';
|
|
7
|
+
// import dataInsert from './funcs/dataInsert.js';
|
|
8
|
+
|
|
9
|
+
// import getAccessFunc from './funcs/getAccess.js';
|
|
10
|
+
|
|
11
|
+
async function plugin(fastify) {
|
|
12
|
+
// fastify.decorate('setOpt', setOpt);
|
|
13
|
+
// fastify.decorate('getOpt', getOpt);
|
|
14
|
+
|
|
15
|
+
// fastify.decorate('dataUpdate', dataUpdate);
|
|
16
|
+
// fastify.decorate('dataInsert', dataInsert);
|
|
17
|
+
|
|
18
|
+
// fastify.decorate('getAccess', getAccessFunc);
|
|
19
|
+
|
|
20
|
+
// fastify.decorate('isFileExists', isFileExists);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default plugin;
|
|
@@ -2,60 +2,83 @@ import { config, getMeta, pgClients, getTemplate, dataInsert } from '../../../ut
|
|
|
2
2
|
|
|
3
3
|
const defaultTable = 'crm.extra_data';
|
|
4
4
|
|
|
5
|
+
function format(key, value, schema) {
|
|
6
|
+
if (!key || !schema?.[key]) return value;
|
|
7
|
+
if (schema?.[key]?.type && ['Number', 'Switcher'].includes(schema?.[key]?.type)) {
|
|
8
|
+
return JSON.parse(value || null);
|
|
9
|
+
}
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
|
|
5
13
|
export default async function extraData({
|
|
6
|
-
|
|
7
|
-
}) {
|
|
8
|
-
if (!id || !
|
|
14
|
+
table, form, id, data, uid,
|
|
15
|
+
}, pg = pgClients.client) {
|
|
16
|
+
if (!id || !table) {
|
|
9
17
|
return null;
|
|
10
18
|
}
|
|
11
19
|
|
|
12
20
|
const loadTemplate = await getTemplate('form', form);
|
|
13
21
|
if (!loadTemplate?.extra) return null;
|
|
14
22
|
|
|
15
|
-
const
|
|
16
|
-
|| config.extraData?.[
|
|
23
|
+
const extraDataTable = config.extraData?.[table]
|
|
24
|
+
|| config.extraData?.[table.split('.').shift()]
|
|
17
25
|
|| config.extraData?.['default']
|
|
18
26
|
|| config.extraData
|
|
19
27
|
|| defaultTable;
|
|
20
28
|
|
|
21
|
-
const { pk: mainPK, columns: mainColumns = [] } = await getMeta({ pg, table
|
|
22
|
-
const { pk, columns: extraColumns = [] } = await getMeta({ pg, table });
|
|
29
|
+
const { pk: mainPK, columns: mainColumns = [] } = await getMeta({ pg, table });
|
|
30
|
+
const { pk, columns: extraColumns = [] } = await getMeta({ pg, table: extraDataTable });
|
|
23
31
|
|
|
24
32
|
if (!mainPK) {
|
|
25
|
-
return { error: `table pk not found: ${
|
|
33
|
+
return { error: `table pk not found: ${table}`, status: 404 };
|
|
26
34
|
}
|
|
27
35
|
|
|
28
36
|
if (!pk) {
|
|
29
|
-
return { error: `extra table pk not found: ${
|
|
37
|
+
return { error: `extra table pk not found: ${extraDataTable}`, status: 404 };
|
|
30
38
|
}
|
|
31
39
|
|
|
32
40
|
const mode = extraColumns.find((col) => col?.name === mainPK)
|
|
33
41
|
? 'column'
|
|
34
42
|
: 'property';
|
|
35
43
|
|
|
36
|
-
|
|
44
|
+
if (mode === 'property') {
|
|
45
|
+
Object.assign(data || {}, { object_id: id });
|
|
46
|
+
}
|
|
37
47
|
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}[mode];
|
|
48
|
+
const deleteRes = mode === 'property'
|
|
49
|
+
? await pg.query(`delete from ${extraDataTable} where object_id=$1 and property_key = any($2::text[]) returning *`, [id, Object.keys(loadTemplate?.schema || {})])
|
|
50
|
+
: await pg.query(`delete from ${extraDataTable} where ${mainPK}=$1 returning *`, [id]);
|
|
42
51
|
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
52
|
+
if (!data) {
|
|
53
|
+
const res1 = mode === 'property'
|
|
54
|
+
? deleteRes?.rows?.reduce((acc, curr) => Object.assign(acc, { [curr.property_key]: format(curr.property_key, curr.value_text, loadTemplate?.schema) }), {})
|
|
55
|
+
: deleteRes?.rows?.[0];
|
|
56
|
+
return res1;
|
|
46
57
|
}
|
|
47
58
|
|
|
48
|
-
if (
|
|
49
|
-
|
|
59
|
+
if (mode === 'column') {
|
|
60
|
+
const filteredData = Object.keys(data)
|
|
61
|
+
.filter(key => Object.keys(loadTemplate?.schema || {}).includes(key))
|
|
62
|
+
.reduce((acc, curr) => Object.assign(acc, { [curr]: data[curr] }), {});
|
|
63
|
+
Object.assign(filteredData, { [mainPK]: id });
|
|
64
|
+
const res = await dataInsert({ pg, table: extraDataTable, data: filteredData, uid }).then(el => el.rows?.[0] || {});
|
|
65
|
+
Object.assign(res, { id: res?.[pg.pk?.[table || '']] });
|
|
66
|
+
return res;
|
|
67
|
+
}
|
|
50
68
|
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
69
|
+
const rows = Object.keys(data || {})
|
|
70
|
+
.filter(key => Object.keys(loadTemplate?.schema || {}).includes(key))
|
|
71
|
+
.filter(key => !mainColumns.map(el => el.name).concat('id', 'token').includes(key))
|
|
72
|
+
.map(key => ({
|
|
73
|
+
object_id: id,
|
|
74
|
+
property_key: key,
|
|
75
|
+
property_entity: table,
|
|
76
|
+
value_text: data[key],
|
|
77
|
+
}));
|
|
56
78
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
79
|
+
const res = await Promise.all(rows.map(async (row) => dataInsert({ pg, table: extraDataTable, data: row, uid }).then(el => el.rows?.[0] || {})));
|
|
80
|
+
return {
|
|
81
|
+
...res.reduce((acc, curr) => Object.assign(acc, { [curr.property_key]: format(curr.property_key, curr.value_text, loadTemplate?.schema) }), {}),
|
|
82
|
+
id: res?.[0]?.object_id,
|
|
83
|
+
};
|
|
61
84
|
}
|
|
@@ -2,9 +2,17 @@ import { config, getTemplate, pgClients, getMeta } from "../../../utils.js";
|
|
|
2
2
|
|
|
3
3
|
const defaultTable = 'crm.extra_data';
|
|
4
4
|
|
|
5
|
+
function format(key, value, schema) {
|
|
6
|
+
if (!key || !schema?.[key]) return undefined; // skip non-existing
|
|
7
|
+
if (schema?.[key]?.type && ['Number', 'Switcher'].includes(schema?.[key]?.type)) {
|
|
8
|
+
return JSON.parse(value || null);
|
|
9
|
+
}
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
|
|
5
13
|
export default async function extraDataGet({
|
|
6
|
-
|
|
7
|
-
}) {
|
|
14
|
+
table: mainTable, form, id,
|
|
15
|
+
}, pg = pgClients.client) {
|
|
8
16
|
if (!id || !form || !mainTable) {
|
|
9
17
|
return null;
|
|
10
18
|
}
|
|
@@ -36,9 +44,15 @@ export default async function extraDataGet({
|
|
|
36
44
|
const { rows = [] } = await pg.query(`select * from ${table} where ${mode === 'column' ? mainPK : 'object_id'}=$1`, [id]);
|
|
37
45
|
|
|
38
46
|
if (mode === 'column') {
|
|
39
|
-
|
|
47
|
+
const res = Object.keys(rows[0] || {})
|
|
48
|
+
.map(key => [key, format(key, rows?.[0]?.[key], loadTemplate?.schema)])
|
|
49
|
+
.filter(el => el[1])
|
|
50
|
+
.reduce((acc, curr) => Object.assign(acc, { [curr[0]]: curr[1] }), {});
|
|
51
|
+
Object.assign(res, { id: rows?.[0]?.[pg.pk?.[mainTable || '']] });
|
|
52
|
+
return res;
|
|
40
53
|
}
|
|
41
54
|
|
|
42
|
-
const res = rows.reduce((acc, curr) => Object.assign(acc, { [curr.property_key]: curr.value_text }), {});
|
|
55
|
+
const res = rows.reduce((acc, curr) => Object.assign(acc, { [curr.property_key]: format(curr.property_key, curr.value_text, loadTemplate?.schema) }), {});
|
|
56
|
+
Object.assign(res, { id: rows?.[0].object_id });
|
|
43
57
|
return res;
|
|
44
58
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import addHook from './funcs/addHook.js';
|
|
2
|
-
import applyHook from './funcs/applyHook.js';
|
|
3
|
-
|
|
4
|
-
async function plugin(fastify) {
|
|
5
|
-
// fastify.decorate('addHook', addHook);
|
|
6
|
-
// fastify.decorate('applyHook', applyHook);
|
|
7
|
-
}
|
|
8
|
-
export default plugin;
|
|
1
|
+
import addHook from './funcs/addHook.js';
|
|
2
|
+
import applyHook from './funcs/applyHook.js';
|
|
3
|
+
|
|
4
|
+
async function plugin(fastify) {
|
|
5
|
+
// fastify.decorate('addHook', addHook);
|
|
6
|
+
// fastify.decorate('applyHook', applyHook);
|
|
7
|
+
}
|
|
8
|
+
export default plugin;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import applyHookSync from '../hook/funcs/applyHookSync.js';
|
|
2
|
-
|
|
3
|
-
function errorStatus(error) {
|
|
4
|
-
const hook = applyHookSync('errorStatus', error);
|
|
5
|
-
if (hook) return hook;
|
|
6
|
-
|
|
7
|
-
if (error.routine === 'exec_stmt_raise' && error.file === 'pl_exec.c') {
|
|
8
|
-
return 601;
|
|
9
|
-
}
|
|
10
|
-
if (error.routine === 'ExecConstraints') {
|
|
11
|
-
return 602;
|
|
12
|
-
}
|
|
13
|
-
if (error.type === 'DatabaseError') {
|
|
14
|
-
return 600;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return 500;
|
|
18
|
-
}
|
|
19
|
-
export default errorStatus;
|
|
1
|
+
import applyHookSync from '../hook/funcs/applyHookSync.js';
|
|
2
|
+
|
|
3
|
+
function errorStatus(error) {
|
|
4
|
+
const hook = applyHookSync('errorStatus', error);
|
|
5
|
+
if (hook) return hook;
|
|
6
|
+
|
|
7
|
+
if (error.routine === 'exec_stmt_raise' && error.file === 'pl_exec.c') {
|
|
8
|
+
return 601;
|
|
9
|
+
}
|
|
10
|
+
if (error.routine === 'ExecConstraints') {
|
|
11
|
+
return 602;
|
|
12
|
+
}
|
|
13
|
+
if (error.type === 'DatabaseError') {
|
|
14
|
+
return 600;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return 500;
|
|
18
|
+
}
|
|
19
|
+
export default errorStatus;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import errorMessage from './errorMessage.js';
|
|
2
|
-
|
|
3
|
-
async function plugin(fastify) {
|
|
4
|
-
fastify.setErrorHandler(async (error, request, reply) => {
|
|
5
|
-
// validation not error
|
|
6
|
-
if (error.validation) {
|
|
7
|
-
request.log.warn(request, { code: error?.code, status: 422, error: error.toString() });
|
|
8
|
-
return reply.status(422).send(error.toString());
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// logger
|
|
12
|
-
request.log.error(error, request);
|
|
13
|
-
console.error({ msg: error.message, where: error.where, stack: error.stack });
|
|
14
|
-
|
|
15
|
-
// errorMessage
|
|
16
|
-
const msg = errorMessage(error);
|
|
17
|
-
|
|
18
|
-
return reply.status(error.statusCode || 500).send(msg);
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
export default plugin;
|
|
1
|
+
import errorMessage from './errorMessage.js';
|
|
2
|
+
|
|
3
|
+
async function plugin(fastify) {
|
|
4
|
+
fastify.setErrorHandler(async (error, request, reply) => {
|
|
5
|
+
// validation not error
|
|
6
|
+
if (error.validation) {
|
|
7
|
+
request.log.warn(request, { code: error?.code, status: 422, error: error.toString() });
|
|
8
|
+
return reply.status(422).send(error.toString());
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// logger
|
|
12
|
+
request.log.error(error, request);
|
|
13
|
+
console.error({ msg: error.message, where: error.where, stack: error.stack });
|
|
14
|
+
|
|
15
|
+
// errorMessage
|
|
16
|
+
const msg = errorMessage(error);
|
|
17
|
+
|
|
18
|
+
return reply.status(error.statusCode || 500).send(msg);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
export default plugin;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import execMigrations from './funcs/exec.migrations.js';
|
|
2
|
-
|
|
3
|
-
async function plugin(fastify) {
|
|
4
|
-
// fastify.decorate('execMigrations', execMigrations);
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export default plugin;
|
|
1
|
+
import execMigrations from './funcs/exec.migrations.js';
|
|
2
|
+
|
|
3
|
+
async function plugin(fastify) {
|
|
4
|
+
// fastify.decorate('execMigrations', execMigrations);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export default plugin;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import pg from 'pg';
|
|
2
|
-
|
|
3
|
-
import config from '../../../config.js';
|
|
4
|
-
import init from './funcs/init.js';
|
|
5
|
-
|
|
6
|
-
const pgClients = {};
|
|
7
|
-
if (config.pg) {
|
|
8
|
-
const client = new pg.Pool({
|
|
9
|
-
host: config.pg?.host || '127.0.0.1',
|
|
10
|
-
port: config.pg?.port || 5432,
|
|
11
|
-
database: config.pg?.database || 'postgres',
|
|
12
|
-
user: config.pg?.user || 'postgres',
|
|
13
|
-
password: config.pg?.password || 'postgres',
|
|
14
|
-
});
|
|
15
|
-
client.init = async () => {
|
|
16
|
-
await init(client);
|
|
17
|
-
};
|
|
18
|
-
client.init();
|
|
19
|
-
pgClients.client = client;
|
|
20
|
-
}
|
|
21
|
-
export default pgClients;
|
|
1
|
+
import pg from 'pg';
|
|
2
|
+
|
|
3
|
+
import config from '../../../config.js';
|
|
4
|
+
import init from './funcs/init.js';
|
|
5
|
+
|
|
6
|
+
const pgClients = {};
|
|
7
|
+
if (config.pg) {
|
|
8
|
+
const client = new pg.Pool({
|
|
9
|
+
host: config.pg?.host || '127.0.0.1',
|
|
10
|
+
port: config.pg?.port || 5432,
|
|
11
|
+
database: config.pg?.database || 'postgres',
|
|
12
|
+
user: config.pg?.user || 'postgres',
|
|
13
|
+
password: config.pg?.password || 'postgres',
|
|
14
|
+
});
|
|
15
|
+
client.init = async () => {
|
|
16
|
+
await init(client);
|
|
17
|
+
};
|
|
18
|
+
client.init();
|
|
19
|
+
pgClients.client = client;
|
|
20
|
+
}
|
|
21
|
+
export default pgClients;
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
const sqlInjection = [
|
|
2
|
-
'()',
|
|
3
|
-
'^',
|
|
4
|
-
'*',
|
|
5
|
-
'like ',
|
|
6
|
-
'@variable',
|
|
7
|
-
'@@variable',
|
|
8
|
-
'group by ',
|
|
9
|
-
'union ',
|
|
10
|
-
'select ',
|
|
11
|
-
'having ',
|
|
12
|
-
'as injectx',
|
|
13
|
-
'where ',
|
|
14
|
-
'rlike ',
|
|
15
|
-
'if(',
|
|
16
|
-
'sleep(',
|
|
17
|
-
'waitfor delay',
|
|
18
|
-
'benchmark(',
|
|
19
|
-
'pg_sleep(',
|
|
20
|
-
"'\\\"",
|
|
21
|
-
'randomblob(',
|
|
22
|
-
'order by ',
|
|
23
|
-
'union all ',
|
|
24
|
-
'+or',
|
|
25
|
-
'or ',
|
|
26
|
-
'and ',
|
|
27
|
-
"'' ",
|
|
28
|
-
'""" ',
|
|
29
|
-
'<script',
|
|
30
|
-
'javascript:',
|
|
31
|
-
];
|
|
32
|
-
|
|
33
|
-
export default sqlInjection;
|
|
1
|
+
const sqlInjection = [
|
|
2
|
+
'()',
|
|
3
|
+
'^',
|
|
4
|
+
'*',
|
|
5
|
+
'like ',
|
|
6
|
+
'@variable',
|
|
7
|
+
'@@variable',
|
|
8
|
+
'group by ',
|
|
9
|
+
'union ',
|
|
10
|
+
'select ',
|
|
11
|
+
'having ',
|
|
12
|
+
'as injectx',
|
|
13
|
+
'where ',
|
|
14
|
+
'rlike ',
|
|
15
|
+
'if(',
|
|
16
|
+
'sleep(',
|
|
17
|
+
'waitfor delay',
|
|
18
|
+
'benchmark(',
|
|
19
|
+
'pg_sleep(',
|
|
20
|
+
"'\\\"",
|
|
21
|
+
'randomblob(',
|
|
22
|
+
'order by ',
|
|
23
|
+
'union all ',
|
|
24
|
+
'+or',
|
|
25
|
+
'or ',
|
|
26
|
+
'and ',
|
|
27
|
+
"'' ",
|
|
28
|
+
'""" ',
|
|
29
|
+
'<script',
|
|
30
|
+
'javascript:',
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
export default sqlInjection;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import redisClients from './funcs/redisClients.js';
|
|
2
|
-
import getRedis from './funcs/getRedis.js';
|
|
3
|
-
|
|
4
|
-
if (!redisClients[0]) {
|
|
5
|
-
getRedis({ db: 0 });
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export default redisClients[0];
|
|
1
|
+
import redisClients from './funcs/redisClients.js';
|
|
2
|
+
import getRedis from './funcs/getRedis.js';
|
|
3
|
+
|
|
4
|
+
if (!redisClients[0]) {
|
|
5
|
+
getRedis({ db: 0 });
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export default redisClients[0];
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
const redisClients = {};
|
|
2
|
-
|
|
3
|
-
export default redisClients;
|
|
1
|
+
const redisClients = {};
|
|
2
|
+
|
|
3
|
+
export default redisClients;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
// import redis from './client.js';
|
|
2
|
-
import redisClients from './funcs/redisClients.js';
|
|
3
|
-
|
|
4
|
-
function close(fastify) {
|
|
5
|
-
// redis.quit();
|
|
6
|
-
Object.keys(redisClients).forEach((key) => redisClients[key].quit());
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
async function plugin(fastify) {
|
|
10
|
-
// const client = getRedis({ db: 0 });
|
|
11
|
-
// client.getJSON = client.get;
|
|
12
|
-
// fastify.decorate('rclient', client);
|
|
13
|
-
// fastify.decorate('getRedis', getRedis);
|
|
14
|
-
fastify.addHook('onClose', close);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export default plugin;
|
|
1
|
+
// import redis from './client.js';
|
|
2
|
+
import redisClients from './funcs/redisClients.js';
|
|
3
|
+
|
|
4
|
+
function close(fastify) {
|
|
5
|
+
// redis.quit();
|
|
6
|
+
Object.keys(redisClients).forEach((key) => redisClients[key].quit());
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async function plugin(fastify) {
|
|
10
|
+
// const client = getRedis({ db: 0 });
|
|
11
|
+
// client.getJSON = client.get;
|
|
12
|
+
// fastify.decorate('rclient', client);
|
|
13
|
+
// fastify.decorate('getRedis', getRedis);
|
|
14
|
+
fastify.addHook('onClose', close);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default plugin;
|