@opengis/fastify-table 1.2.32 → 1.2.34
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/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/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/funcs/getPG.js +10 -1
- package/server/plugins/pg/funcs/getPGAsync.js +10 -1
- package/server/plugins/pg/pgClients.js +21 -21
- package/server/plugins/policy/funcs/checkPolicy.js +1 -1
- 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 +96 -96
- 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/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 +91 -91
- 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/form.js +42 -42
- package/server/routes/table/controllers/search.js +74 -74
- package/server/routes/table/controllers/suggest.js +1 -1
- 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,91 +1,91 @@
|
|
|
1
|
-
import {
|
|
2
|
-
config, getAccess, getTemplate, getMeta, setToken, applyHook, getToken,
|
|
3
|
-
} from '../../../../utils.js';
|
|
4
|
-
|
|
5
|
-
export default async function tableAPI(req) {
|
|
6
|
-
const {
|
|
7
|
-
pg, params, user = {}, query = {},
|
|
8
|
-
} = req;
|
|
9
|
-
const tokenData = await getToken({ token: params?.table, uid: user.uid, json: 1 }) || {};
|
|
10
|
-
|
|
11
|
-
const hookData = await applyHook('preTable', {
|
|
12
|
-
table: params?.table, id: params?.id, ...tokenData || {}, user,
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
if (hookData?.message && hookData?.status) {
|
|
16
|
-
return { message: hookData?.message, status: hookData?.status };
|
|
17
|
-
}
|
|
18
|
-
const tableName1 = hookData?.table || tokenData.table || params.table;
|
|
19
|
-
|
|
20
|
-
const loadTable = await getTemplate('table', tableName1) || {};
|
|
21
|
-
if (!loadTable && !pg.pk?.[tokenData.table]) {
|
|
22
|
-
return { message: 'not found', status: 404 };
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const { table, /* columns, */ form } = loadTable;
|
|
26
|
-
|
|
27
|
-
const tableName = table || hookData?.table || tokenData.table || params.table;
|
|
28
|
-
|
|
29
|
-
const id = hookData?.id || tokenData.id || params.id;
|
|
30
|
-
|
|
31
|
-
if (tokenData && !id) return { message: {} };
|
|
32
|
-
if (!tableName && !id) {
|
|
33
|
-
return { message: 'not enough params', status: 400 };
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const { actions = [], query: accessQuery } = await getAccess({
|
|
37
|
-
table: hookData?.table || tokenData.table || params.table,
|
|
38
|
-
id,
|
|
39
|
-
user,
|
|
40
|
-
}) || {};
|
|
41
|
-
|
|
42
|
-
if (!actions.includes('edit') && !config?.local && !tokenData) {
|
|
43
|
-
return { message: 'access restricted', status: 403 };
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const { pk, columns: dbColumns = [] } = await getMeta(tableName);
|
|
47
|
-
if (!pk) return { message: `table not found: ${table}`, status: 404 };
|
|
48
|
-
|
|
49
|
-
// const cols = columns.map((el) => el.name || el).join(',');
|
|
50
|
-
const formName = hookData?.form || tokenData?.form || form;
|
|
51
|
-
const formData = await getTemplate('form', formName) || {};
|
|
52
|
-
const schema = formData?.schema || formData;
|
|
53
|
-
// skip DataTable from another table
|
|
54
|
-
const extraKeys = Object.keys(schema)?.filter((key) => schema[key]?.type === 'DataTable' && schema[key]?.table && schema[key]?.parent_id && schema[key]?.colModel?.length);
|
|
55
|
-
// skip non-existing columns
|
|
56
|
-
const columnList = dbColumns.map((el) => el.name || el).join(',');
|
|
57
|
-
|
|
58
|
-
const { fields = [] } = !loadTable?.table ? await pg.query(`select * from ${tableName} limit 0`) : {};
|
|
59
|
-
const cols = loadTable?.table
|
|
60
|
-
? Object.keys(schema || {}).filter((col) => columnList.includes(col) && !extraKeys.includes(col))?.map((col) => (col?.includes('geom') && schema?.[col]?.type === 'Geom' ? `st_asgeojson(${col})::json as "${col}"` : `"${col}"`))?.join(',')
|
|
61
|
-
: fields.map((el) => (el?.name?.includes('geom') && pg.pgType[el?.dataTypeID] === 'geometry' ? `st_asgeojson(${el.name})::json as "${el.name}"` : `"${el?.name}"`)).join(',');
|
|
62
|
-
const where = [`"${pk}" = $1`, loadTable.query, accessQuery].filter((el) => el);
|
|
63
|
-
const geom = dbColumns.find((el) => el.name === 'geom' && pg.pgType[el.dataTypeID] === 'geometry') ? ',st_asgeojson(geom)::json as geom' : '';
|
|
64
|
-
const q = `select "${pk}" as id, ${cols || '*'} ${geom} from ${tableName} t where ${where.join(' and ') || 'true'} limit 1`;
|
|
65
|
-
|
|
66
|
-
if (query?.sql === '1') return q;
|
|
67
|
-
|
|
68
|
-
const data = await pg.query(q, [id]).then(el => el.rows[0]);
|
|
69
|
-
if (!data) return { message: 'not found', status: 404 };
|
|
70
|
-
|
|
71
|
-
if (extraKeys?.length) {
|
|
72
|
-
await Promise.all(extraKeys?.map(async (key) => {
|
|
73
|
-
const { colModel, table: extraTable, parent_id: parentId } = schema[key];
|
|
74
|
-
const q1 = `select ${parentId} as parent, ${colModel.map((col) => col.name || col.key).join(',')} from ${extraTable} a where ${parentId}=$1`;
|
|
75
|
-
// console.log(tableName, formName, q1);
|
|
76
|
-
const { rows: extraRows } = await pg.query(q1, [hookData?.id || tokenData?.id || params?.id]);
|
|
77
|
-
Object.assign(data, { [key]: extraRows });
|
|
78
|
-
}));
|
|
79
|
-
}
|
|
80
|
-
if (user?.uid && actions?.includes?.('edit')) {
|
|
81
|
-
data.token = tokenData?.table ? params.table : setToken({
|
|
82
|
-
ids: [JSON.stringify({ id, table: tableName, form: loadTable.form })],
|
|
83
|
-
uid: user.uid,
|
|
84
|
-
array: 1,
|
|
85
|
-
})[0];
|
|
86
|
-
}
|
|
87
|
-
const res = await applyHook('afterTable', {
|
|
88
|
-
table: tableName, payload: [data], user,
|
|
89
|
-
});
|
|
90
|
-
return res || data || {};
|
|
91
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
config, getAccess, getTemplate, getMeta, setToken, applyHook, getToken,
|
|
3
|
+
} from '../../../../utils.js';
|
|
4
|
+
|
|
5
|
+
export default async function tableAPI(req) {
|
|
6
|
+
const {
|
|
7
|
+
pg, params, user = {}, query = {},
|
|
8
|
+
} = req;
|
|
9
|
+
const tokenData = await getToken({ token: params?.table, uid: user.uid, json: 1 }) || {};
|
|
10
|
+
|
|
11
|
+
const hookData = await applyHook('preTable', {
|
|
12
|
+
table: params?.table, id: params?.id, ...tokenData || {}, user,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
if (hookData?.message && hookData?.status) {
|
|
16
|
+
return { message: hookData?.message, status: hookData?.status };
|
|
17
|
+
}
|
|
18
|
+
const tableName1 = hookData?.table || tokenData.table || params.table;
|
|
19
|
+
|
|
20
|
+
const loadTable = await getTemplate('table', tableName1) || {};
|
|
21
|
+
if (!loadTable && !pg.pk?.[tokenData.table]) {
|
|
22
|
+
return { message: 'not found', status: 404 };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const { table, /* columns, */ form } = loadTable;
|
|
26
|
+
|
|
27
|
+
const tableName = table || hookData?.table || tokenData.table || params.table;
|
|
28
|
+
|
|
29
|
+
const id = hookData?.id || tokenData.id || params.id;
|
|
30
|
+
|
|
31
|
+
if (tokenData && !id) return { message: {} };
|
|
32
|
+
if (!tableName && !id) {
|
|
33
|
+
return { message: 'not enough params', status: 400 };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const { actions = [], query: accessQuery } = await getAccess({
|
|
37
|
+
table: hookData?.table || tokenData.table || params.table,
|
|
38
|
+
id,
|
|
39
|
+
user,
|
|
40
|
+
}) || {};
|
|
41
|
+
|
|
42
|
+
if (!actions.includes('edit') && !config?.local && !tokenData) {
|
|
43
|
+
return { message: 'access restricted', status: 403 };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const { pk, columns: dbColumns = [] } = await getMeta(tableName);
|
|
47
|
+
if (!pk) return { message: `table not found: ${table}`, status: 404 };
|
|
48
|
+
|
|
49
|
+
// const cols = columns.map((el) => el.name || el).join(',');
|
|
50
|
+
const formName = hookData?.form || tokenData?.form || form;
|
|
51
|
+
const formData = await getTemplate('form', formName) || {};
|
|
52
|
+
const schema = formData?.schema || formData;
|
|
53
|
+
// skip DataTable from another table
|
|
54
|
+
const extraKeys = Object.keys(schema)?.filter((key) => schema[key]?.type === 'DataTable' && schema[key]?.table && schema[key]?.parent_id && schema[key]?.colModel?.length);
|
|
55
|
+
// skip non-existing columns
|
|
56
|
+
const columnList = dbColumns.map((el) => el.name || el).join(',');
|
|
57
|
+
|
|
58
|
+
const { fields = [] } = !loadTable?.table ? await pg.query(`select * from ${tableName} limit 0`) : {};
|
|
59
|
+
const cols = loadTable?.table
|
|
60
|
+
? Object.keys(schema || {}).filter((col) => columnList.includes(col) && !extraKeys.includes(col))?.map((col) => (col?.includes('geom') && schema?.[col]?.type === 'Geom' ? `st_asgeojson(${col})::json as "${col}"` : `"${col}"`))?.join(',')
|
|
61
|
+
: fields.map((el) => (el?.name?.includes('geom') && pg.pgType[el?.dataTypeID] === 'geometry' ? `st_asgeojson(${el.name})::json as "${el.name}"` : `"${el?.name}"`)).join(',');
|
|
62
|
+
const where = [`"${pk}" = $1`, loadTable.query, accessQuery].filter((el) => el);
|
|
63
|
+
const geom = dbColumns.find((el) => el.name === 'geom' && pg.pgType[el.dataTypeID] === 'geometry') ? ',st_asgeojson(geom)::json as geom' : '';
|
|
64
|
+
const q = `select "${pk}" as id, ${cols || '*'} ${geom} from ${tableName} t where ${where.join(' and ') || 'true'} limit 1`;
|
|
65
|
+
|
|
66
|
+
if (query?.sql === '1') return q;
|
|
67
|
+
|
|
68
|
+
const data = await pg.query(q, [id]).then(el => el.rows[0]);
|
|
69
|
+
if (!data) return { message: 'not found', status: 404 };
|
|
70
|
+
|
|
71
|
+
if (extraKeys?.length) {
|
|
72
|
+
await Promise.all(extraKeys?.map(async (key) => {
|
|
73
|
+
const { colModel, table: extraTable, parent_id: parentId } = schema[key];
|
|
74
|
+
const q1 = `select ${parentId} as parent, ${colModel.map((col) => col.name || col.key).join(',')} from ${extraTable} a where ${parentId}=$1`;
|
|
75
|
+
// console.log(tableName, formName, q1);
|
|
76
|
+
const { rows: extraRows } = await pg.query(q1, [hookData?.id || tokenData?.id || params?.id]);
|
|
77
|
+
Object.assign(data, { [key]: extraRows });
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
if (user?.uid && actions?.includes?.('edit')) {
|
|
81
|
+
data.token = tokenData?.table ? params.table : setToken({
|
|
82
|
+
ids: [JSON.stringify({ id, table: tableName, form: loadTable.form })],
|
|
83
|
+
uid: user.uid,
|
|
84
|
+
array: 1,
|
|
85
|
+
})[0];
|
|
86
|
+
}
|
|
87
|
+
const res = await applyHook('afterTable', {
|
|
88
|
+
table: tableName, payload: [data], user,
|
|
89
|
+
});
|
|
90
|
+
return res || data || {};
|
|
91
|
+
}
|
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { lstat, readdir, readFile } from 'node:fs/promises';
|
|
3
|
-
import { createReadStream, existsSync } from 'node:fs';
|
|
4
|
-
import readline from 'node: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
|
-
// console.log(user);
|
|
21
|
-
const access = checkUserAccess({ user });
|
|
22
|
-
// log.info('Сервер запущен по адресу?'); // test!
|
|
23
|
-
|
|
24
|
-
if (access?.status !== 200) return access;
|
|
25
|
-
|
|
26
|
-
// absolute / relative path
|
|
27
|
-
const rootDir = getRootDir();
|
|
28
|
-
|
|
29
|
-
const filepath = path.join(rootDir, params['*'] || '');
|
|
30
|
-
|
|
31
|
-
if (!existsSync(filepath)) {
|
|
32
|
-
return { message: 'file not exists', status: 404 };
|
|
33
|
-
}
|
|
34
|
-
const stat = await lstat(filepath);
|
|
35
|
-
const isFile = stat.isFile();
|
|
36
|
-
|
|
37
|
-
if (query.download && isFile) {
|
|
38
|
-
return reply.download(filepath);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (query.full && isFile) {
|
|
42
|
-
if (stat.size > 20 * 1000 * 1000) {
|
|
43
|
-
return { message: 'file size > 20MB' };
|
|
44
|
-
}
|
|
45
|
-
const buffer = await readFile(filepath, { buffer: true });
|
|
46
|
-
return buffer;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (isFile) {
|
|
50
|
-
const ext = path.extname(filepath);
|
|
51
|
-
|
|
52
|
-
const lines = await new Promise((resolve) => {
|
|
53
|
-
const rl = readline.createInterface({
|
|
54
|
-
input: createReadStream(filepath, { start: stat.size > limit ? stat.size - limit : 0 }),
|
|
55
|
-
});
|
|
56
|
-
const lines1 = [];
|
|
57
|
-
rl.on('close', () => resolve(lines1));
|
|
58
|
-
rl.on('line', (line) => lines1.push(line));
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
if (ext === '.html') {
|
|
62
|
-
const buffer = await readFile(filepath, { buffer: true });
|
|
63
|
-
reply.headers({ 'Content-type': 'text/html; charset=UTF-8' });
|
|
64
|
-
return buffer;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
reply.headers({ 'Content-type': 'text/plain; charset=UTF-8' });
|
|
68
|
-
return stat.size > limit && lines.length > 1
|
|
69
|
-
? lines.reverse().slice(0, -1).join('\n')
|
|
70
|
-
: lines.reverse().join('\n');
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// dir
|
|
74
|
-
const files = await readdir(filepath);
|
|
75
|
-
|
|
76
|
-
if (query.dir) {
|
|
77
|
-
return files.filter((el) => !['backup', 'marker_icon', 'error', 'migration'].includes(el));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const lstatsArr = await Promise.all(files.map(async (file) => [file, await lstat(path.join(filepath, file))]));
|
|
81
|
-
const lstats = Object.fromEntries(lstatsArr);
|
|
82
|
-
|
|
83
|
-
const message = (params['*'] ? '<a href="/logger-file/">...</a><br>' : '')
|
|
84
|
-
+ files.map((file) => `<a href="${originalUrl}/${file}">${file}</a> (${lstats[file].size} bytes)`).join('</br>');
|
|
85
|
-
|
|
86
|
-
reply.headers({
|
|
87
|
-
'Content-Type': 'text/html; charset=UTF-8',
|
|
88
|
-
'Content-Security-Policy': "default-src 'none'",
|
|
89
|
-
'X-Content-Type-Options': 'nosniff',
|
|
90
|
-
});
|
|
91
|
-
return message;
|
|
92
|
-
}
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { lstat, readdir, readFile } from 'node:fs/promises';
|
|
3
|
+
import { createReadStream, existsSync } from 'node:fs';
|
|
4
|
+
import readline from 'node: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
|
+
// console.log(user);
|
|
21
|
+
const access = checkUserAccess({ user });
|
|
22
|
+
// log.info('Сервер запущен по адресу?'); // test!
|
|
23
|
+
|
|
24
|
+
if (access?.status !== 200) return access;
|
|
25
|
+
|
|
26
|
+
// absolute / relative path
|
|
27
|
+
const rootDir = getRootDir();
|
|
28
|
+
|
|
29
|
+
const filepath = path.join(rootDir, params['*'] || '');
|
|
30
|
+
|
|
31
|
+
if (!existsSync(filepath)) {
|
|
32
|
+
return { message: 'file not exists', status: 404 };
|
|
33
|
+
}
|
|
34
|
+
const stat = await lstat(filepath);
|
|
35
|
+
const isFile = stat.isFile();
|
|
36
|
+
|
|
37
|
+
if (query.download && isFile) {
|
|
38
|
+
return reply.download(filepath);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (query.full && isFile) {
|
|
42
|
+
if (stat.size > 20 * 1000 * 1000) {
|
|
43
|
+
return { message: 'file size > 20MB' };
|
|
44
|
+
}
|
|
45
|
+
const buffer = await readFile(filepath, { buffer: true });
|
|
46
|
+
return buffer;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (isFile) {
|
|
50
|
+
const ext = path.extname(filepath);
|
|
51
|
+
|
|
52
|
+
const lines = await new Promise((resolve) => {
|
|
53
|
+
const rl = readline.createInterface({
|
|
54
|
+
input: createReadStream(filepath, { start: stat.size > limit ? stat.size - limit : 0 }),
|
|
55
|
+
});
|
|
56
|
+
const lines1 = [];
|
|
57
|
+
rl.on('close', () => resolve(lines1));
|
|
58
|
+
rl.on('line', (line) => lines1.push(line));
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
if (ext === '.html') {
|
|
62
|
+
const buffer = await readFile(filepath, { buffer: true });
|
|
63
|
+
reply.headers({ 'Content-type': 'text/html; charset=UTF-8' });
|
|
64
|
+
return buffer;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
reply.headers({ 'Content-type': 'text/plain; charset=UTF-8' });
|
|
68
|
+
return stat.size > limit && lines.length > 1
|
|
69
|
+
? lines.reverse().slice(0, -1).join('\n')
|
|
70
|
+
: lines.reverse().join('\n');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// dir
|
|
74
|
+
const files = await readdir(filepath);
|
|
75
|
+
|
|
76
|
+
if (query.dir) {
|
|
77
|
+
return files.filter((el) => !['backup', 'marker_icon', 'error', 'migration'].includes(el));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const lstatsArr = await Promise.all(files.map(async (file) => [file, await lstat(path.join(filepath, file))]));
|
|
81
|
+
const lstats = Object.fromEntries(lstatsArr);
|
|
82
|
+
|
|
83
|
+
const message = (params['*'] ? '<a href="/logger-file/">...</a><br>' : '')
|
|
84
|
+
+ files.map((file) => `<a href="${originalUrl}/${file}">${file}</a> (${lstats[file].size} bytes)`).join('</br>');
|
|
85
|
+
|
|
86
|
+
reply.headers({
|
|
87
|
+
'Content-Type': 'text/html; charset=UTF-8',
|
|
88
|
+
'Content-Security-Policy': "default-src 'none'",
|
|
89
|
+
'X-Content-Type-Options': 'nosniff',
|
|
90
|
+
});
|
|
91
|
+
return message;
|
|
92
|
+
}
|
|
@@ -1,19 +1,19 @@
|
|
|
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({ user = {} }) {
|
|
10
|
-
// console.log(user);
|
|
11
|
-
if (user.user_type !== 'admin' && !config?.local) {
|
|
12
|
-
return { message: 'access restricted', status: 403 };
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/* if (!['admin', 'superadmin']?.includes(user.user_type) && count === '0') {
|
|
16
|
-
return { message: 'access restricted', status: 403 };
|
|
17
|
-
} */
|
|
18
|
-
return { message: 'access granted', status: 200 };
|
|
19
|
-
}
|
|
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({ user = {} }) {
|
|
10
|
+
// console.log(user);
|
|
11
|
+
if (user.user_type !== 'admin' && !config?.local) {
|
|
12
|
+
return { message: 'access restricted', status: 403 };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/* if (!['admin', 'superadmin']?.includes(user.user_type) && count === '0') {
|
|
16
|
+
return { message: 'access restricted', status: 403 };
|
|
17
|
+
} */
|
|
18
|
+
return { message: 'access granted', status: 200 };
|
|
19
|
+
}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
|
|
4
|
-
import config from '../../../../../config.js';
|
|
5
|
-
|
|
6
|
-
// import { existsSync } from 'fs';
|
|
7
|
-
let logDir = null;
|
|
8
|
-
export default function getRootDir() {
|
|
9
|
-
// absolute / relative path
|
|
10
|
-
if (logDir) return logDir;
|
|
11
|
-
const file = ['config.json', '/data/local/config.json'].find(el => (fs.existsSync(el) ? el : null));
|
|
12
|
-
const root = file === 'config.json' ? process.cwd() : '/data/local';
|
|
13
|
-
logDir = config.logDir || path.join(root, config.log?.dir || 'log');
|
|
14
|
-
console.log({ logDir });
|
|
15
|
-
return logDir;
|
|
16
|
-
|
|
17
|
-
// windows debug support
|
|
18
|
-
/* const customLogDir = process.cwd().includes(':') ? 'c:/data/local' : '/data/local';
|
|
19
|
-
// docker default path
|
|
20
|
-
if (existsSync(customLogDir)) {
|
|
21
|
-
return path.join(customLogDir, config.folder || '', 'log');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// non-docker default path
|
|
25
|
-
return path.join(config.root || '/data/local', config.folder || '', 'log'); */
|
|
26
|
-
}
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
import config from '../../../../../config.js';
|
|
5
|
+
|
|
6
|
+
// import { existsSync } from 'fs';
|
|
7
|
+
let logDir = null;
|
|
8
|
+
export default function getRootDir() {
|
|
9
|
+
// absolute / relative path
|
|
10
|
+
if (logDir) return logDir;
|
|
11
|
+
const file = ['config.json', '/data/local/config.json'].find(el => (fs.existsSync(el) ? el : null));
|
|
12
|
+
const root = file === 'config.json' ? process.cwd() : '/data/local';
|
|
13
|
+
logDir = config.logDir || path.join(root, config.log?.dir || 'log');
|
|
14
|
+
console.log({ logDir });
|
|
15
|
+
return logDir;
|
|
16
|
+
|
|
17
|
+
// windows debug support
|
|
18
|
+
/* const customLogDir = process.cwd().includes(':') ? 'c:/data/local' : '/data/local';
|
|
19
|
+
// docker default path
|
|
20
|
+
if (existsSync(customLogDir)) {
|
|
21
|
+
return path.join(customLogDir, config.folder || '', 'log');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// non-docker default path
|
|
25
|
+
return path.join(config.root || '/data/local', config.folder || '', 'log'); */
|
|
26
|
+
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import loggerFile from './controllers/logger.file.js';
|
|
2
|
-
|
|
3
|
-
// import loggerTest from './controllers/logger.test.api.js';
|
|
4
|
-
|
|
5
|
-
const loggerSchema = {
|
|
6
|
-
querystring: {
|
|
7
|
-
download: { type: 'string', pattern: '^(\\d+)$' },
|
|
8
|
-
full: { type: 'string', pattern: '^(\\d+)$' },
|
|
9
|
-
dir: { type: 'string', pattern: '^(\\d+)$' },
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
async function plugin(fastify) {
|
|
14
|
-
fastify.get('/logger-file/*', { config: { policy: ['site'] }, schema: loggerSchema }, loggerFile);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export default plugin;
|
|
1
|
+
import loggerFile from './controllers/logger.file.js';
|
|
2
|
+
|
|
3
|
+
// import loggerTest from './controllers/logger.test.api.js';
|
|
4
|
+
|
|
5
|
+
const loggerSchema = {
|
|
6
|
+
querystring: {
|
|
7
|
+
download: { type: 'string', pattern: '^(\\d+)$' },
|
|
8
|
+
full: { type: 'string', pattern: '^(\\d+)$' },
|
|
9
|
+
dir: { type: 'string', pattern: '^(\\d+)$' },
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
async function plugin(fastify) {
|
|
14
|
+
fastify.get('/logger-file/*', { config: { policy: ['site'] }, schema: loggerSchema }, loggerFile);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default plugin;
|
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import { dataInsert } 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
|
-
await pg.query('delete from crm.properties where object_id=$1', [id]); // rewrite?
|
|
38
|
-
const keyTypeMatch = extraProperties.filter((key) => body[key]).reduce((acc, curr) => Object.assign(acc, checkKeyType({ body, key: curr })), {});
|
|
39
|
-
const res = await Promise.all(Object.keys(keyTypeMatch).map(async (key) => {
|
|
40
|
-
const propertyType = keyTypeMatch[key];
|
|
41
|
-
const { rows = [] } = await dataInsert({
|
|
42
|
-
pg,
|
|
43
|
-
table,
|
|
44
|
-
data: {
|
|
45
|
-
property_type: propertyType,
|
|
46
|
-
property_key: key,
|
|
47
|
-
object_id: id,
|
|
48
|
-
[`property_${propertyType}`]: body[key],
|
|
49
|
-
},
|
|
50
|
-
uid,
|
|
51
|
-
});
|
|
52
|
-
return { id: rows[0]?.property_id, type: propertyType, value: body[key] };
|
|
53
|
-
}));
|
|
54
|
-
return { message: { rows: res }, status: 200 };
|
|
55
|
-
}
|
|
1
|
+
import { dataInsert } 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
|
+
await pg.query('delete from crm.properties where object_id=$1', [id]); // rewrite?
|
|
38
|
+
const keyTypeMatch = extraProperties.filter((key) => body[key]).reduce((acc, curr) => Object.assign(acc, checkKeyType({ body, key: curr })), {});
|
|
39
|
+
const res = await Promise.all(Object.keys(keyTypeMatch).map(async (key) => {
|
|
40
|
+
const propertyType = keyTypeMatch[key];
|
|
41
|
+
const { rows = [] } = await dataInsert({
|
|
42
|
+
pg,
|
|
43
|
+
table,
|
|
44
|
+
data: {
|
|
45
|
+
property_type: propertyType,
|
|
46
|
+
property_key: key,
|
|
47
|
+
object_id: id,
|
|
48
|
+
[`property_${propertyType}`]: body[key],
|
|
49
|
+
},
|
|
50
|
+
uid,
|
|
51
|
+
});
|
|
52
|
+
return { id: rows[0]?.property_id, type: propertyType, value: body[key] };
|
|
53
|
+
}));
|
|
54
|
+
return { message: { rows: res }, status: 200 };
|
|
55
|
+
}
|
|
@@ -1,17 +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
|
-
}
|
|
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
|
+
}
|