@opengis/fastify-table 1.1.51 → 1.1.52
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/.eslintrc.cjs +42 -42
- package/.gitlab-ci.yml +18 -18
- package/Changelog.md +352 -352
- package/README.md +26 -26
- package/config.js +10 -10
- package/cron/controllers/cronApi.js +22 -22
- package/cron/controllers/utils/cronList.js +1 -1
- package/cron/funcs/addCron.js +132 -132
- package/cron/index.js +12 -10
- package/cron/schema.js +8 -0
- package/crud/controllers/deleteCrud.js +36 -36
- package/crud/controllers/insert.js +71 -71
- package/crud/controllers/update.js +76 -76
- package/crud/controllers/utils/xssInjection.js +72 -72
- package/crud/funcs/dataDelete.js +19 -19
- package/crud/funcs/dataInsert.js +30 -30
- package/crud/funcs/dataUpdate.js +48 -48
- package/crud/funcs/getAccess.js +46 -46
- package/crud/funcs/getOpt.js +10 -10
- package/crud/funcs/getToken.js +27 -27
- package/crud/funcs/isFileExists.js +13 -13
- package/crud/funcs/setOpt.js +16 -16
- package/crud/funcs/setToken.js +53 -53
- package/crud/funcs/utils/getFolder.js +9 -9
- package/crud/funcs/utils/logChanges.js +62 -62
- package/crud/index.js +31 -36
- package/crud/schema.js +11 -0
- package/docs/.vitepress/abbr.mjs +26 -26
- package/docs/.vitepress/config.mjs +127 -127
- package/docs/.vitepress/navigation.mjs +82 -82
- package/docs/.vitepress/theme/Layout.vue +17 -17
- package/docs/.vitepress/theme/components/NavigationLinks.vue +102 -102
- package/docs/.vitepress/theme/components/Panzoom.vue +169 -169
- package/docs/.vitepress/theme/index.mjs +15 -15
- package/docs/.vitepress/theme/style.scss +163 -163
- package/docs/abbr.json +4 -4
- package/docs/api/cron/cronApi.md +56 -56
- package/docs/api/crud/deleteCrud.md +58 -58
- package/docs/api/crud/insert.md +82 -82
- package/docs/api/crud/update.md +85 -85
- package/docs/api/index.md +47 -47
- package/docs/api/notification/testEmail.md +91 -91
- package/docs/api/table/card.md +73 -73
- package/docs/api/table/data.md +134 -134
- package/docs/api/table/export.md +60 -60
- package/docs/api/table/filter.md +104 -104
- package/docs/api/table/form.md +126 -126
- package/docs/api/table/search.md +123 -123
- package/docs/api/table/suggest.md +156 -156
- package/docs/api/table/table.md +107 -107
- package/docs/api/user/user.cls.id.md +77 -77
- package/docs/api/user/user.cls.md +49 -49
- package/docs/api/user/user.cls.post.md +62 -62
- package/docs/api/user/user.info.md +37 -37
- package/docs/api/utils/logger.file.md +60 -60
- package/docs/api/utils/next.id.md +34 -34
- package/docs/api/utils/properties.add.md +127 -127
- package/docs/api/utils/properties.get.md +73 -73
- package/docs/api/utils/status.monitor.md +36 -36
- package/docs/api/widget/widget.del.md +76 -76
- package/docs/api/widget/widget.get.md +233 -233
- package/docs/api/widget/widget.set.md +88 -88
- package/docs/db/admin.md +947 -947
- package/docs/db/crm.md +564 -564
- package/docs/db/index.md +9 -9
- package/docs/db/log.md +204 -204
- package/docs/hook/card/afterCard.md +20 -20
- package/docs/hook/card/preCard.md +25 -25
- package/docs/hook/data/afterData.md +26 -26
- package/docs/hook/data/preData.md +26 -26
- package/docs/hook/deleteCrud/afterDelete.md +21 -21
- package/docs/hook/deleteCrud/preDelete.md +26 -26
- package/docs/hook/form/afterForm.md +19 -19
- package/docs/hook/form/preForm.md +26 -26
- package/docs/hook/getTemplate/afterTemplate.md +24 -24
- package/docs/hook/getTemplate/preTemplate.md +29 -29
- package/docs/hook/index.md +45 -45
- package/docs/hook/insert/afterInsert.md +41 -41
- package/docs/hook/insert/preInsert.md +25 -25
- package/docs/hook/table/afterTable.md +20 -20
- package/docs/hook/table/preTable.md +25 -25
- package/docs/hook/update/afterUpdate.md +41 -41
- package/docs/hook/update/preUpdate.md +25 -25
- package/docs/index.md +42 -42
- package/docs/public/fastify-dark.svg +3 -3
- package/docs/public/logo-short-dark.svg +11 -11
- package/docs/public/logo-short.svg +10 -10
- package/docs/public/logo.svg +19 -19
- package/docs/readme/index.md +121 -121
- package/docs/templates/card.md +83 -83
- package/docs/templates/cls.md +29 -29
- package/docs/templates/filters.md +91 -91
- package/docs/templates/forms.md +139 -139
- package/docs/templates/index.md +28 -28
- package/docs/templates/select.md +90 -90
- package/docs/templates/table.md +162 -162
- package/docs/utils/cron/addCron.md +29 -29
- package/docs/utils/crud/dataInsert.md +51 -51
- package/docs/utils/crud/dataUpdate.md +52 -52
- package/docs/utils/crud/getOpt.md +33 -33
- package/docs/utils/crud/isFileExists.md +37 -37
- package/docs/utils/crud/setOpt.md +37 -37
- package/docs/utils/hook/addHook.md +74 -74
- package/docs/utils/hook/applyHook.md +64 -64
- package/docs/utils/index.md +47 -47
- package/docs/utils/notification/addNotification.md +28 -28
- package/docs/utils/notification/notification.md +41 -41
- package/docs/utils/pg/autoIndex.md +22 -22
- package/docs/utils/pg/getMeta.md +58 -58
- package/docs/utils/pg/getPG.md +34 -34
- package/docs/utils/pg/init.md +29 -29
- package/docs/utils/pg/pg.md +70 -70
- package/docs/utils/redis/getRedis.md +36 -36
- package/docs/utils/redis/rclient.md +74 -74
- package/docs/utils/table/getForm.md +68 -68
- package/docs/utils/table/getMeta.md +55 -55
- package/docs/utils/table/getSelect.md +38 -38
- package/docs/utils/table/getSelectMeta.md +46 -46
- package/docs/utils/table/getTable.md +77 -77
- package/helper.js +30 -30
- package/index.js +105 -105
- package/migration/exec.migrations.js +79 -79
- package/module/core/select/core.user_mentioned.sql +1 -1
- package/module/test/cls/itree.composition.json +25 -25
- package/module/test/table/test.rest_zone.table.json +265 -265
- package/notification/controllers/readNotifications.js +27 -30
- package/notification/controllers/testEmail.js +46 -50
- package/notification/controllers/userNotifications.js +61 -64
- package/notification/funcs/addNotification.js +21 -21
- package/notification/funcs/sendNotification.js +112 -112
- package/notification/index.js +3 -8
- package/notification/schema.js +10 -0
- package/package.json +41 -41
- package/pg/funcs/getMeta.js +29 -29
- package/pg/funcs/getPG.js +30 -30
- package/pg/pgClients.js +20 -20
- package/policy/funcs/checkPolicy.js +92 -92
- package/policy/funcs/sqlInjection.js +33 -33
- package/policy/index.js +14 -14
- package/redis/client.js +8 -8
- package/redis/funcs/getRedis.js +23 -23
- package/redis/funcs/redisClients.js +2 -2
- package/redis/index.js +19 -19
- package/server/migrations/0.sql +78 -78
- package/server/migrations/cls.sql +39 -39
- package/server/migrations/log.sql +80 -80
- package/server/migrations/properties.sql +144 -144
- package/server/migrations/roles.sql +172 -172
- package/server/migrations/users.sql +168 -168
- package/server.js +26 -26
- package/table/controllers/data.js +157 -150
- package/table/controllers/filter.js +61 -50
- package/table/controllers/form.js +42 -42
- package/table/controllers/search.js +76 -80
- package/table/controllers/suggest.js +79 -79
- package/table/controllers/table.js +83 -83
- package/table/controllers/utils/addTemplateDir.js +8 -8
- package/table/controllers/utils/getSelect.js +19 -19
- package/table/controllers/utils/getSelectMeta.js +66 -66
- package/table/controllers/utils/getTemplate_old.js +28 -28
- package/table/controllers/utils/getTemplates.js +18 -18
- package/table/controllers/utils/gisIRColumn.js +72 -67
- package/table/controllers/utils/loadTemplate.js +1 -1
- package/table/controllers/utils/loadTemplatePath.js +1 -1
- package/table/controllers/utils/userTemplateDir.js +1 -1
- package/table/funcs/getFilterSQL/index.js +94 -94
- package/table/funcs/getFilterSQL/util/formatValue.js +170 -170
- package/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
- package/table/funcs/getFilterSQL/util/getFilterQuery.js +66 -66
- package/table/funcs/getFilterSQL/util/getOptimizedQuery.js +12 -12
- package/table/funcs/getFilterSQL/util/getTableSql.js +34 -34
- package/table/funcs/metaFormat/getSelectVal.js +21 -21
- package/table/funcs/metaFormat/index.js +28 -28
- package/table/index.js +37 -37
- package/table/schema.js +64 -54
- package/test/api/applyHook.test.js +95 -95
- package/test/api/crud.test.js +89 -89
- package/test/api/crud.xss.test.js +80 -80
- package/test/api/suggest.test.js +66 -66
- package/test/api/table.test.js +134 -134
- package/test/api/user.test.js +85 -85
- package/test/api/widget.test.js +117 -117
- package/test/config.example +18 -18
- package/test/funcs/pg.test.js +34 -34
- package/test/funcs/redis.test.js +19 -19
- package/test/helper/formatDate.test.js +62 -62
- package/test/templates/cls/test.json +9 -9
- package/test/templates/form/cp_building.form.json +32 -32
- package/test/templates/select/account_id.json +3 -3
- package/test/templates/select/storage.data.json +2 -2
- package/test/templates/select/test.storage.data.json +3 -3
- package/test/templates/select/test.suggest.ato_new.json +3 -3
- package/test/templates/select/test.suggest.ato_new.sql +25 -25
- package/test/templates/select/test.suggest.data.json +4 -4
- package/test/templates/select/test.suggest.parent.sql +1 -1
- package/test/templates/table/gis.dataset.table.json +20 -20
- package/user/controllers/user.cls.id.js +14 -14
- package/user/controllers/user.cls.js +71 -75
- package/user/controllers/user.cls.post.js +52 -55
- package/user/controllers/user.info.js +17 -21
- package/user/index.js +7 -36
- package/user/schema.js +17 -0
- package/util/controllers/logger.file.js +91 -91
- package/util/controllers/next.id.js +4 -4
- package/util/controllers/properties.add.js +56 -60
- package/util/controllers/properties.get.js +16 -19
- package/util/controllers/status.monitor.js +8 -8
- package/util/controllers/utils/checkUserAccess.js +20 -17
- package/util/controllers/utils/getRootDir.js +25 -25
- package/util/index.js +19 -23
- package/util/schema.js +19 -0
- package/utils.js +106 -104
- package/widget/controllers/utils/historyFormat.js +76 -76
- package/widget/controllers/utils/obj2db.js +13 -13
- package/widget/controllers/widget.del.js +41 -44
- package/widget/controllers/widget.get.js +96 -102
- package/widget/controllers/widget.set.js +74 -79
- package/widget/index.js +40 -40
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
export default async function userInfo({
|
|
2
|
-
pg, session = {},
|
|
3
|
-
}) {
|
|
4
|
-
const { uid } = session.passport?.user || {};
|
|
5
|
-
|
|
6
|
-
if (!uid) {
|
|
7
|
-
return { message: 'access restricted', status: 403 };
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const data = await pg.query(`select user_name, sur_name, father_name, user_rnokpp, user_type, email, login from admin.users
|
|
11
|
-
where uid=$1`, [uid]).then((res) => res.rows?.[0] || {});
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
catch (err) {
|
|
19
|
-
return { error: err.toString(), status: 500 };
|
|
20
|
-
}
|
|
21
|
-
}
|
|
1
|
+
export default async function userInfo({
|
|
2
|
+
pg, session = {},
|
|
3
|
+
}) {
|
|
4
|
+
const { uid } = session.passport?.user || {};
|
|
5
|
+
|
|
6
|
+
if (!uid) {
|
|
7
|
+
return { message: 'access restricted', status: 403 };
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const data = await pg.query(`select user_name, sur_name, father_name, user_rnokpp, user_type, email, login from admin.users
|
|
11
|
+
where uid=$1`, [uid]).then((res) => res.rows?.[0] || {});
|
|
12
|
+
|
|
13
|
+
const { notifications = 0 } = await pg.query(`select count(*)::int as notifications from crm.notifications
|
|
14
|
+
where addressee_id=$1 and read is not true`, [uid]).then((res) => res.rows?.[0] || {});
|
|
15
|
+
return { uid, ...data, notifications };
|
|
16
|
+
|
|
17
|
+
}
|
package/user/index.js
CHANGED
|
@@ -3,44 +3,15 @@ import userClsId from './controllers/user.cls.id.js';
|
|
|
3
3
|
import userInfo from './controllers/user.info.js';
|
|
4
4
|
import userClsPost from './controllers/user.cls.post.js';
|
|
5
5
|
|
|
6
|
+
import { userClsSchema, userClsIdSchema } from './schema.js'
|
|
7
|
+
|
|
6
8
|
async function plugin(fastify, opts) {
|
|
7
9
|
const { prefix = '/api' } = opts || {};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
},
|
|
14
|
-
schema: {},
|
|
15
|
-
handler: userCls,
|
|
16
|
-
});
|
|
17
|
-
fastify.route({
|
|
18
|
-
method: 'GET',
|
|
19
|
-
url: `${prefix}/user-cls/:id`,
|
|
20
|
-
config: {
|
|
21
|
-
policy: ['user'],
|
|
22
|
-
},
|
|
23
|
-
schema: {},
|
|
24
|
-
handler: userClsId,
|
|
25
|
-
});
|
|
26
|
-
fastify.route({
|
|
27
|
-
method: 'POST',
|
|
28
|
-
url: `${prefix}/user-cls`,
|
|
29
|
-
config: {
|
|
30
|
-
policy: ['user'],
|
|
31
|
-
},
|
|
32
|
-
schema: {},
|
|
33
|
-
handler: userClsPost,
|
|
34
|
-
});
|
|
35
|
-
fastify.route({
|
|
36
|
-
method: 'GET',
|
|
37
|
-
url: `${prefix}/user-info`,
|
|
38
|
-
config: {
|
|
39
|
-
policy: ['user'],
|
|
40
|
-
},
|
|
41
|
-
schema: {},
|
|
42
|
-
handler: userInfo,
|
|
43
|
-
});
|
|
10
|
+
|
|
11
|
+
fastify.get(`${prefix}/user-cls`, { config: { policy: ['user'] }, schema: userClsSchema }, userCls);
|
|
12
|
+
fastify.get(`${prefix}/user-cls/:id`, { config: { policy: ['user'] }, schema: userClsIdSchema }, userClsId);
|
|
13
|
+
fastify.get(`${prefix}/user-info`, { config: { policy: ['user'] } }, userInfo);
|
|
14
|
+
fastify.post(`${prefix}/user-cls/:id`, { config: { policy: ['user'] }, schema: userClsIdSchema }, userClsPost);
|
|
44
15
|
}
|
|
45
16
|
|
|
46
17
|
export default plugin;
|
package/user/schema.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const userClsSchema = {
|
|
2
|
+
params: {
|
|
3
|
+
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
4
|
+
},
|
|
5
|
+
quertstring: {
|
|
6
|
+
sql: { type: 'string', pattern: '^(\\d)$' },
|
|
7
|
+
},
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const userClsIdSchema = {
|
|
11
|
+
params: {
|
|
12
|
+
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { userClsSchema, userClsIdSchema };
|
|
17
|
+
export default null;
|
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { lstat, readdir, readFile } from 'fs/promises';
|
|
3
|
-
import { createReadStream, existsSync } from 'fs';
|
|
4
|
-
import readline from 'readline';
|
|
5
|
-
|
|
6
|
-
import checkUserAccess from './utils/checkUserAccess.js';
|
|
7
|
-
import getRootDir from './utils/getRootDir.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
* @method GET
|
|
12
|
-
* @summary API для перегляду логів
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
export default async function loggerFile({
|
|
17
|
-
params = {}, user = {}, query = {}, originalUrl,
|
|
18
|
-
}, reply) {
|
|
19
|
-
const limit = 200000;
|
|
20
|
-
const access =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (access?.status
|
|
24
|
-
|
|
25
|
-
// absolute / relative path
|
|
26
|
-
const rootDir = getRootDir();
|
|
27
|
-
|
|
28
|
-
const filepath = path.join(rootDir, params['*'] || '');
|
|
29
|
-
|
|
30
|
-
if (!existsSync(filepath)) {
|
|
31
|
-
return {
|
|
32
|
-
}
|
|
33
|
-
const stat = await lstat(filepath);
|
|
34
|
-
const isFile = stat.isFile();
|
|
35
|
-
|
|
36
|
-
if (query.download && isFile) {
|
|
37
|
-
return reply.download(filepath);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (query.full && isFile) {
|
|
41
|
-
if (stat.size > 20 * 1000 * 1000) {
|
|
42
|
-
return { message: 'file size > 20MB' };
|
|
43
|
-
}
|
|
44
|
-
const buffer = await readFile(filepath, { buffer: true });
|
|
45
|
-
return buffer;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (isFile) {
|
|
49
|
-
const ext = path.extname(filepath);
|
|
50
|
-
|
|
51
|
-
const lines = await new Promise((resolve) => {
|
|
52
|
-
const rl = readline.createInterface({
|
|
53
|
-
input: createReadStream(filepath, { start: stat.size > limit ? stat.size - limit : 0 }),
|
|
54
|
-
});
|
|
55
|
-
const lines1 = [];
|
|
56
|
-
rl.on('close', () => resolve(lines1));
|
|
57
|
-
rl.on('line', (line) => lines1.push(line));
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
if (ext === '.html') {
|
|
61
|
-
const buffer = await readFile(filepath, { buffer: true });
|
|
62
|
-
reply.headers({ 'Content-type': 'text/html; charset=UTF-8' });
|
|
63
|
-
return buffer;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
reply.headers({ 'Content-type': 'text/plain' });
|
|
67
|
-
return stat.size > limit && lines.length > 1
|
|
68
|
-
? lines.reverse().slice(0, -1).join('\n')
|
|
69
|
-
: lines.reverse().join('\n');
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// dir
|
|
73
|
-
const files = await readdir(filepath);
|
|
74
|
-
|
|
75
|
-
if (query.dir) {
|
|
76
|
-
return files.filter((el) => !['backup', 'marker_icon', 'error', 'migration'].includes(el));
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const lstatsArr = await Promise.all(files.map(async (file) => [file, await lstat(path.join(filepath, file))]));
|
|
80
|
-
const lstats = Object.fromEntries(lstatsArr);
|
|
81
|
-
|
|
82
|
-
const message = (params['*'] ? '<a href="/logger-file/">...</a><br>' : '')
|
|
83
|
-
+ files.map((file) => `<a href="${originalUrl}/${file}">${file}</a> (${lstats[file].size} bytes)`).join('</br>');
|
|
84
|
-
|
|
85
|
-
reply.headers({
|
|
86
|
-
'Content-Type': 'text/html; charset=UTF-8',
|
|
87
|
-
'Content-Security-Policy': "default-src 'none'",
|
|
88
|
-
'X-Content-Type-Options': 'nosniff',
|
|
89
|
-
});
|
|
90
|
-
return message;
|
|
91
|
-
}
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { lstat, readdir, readFile } from 'fs/promises';
|
|
3
|
+
import { createReadStream, existsSync } from 'fs';
|
|
4
|
+
import readline from 'readline';
|
|
5
|
+
|
|
6
|
+
import checkUserAccess from './utils/checkUserAccess.js';
|
|
7
|
+
import getRootDir from './utils/getRootDir.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @method GET
|
|
12
|
+
* @summary API для перегляду логів
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export default async function loggerFile({
|
|
17
|
+
log, params = {}, user = {}, query = {}, originalUrl,
|
|
18
|
+
}, reply) {
|
|
19
|
+
const limit = 200000;
|
|
20
|
+
const access = checkUserAccess({ user });
|
|
21
|
+
// log.info('Сервер запущен по адресу?'); // test!
|
|
22
|
+
|
|
23
|
+
if (access?.status !== 200) return access;
|
|
24
|
+
|
|
25
|
+
// absolute / relative path
|
|
26
|
+
const rootDir = getRootDir();
|
|
27
|
+
|
|
28
|
+
const filepath = path.join(rootDir, params['*'] || '');
|
|
29
|
+
|
|
30
|
+
if (!existsSync(filepath)) {
|
|
31
|
+
return { message: 'file not exists', status: 404 };
|
|
32
|
+
}
|
|
33
|
+
const stat = await lstat(filepath);
|
|
34
|
+
const isFile = stat.isFile();
|
|
35
|
+
|
|
36
|
+
if (query.download && isFile) {
|
|
37
|
+
return reply.download(filepath);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (query.full && isFile) {
|
|
41
|
+
if (stat.size > 20 * 1000 * 1000) {
|
|
42
|
+
return { message: 'file size > 20MB' };
|
|
43
|
+
}
|
|
44
|
+
const buffer = await readFile(filepath, { buffer: true });
|
|
45
|
+
return buffer;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (isFile) {
|
|
49
|
+
const ext = path.extname(filepath);
|
|
50
|
+
|
|
51
|
+
const lines = await new Promise((resolve) => {
|
|
52
|
+
const rl = readline.createInterface({
|
|
53
|
+
input: createReadStream(filepath, { start: stat.size > limit ? stat.size - limit : 0 }),
|
|
54
|
+
});
|
|
55
|
+
const lines1 = [];
|
|
56
|
+
rl.on('close', () => resolve(lines1));
|
|
57
|
+
rl.on('line', (line) => lines1.push(line));
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
if (ext === '.html') {
|
|
61
|
+
const buffer = await readFile(filepath, { buffer: true });
|
|
62
|
+
reply.headers({ 'Content-type': 'text/html; charset=UTF-8' });
|
|
63
|
+
return buffer;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
reply.headers({ 'Content-type': 'text/plain' });
|
|
67
|
+
return stat.size > limit && lines.length > 1
|
|
68
|
+
? lines.reverse().slice(0, -1).join('\n')
|
|
69
|
+
: lines.reverse().join('\n');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// dir
|
|
73
|
+
const files = await readdir(filepath);
|
|
74
|
+
|
|
75
|
+
if (query.dir) {
|
|
76
|
+
return files.filter((el) => !['backup', 'marker_icon', 'error', 'migration'].includes(el));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const lstatsArr = await Promise.all(files.map(async (file) => [file, await lstat(path.join(filepath, file))]));
|
|
80
|
+
const lstats = Object.fromEntries(lstatsArr);
|
|
81
|
+
|
|
82
|
+
const message = (params['*'] ? '<a href="/logger-file/">...</a><br>' : '')
|
|
83
|
+
+ files.map((file) => `<a href="${originalUrl}/${file}">${file}</a> (${lstats[file].size} bytes)`).join('</br>');
|
|
84
|
+
|
|
85
|
+
reply.headers({
|
|
86
|
+
'Content-Type': 'text/html; charset=UTF-8',
|
|
87
|
+
'Content-Security-Policy': "default-src 'none'",
|
|
88
|
+
'X-Content-Type-Options': 'nosniff',
|
|
89
|
+
});
|
|
90
|
+
return message;
|
|
91
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default async function nextId({ pg }) {
|
|
2
|
-
const { id } = await pg.one('select next_id() as id');
|
|
3
|
-
return { id: id.toString() };
|
|
4
|
-
};
|
|
1
|
+
export default async function nextId({ pg }) {
|
|
2
|
+
const { id } = await pg.one('select next_id() as id');
|
|
3
|
+
return { id: id.toString() };
|
|
4
|
+
};
|
|
@@ -1,60 +1,56 @@
|
|
|
1
|
-
import { dataInsert, config } from '../../utils.js';
|
|
2
|
-
|
|
3
|
-
const table = 'crm.properties';
|
|
4
|
-
|
|
5
|
-
function checkKeyType({ body, key }) {
|
|
6
|
-
if (typeof body[key] === 'number' && (!/\D/.test(body[key].toString()) && body[key].toString().length < 10)) {
|
|
7
|
-
return { [key]: 'int' };
|
|
8
|
-
} if (typeof body[key] === 'object') {
|
|
9
|
-
return { [key]: 'json' };
|
|
10
|
-
}
|
|
11
|
-
if (Date.parse(body[key], 'yyyy/MM/ddTHH:mm:ss.000Z')) {
|
|
12
|
-
return { [key]: 'date' };
|
|
13
|
-
}
|
|
14
|
-
return { [key]: 'text' };
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export default async function addExtraProperties({
|
|
18
|
-
pg, params = {}, body = {}, user = {},
|
|
19
|
-
}) {
|
|
20
|
-
const { id } = params;
|
|
21
|
-
const { uid } = user;
|
|
22
|
-
if (!uid) {
|
|
23
|
-
return { message: 'access restricted: uid', status: 403 };
|
|
24
|
-
}
|
|
25
|
-
if (!id) {
|
|
26
|
-
return { message: 'not enougn params: 1', status: 400 };
|
|
27
|
-
}
|
|
28
|
-
const extraProperties = Object.keys(body);
|
|
29
|
-
if (!extraProperties.length) {
|
|
30
|
-
return { message: 'not enougn params: 2', status: 400 };
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (!pg.pk?.[table]) {
|
|
34
|
-
return { message: 'table not found: crm.properties', status: 400 };
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
await pg.query('delete from crm.properties where object_id=$1', [id]); // rewrite?
|
|
39
|
-
const keyTypeMatch = extraProperties.filter((key) => body[key]).reduce((acc, curr) => Object.assign(acc, checkKeyType({ body, key: curr })), {});
|
|
40
|
-
const res = await Promise.all(Object.keys(keyTypeMatch).map(async (key) => {
|
|
41
|
-
const propertyType = keyTypeMatch[key];
|
|
42
|
-
const { rows = [] } = await dataInsert({
|
|
43
|
-
pg,
|
|
44
|
-
table,
|
|
45
|
-
data: {
|
|
46
|
-
property_type: propertyType,
|
|
47
|
-
property_key: key,
|
|
48
|
-
object_id: id,
|
|
49
|
-
[`property_${propertyType}`]: body[key],
|
|
50
|
-
},
|
|
51
|
-
uid,
|
|
52
|
-
});
|
|
53
|
-
return { id: rows[0]?.property_id, type: propertyType, value: body[key] };
|
|
54
|
-
}));
|
|
55
|
-
return { message: { rows: res }, status: 200 };
|
|
56
|
-
|
|
57
|
-
catch (err) {
|
|
58
|
-
return { error: err.toString(), status: 500 };
|
|
59
|
-
}
|
|
60
|
-
}
|
|
1
|
+
import { dataInsert, config } from '../../utils.js';
|
|
2
|
+
|
|
3
|
+
const table = 'crm.properties';
|
|
4
|
+
|
|
5
|
+
function checkKeyType({ body, key }) {
|
|
6
|
+
if (typeof body[key] === 'number' && (!/\D/.test(body[key].toString()) && body[key].toString().length < 10)) {
|
|
7
|
+
return { [key]: 'int' };
|
|
8
|
+
} if (typeof body[key] === 'object') {
|
|
9
|
+
return { [key]: 'json' };
|
|
10
|
+
}
|
|
11
|
+
if (Date.parse(body[key], 'yyyy/MM/ddTHH:mm:ss.000Z')) {
|
|
12
|
+
return { [key]: 'date' };
|
|
13
|
+
}
|
|
14
|
+
return { [key]: 'text' };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default async function addExtraProperties({
|
|
18
|
+
pg, params = {}, body = {}, user = {},
|
|
19
|
+
}) {
|
|
20
|
+
const { id } = params;
|
|
21
|
+
const { uid } = user;
|
|
22
|
+
if (!uid) {
|
|
23
|
+
return { message: 'access restricted: uid', status: 403 };
|
|
24
|
+
}
|
|
25
|
+
if (!id) {
|
|
26
|
+
return { message: 'not enougn params: 1', status: 400 };
|
|
27
|
+
}
|
|
28
|
+
const extraProperties = Object.keys(body);
|
|
29
|
+
if (!extraProperties.length) {
|
|
30
|
+
return { message: 'not enougn params: 2', status: 400 };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!pg.pk?.[table]) {
|
|
34
|
+
return { message: 'table not found: crm.properties', status: 400 };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
await pg.query('delete from crm.properties where object_id=$1', [id]); // rewrite?
|
|
39
|
+
const keyTypeMatch = extraProperties.filter((key) => body[key]).reduce((acc, curr) => Object.assign(acc, checkKeyType({ body, key: curr })), {});
|
|
40
|
+
const res = await Promise.all(Object.keys(keyTypeMatch).map(async (key) => {
|
|
41
|
+
const propertyType = keyTypeMatch[key];
|
|
42
|
+
const { rows = [] } = await dataInsert({
|
|
43
|
+
pg,
|
|
44
|
+
table,
|
|
45
|
+
data: {
|
|
46
|
+
property_type: propertyType,
|
|
47
|
+
property_key: key,
|
|
48
|
+
object_id: id,
|
|
49
|
+
[`property_${propertyType}`]: body[key],
|
|
50
|
+
},
|
|
51
|
+
uid,
|
|
52
|
+
});
|
|
53
|
+
return { id: rows[0]?.property_id, type: propertyType, value: body[key] };
|
|
54
|
+
}));
|
|
55
|
+
return { message: { rows: res }, status: 200 };
|
|
56
|
+
}
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
export default async function getExtraProperties({
|
|
2
|
-
pg, params = {},
|
|
3
|
-
}) {
|
|
4
|
-
const { id } = params;
|
|
5
|
-
if (!id) {
|
|
6
|
-
return { message: 'not enougn params', status: 400 };
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const { rows = [] } = pg.pk?.['crm.properties']
|
|
10
|
-
? await pg.query(`select property_key, property_type, property_text, property_int,
|
|
11
|
-
property_json, property_date from crm.properties where property_key is not null and object_id=$1`, [id])
|
|
12
|
-
: {};
|
|
13
|
-
if (!rows.length) return {};
|
|
14
|
-
|
|
15
|
-
const data = rows.reduce((acc, curr) => Object.assign(acc, { [curr.property_key]: curr[`property_${curr.property_type}`] }), {});
|
|
16
|
-
return { message: data, status: 200 };
|
|
17
|
-
} catch (err) {
|
|
18
|
-
return { error: err.toString(), status: 500 };
|
|
19
|
-
}
|
|
1
|
+
export default async function getExtraProperties({
|
|
2
|
+
pg, params = {},
|
|
3
|
+
}) {
|
|
4
|
+
const { id } = params;
|
|
5
|
+
if (!id) {
|
|
6
|
+
return { message: 'not enougn params', status: 400 };
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const { rows = [] } = pg.pk?.['crm.properties']
|
|
10
|
+
? await pg.query(`select property_key, property_type, property_text, property_int,
|
|
11
|
+
property_json, property_date from crm.properties where property_key is not null and object_id=$1`, [id])
|
|
12
|
+
: {};
|
|
13
|
+
if (!rows.length) return {};
|
|
14
|
+
|
|
15
|
+
const data = rows.reduce((acc, curr) => Object.assign(acc, { [curr.property_key]: curr[`property_${curr.property_type}`] }), {});
|
|
16
|
+
return { message: data, status: 200 };
|
|
20
17
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const formatMemoryUsage = (data) => `${Math.round(data / 1024 / 1024 * 100) / 100} MB`;
|
|
2
|
-
|
|
3
|
-
export default async function statusMonitor() {
|
|
4
|
-
const memoryUsage = process.memoryUsage();
|
|
5
|
-
const message = Object.keys(memoryUsage)
|
|
6
|
-
.reduce((acc, curr) => Object.assign(acc, { [curr]: formatMemoryUsage(memoryUsage[curr]) }), {});
|
|
7
|
-
return { message, status: 200 };
|
|
8
|
-
}
|
|
1
|
+
const formatMemoryUsage = (data) => `${Math.round(data / 1024 / 1024 * 100) / 100} MB`;
|
|
2
|
+
|
|
3
|
+
export default async function statusMonitor() {
|
|
4
|
+
const memoryUsage = process.memoryUsage();
|
|
5
|
+
const message = Object.keys(memoryUsage)
|
|
6
|
+
.reduce((acc, curr) => Object.assign(acc, { [curr]: formatMemoryUsage(memoryUsage[curr]) }), {});
|
|
7
|
+
return { message, status: 200 };
|
|
8
|
+
}
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
1
|
+
import config from '../../../config.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @summary check user access to logger interface - per admin user type or user group
|
|
6
|
+
* @returns {Object} message, status
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export default function checkUserAccess({
|
|
10
|
+
user = {},
|
|
11
|
+
}) {
|
|
12
|
+
if (user?.uid && !config?.local) {
|
|
13
|
+
return { message: 'access restricted', status: 403 };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/* if (!['admin', 'superadmin']?.includes(user.user_type) && count === '0') {
|
|
17
|
+
return { message: 'access restricted', status: 403 };
|
|
18
|
+
} */
|
|
19
|
+
return { message: 'access granted', status: 200 };
|
|
20
|
+
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import config from '../../../config.js';
|
|
4
|
-
|
|
5
|
-
// import { existsSync } from 'fs';
|
|
6
|
-
let logDir = null;
|
|
7
|
-
export default function getRootDir() {
|
|
8
|
-
// absolute / relative path
|
|
9
|
-
if (logDir) return logDir;
|
|
10
|
-
const file = ['config.json', '/data/local/config.json'].find(el => (fs.existsSync(el) ? el : null));
|
|
11
|
-
const root = file === 'config.json' ? process.cwd() : '/data/local';
|
|
12
|
-
logDir = config.logDir || path.join(root, config.log?.dir || 'log');
|
|
13
|
-
console.log({ logDir });
|
|
14
|
-
return logDir;
|
|
15
|
-
|
|
16
|
-
// windows debug support
|
|
17
|
-
/* const customLogDir = process.cwd().includes(':') ? 'c:/data/local' : '/data/local';
|
|
18
|
-
// docker default path
|
|
19
|
-
if (existsSync(customLogDir)) {
|
|
20
|
-
return path.join(customLogDir, config.folder || '', 'log');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// non-docker default path
|
|
24
|
-
return path.join(config.root || '/data/local', config.folder || '', 'log'); */
|
|
25
|
-
}
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import config from '../../../config.js';
|
|
4
|
+
|
|
5
|
+
// import { existsSync } from 'fs';
|
|
6
|
+
let logDir = null;
|
|
7
|
+
export default function getRootDir() {
|
|
8
|
+
// absolute / relative path
|
|
9
|
+
if (logDir) return logDir;
|
|
10
|
+
const file = ['config.json', '/data/local/config.json'].find(el => (fs.existsSync(el) ? el : null));
|
|
11
|
+
const root = file === 'config.json' ? process.cwd() : '/data/local';
|
|
12
|
+
logDir = config.logDir || path.join(root, config.log?.dir || 'log');
|
|
13
|
+
console.log({ logDir });
|
|
14
|
+
return logDir;
|
|
15
|
+
|
|
16
|
+
// windows debug support
|
|
17
|
+
/* const customLogDir = process.cwd().includes(':') ? 'c:/data/local' : '/data/local';
|
|
18
|
+
// docker default path
|
|
19
|
+
if (existsSync(customLogDir)) {
|
|
20
|
+
return path.join(customLogDir, config.folder || '', 'log');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// non-docker default path
|
|
24
|
+
return path.join(config.root || '/data/local', config.folder || '', 'log'); */
|
|
25
|
+
}
|
package/util/index.js
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
import getExtraProperties from './controllers/properties.get.js';
|
|
2
|
-
import addExtraProperties from './controllers/properties.add.js';
|
|
3
|
-
import nextId from './controllers/next.id.js';
|
|
4
|
-
import statusMonitor from './controllers/status.monitor.js';
|
|
5
|
-
import loggerFile from './controllers/logger.file.js';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
fastify.get(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
fastify.get('/logger-file/*', { config: { policy: ['log'] } }, loggerFile);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export default plugin;
|
|
1
|
+
import getExtraProperties from './controllers/properties.get.js';
|
|
2
|
+
import addExtraProperties from './controllers/properties.add.js';
|
|
3
|
+
import nextId from './controllers/next.id.js';
|
|
4
|
+
import statusMonitor from './controllers/status.monitor.js';
|
|
5
|
+
import loggerFile from './controllers/logger.file.js';
|
|
6
|
+
|
|
7
|
+
import { propertiesSchema, loggerSchema } from './schema.js'
|
|
8
|
+
|
|
9
|
+
async function plugin(fastify, config = {}) {
|
|
10
|
+
const prefix = config.prefix || '/api';
|
|
11
|
+
|
|
12
|
+
fastify.get(`${prefix}/next-id`, {}, nextId);
|
|
13
|
+
fastify.get(`${prefix}/status-monitor`, {}, statusMonitor);
|
|
14
|
+
fastify.get(`${prefix}/properties/:id`, { schema: propertiesSchema }, getExtraProperties);
|
|
15
|
+
fastify.post(`${prefix}/properties/:id`, { schema: propertiesSchema }, addExtraProperties);
|
|
16
|
+
fastify.get('/logger-file/*', { config: { policy: ['log'] }, schema: loggerSchema }, loggerFile);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default plugin;
|
package/util/schema.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const propertiesSchema = {
|
|
2
|
+
params: {
|
|
3
|
+
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
4
|
+
},
|
|
5
|
+
};
|
|
6
|
+
const loggerSchema = {
|
|
7
|
+
// params: {
|
|
8
|
+
//
|
|
9
|
+
// },
|
|
10
|
+
querystring: {
|
|
11
|
+
download: { type: 'string', pattern: '^(\\d+)$' },
|
|
12
|
+
full: { type: 'string', pattern: '^(\\d+)$' },
|
|
13
|
+
dir: { type: 'string', pattern: '^(\\d+)$' },
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
export {
|
|
17
|
+
propertiesSchema, loggerSchema
|
|
18
|
+
}
|
|
19
|
+
export default null;
|