@opengis/fastify-table 1.2.13 → 1.2.14
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/index.js +79 -79
- package/package.json +1 -1
- package/server/migrations/0.sql +84 -84
- package/server/migrations/cls.sql +39 -39
- package/server/migrations/properties.sql +184 -184
- package/server/migrations/template.sql +34 -34
- package/server/migrations/users.sql +175 -175
- package/server/plugins/cron/funcs/addCron.js +130 -130
- package/server/plugins/cron/index.js +6 -6
- package/server/plugins/crud/funcs/dataDelete.js +24 -24
- package/server/plugins/crud/funcs/dataInsert.js +53 -53
- package/server/plugins/crud/funcs/dataUpdate.js +65 -65
- 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/funcs/utils/logChanges.js +118 -118
- 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/exec.migrations.js +37 -37
- package/server/plugins/migration/index.js +7 -7
- package/server/plugins/pg/pgClients.js +21 -21
- package/server/plugins/policy/index.js +12 -12
- 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/addTemplateDir.js +8 -8
- package/server/plugins/table/funcs/getFilterSQL/index.js +96 -96
- package/server/plugins/table/funcs/getFilterSQL/util/formatValue.js +179 -179
- package/server/plugins/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
- package/server/plugins/table/funcs/getFilterSQL/util/getFilterQuery.js +66 -66
- 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/getSelectVal.js +50 -50
- package/server/plugins/table/funcs/metaFormat/index.js +45 -45
- 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/deleteCrud.js +39 -39
- 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/filter.js +67 -67
- 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 +166 -166
- 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
- package/utils.js +129 -129
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
-
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
-
import getRedis from '../../redis/funcs/getRedis.js';
|
|
4
|
-
|
|
5
|
-
import logChanges from './utils/logChanges.js';
|
|
6
|
-
|
|
7
|
-
const rclient = getRedis();
|
|
8
|
-
|
|
9
|
-
export default async function dataDelete({
|
|
10
|
-
table, tokenData, referer, id, pg: pg1, uid,
|
|
11
|
-
}) {
|
|
12
|
-
const pg = pg1 || getPG({ name: 'client' });
|
|
13
|
-
const { pk } = await getMeta({ pg, table });
|
|
14
|
-
const table1 = table.replace(/"/g, '');
|
|
15
|
-
if (!pg.tlist?.includes(table1)) return 'table not exist';
|
|
16
|
-
const delQuery = `delete from ${table} WHERE ${pk} = $1 returning *`;
|
|
17
|
-
|
|
18
|
-
const res = await pg.query(delQuery, [id]).then(el => el.rows?.[0] || {});
|
|
19
|
-
await logChanges({
|
|
20
|
-
pg, table, tokenData, referer, id, uid, type: 'DELETE',
|
|
21
|
-
});
|
|
22
|
-
rclient.incr(`pg:${table}:crud`);
|
|
23
|
-
return res;
|
|
24
|
-
}
|
|
1
|
+
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
+
import getRedis from '../../redis/funcs/getRedis.js';
|
|
4
|
+
|
|
5
|
+
import logChanges from './utils/logChanges.js';
|
|
6
|
+
|
|
7
|
+
const rclient = getRedis();
|
|
8
|
+
|
|
9
|
+
export default async function dataDelete({
|
|
10
|
+
table, tokenData, referer, id, pg: pg1, uid,
|
|
11
|
+
}) {
|
|
12
|
+
const pg = pg1 || getPG({ name: 'client' });
|
|
13
|
+
const { pk } = await getMeta({ pg, table });
|
|
14
|
+
const table1 = table.replace(/"/g, '');
|
|
15
|
+
if (!pg.tlist?.includes(table1)) return 'table not exist';
|
|
16
|
+
const delQuery = `delete from ${table} WHERE ${pk} = $1 returning *`;
|
|
17
|
+
|
|
18
|
+
const res = await pg.query(delQuery, [id]).then(el => el.rows?.[0] || {});
|
|
19
|
+
await logChanges({
|
|
20
|
+
pg, table, tokenData, referer, id, uid, type: 'DELETE',
|
|
21
|
+
});
|
|
22
|
+
rclient.incr(`pg:${table}:crud`);
|
|
23
|
+
return res;
|
|
24
|
+
}
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
-
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
-
import getRedis from '../../redis/funcs/getRedis.js';
|
|
4
|
-
|
|
5
|
-
import logChanges from './utils/logChanges.js';
|
|
6
|
-
|
|
7
|
-
const rclient = getRedis();
|
|
8
|
-
|
|
9
|
-
export default async function dataInsert({
|
|
10
|
-
id, table, tokenData, referer, data, pg: pg1, uid,
|
|
11
|
-
}) {
|
|
12
|
-
const pg = pg1 || getPG({ name: 'client' });
|
|
13
|
-
if (!data) return null;
|
|
14
|
-
const { columns } = await getMeta({ pg, table });
|
|
15
|
-
if (!columns) return null;
|
|
16
|
-
|
|
17
|
-
const names = columns.map((el) => el.name);
|
|
18
|
-
|
|
19
|
-
Object.assign(data, {
|
|
20
|
-
...(id && pg.pk?.[table] ? { [pg.pk?.[table]]: id } : {}),
|
|
21
|
-
...(table !== 'admin.users' ? { uid } : {}),
|
|
22
|
-
// editor_id: uid,
|
|
23
|
-
});
|
|
24
|
-
const systemColumns = ['cdate', 'editor_date'].filter((el) => names.includes(el)).map((el) => [el, 'now()']);
|
|
25
|
-
|
|
26
|
-
const filterData = Object.keys(data)
|
|
27
|
-
.filter((el) => !['cdate', 'editor_date'].includes(el) && (typeof data[el] === 'boolean' ? true : data[el]) && names.includes(el)).map((el) => [el, data[el]]);
|
|
28
|
-
|
|
29
|
-
const insertQuery = `insert into ${table}
|
|
30
|
-
|
|
31
|
-
( ${filterData?.map((key) => `"${key[0]}"`).concat(systemColumns.map((el) => el[0])).join(',')})
|
|
32
|
-
|
|
33
|
-
values (${filterData?.map((key, i) => (key[0] === 'geom' ? `st_setsrid(st_geomfromgeojson($${i + 1}::json),4326)` : `$${i + 1}`)).concat(systemColumns.map((el) => el[1])).join(',')})
|
|
34
|
-
|
|
35
|
-
returning *`;
|
|
36
|
-
|
|
37
|
-
const res = await pg.query(insertQuery, [...filterData.map((el) => (typeof el[1] === 'object' && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]))]) || {};
|
|
38
|
-
|
|
39
|
-
const table1 = pg.pk[table] ? table : table.replace(/"/g, '');
|
|
40
|
-
await logChanges({
|
|
41
|
-
pg,
|
|
42
|
-
table,
|
|
43
|
-
tokenData,
|
|
44
|
-
referer,
|
|
45
|
-
data,
|
|
46
|
-
id: res.rows?.[0]?.[pg.pk[table1]],
|
|
47
|
-
uid,
|
|
48
|
-
type: 'INSERT',
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
rclient.incr(`pg:${table}:crud`);
|
|
52
|
-
return res;
|
|
53
|
-
}
|
|
1
|
+
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
+
import getRedis from '../../redis/funcs/getRedis.js';
|
|
4
|
+
|
|
5
|
+
import logChanges from './utils/logChanges.js';
|
|
6
|
+
|
|
7
|
+
const rclient = getRedis();
|
|
8
|
+
|
|
9
|
+
export default async function dataInsert({
|
|
10
|
+
id, table, tokenData, referer, data, pg: pg1, uid,
|
|
11
|
+
}) {
|
|
12
|
+
const pg = pg1 || getPG({ name: 'client' });
|
|
13
|
+
if (!data) return null;
|
|
14
|
+
const { columns } = await getMeta({ pg, table });
|
|
15
|
+
if (!columns) return null;
|
|
16
|
+
|
|
17
|
+
const names = columns.map((el) => el.name);
|
|
18
|
+
|
|
19
|
+
Object.assign(data, {
|
|
20
|
+
...(id && pg.pk?.[table] ? { [pg.pk?.[table]]: id } : {}),
|
|
21
|
+
...(table !== 'admin.users' ? { uid } : {}),
|
|
22
|
+
// editor_id: uid,
|
|
23
|
+
});
|
|
24
|
+
const systemColumns = ['cdate', 'editor_date'].filter((el) => names.includes(el)).map((el) => [el, 'now()']);
|
|
25
|
+
|
|
26
|
+
const filterData = Object.keys(data)
|
|
27
|
+
.filter((el) => !['cdate', 'editor_date'].includes(el) && (typeof data[el] === 'boolean' ? true : data[el]) && names.includes(el)).map((el) => [el, data[el]]);
|
|
28
|
+
|
|
29
|
+
const insertQuery = `insert into ${table}
|
|
30
|
+
|
|
31
|
+
( ${filterData?.map((key) => `"${key[0]}"`).concat(systemColumns.map((el) => el[0])).join(',')})
|
|
32
|
+
|
|
33
|
+
values (${filterData?.map((key, i) => (key[0] === 'geom' ? `st_setsrid(st_geomfromgeojson($${i + 1}::json),4326)` : `$${i + 1}`)).concat(systemColumns.map((el) => el[1])).join(',')})
|
|
34
|
+
|
|
35
|
+
returning *`;
|
|
36
|
+
|
|
37
|
+
const res = await pg.query(insertQuery, [...filterData.map((el) => (typeof el[1] === 'object' && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]))]) || {};
|
|
38
|
+
|
|
39
|
+
const table1 = pg.pk[table] ? table : table.replace(/"/g, '');
|
|
40
|
+
await logChanges({
|
|
41
|
+
pg,
|
|
42
|
+
table,
|
|
43
|
+
tokenData,
|
|
44
|
+
referer,
|
|
45
|
+
data,
|
|
46
|
+
id: res.rows?.[0]?.[pg.pk[table1]],
|
|
47
|
+
uid,
|
|
48
|
+
type: 'INSERT',
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
rclient.incr(`pg:${table}:crud`);
|
|
52
|
+
return res;
|
|
53
|
+
}
|
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
-
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
-
import getRedis from '../../redis/funcs/getRedis.js';
|
|
4
|
-
|
|
5
|
-
import logChanges from './utils/logChanges.js';
|
|
6
|
-
|
|
7
|
-
const rclient = getRedis();
|
|
8
|
-
const srids = {};
|
|
9
|
-
|
|
10
|
-
function assignValue(key, i, srid = 4326, columnType = 'text') {
|
|
11
|
-
if (key === 'geom' && columnType === 'geometry') {
|
|
12
|
-
return `"${key}"=st_setsrid(st_geomfromgeojson($${i + 2}::json),4326)`;
|
|
13
|
-
}
|
|
14
|
-
if (key?.includes('geom') && columnType === 'geometry') {
|
|
15
|
-
return `"${key}"=st_setsrid(st_geomfromgeojson($${i + 2}::json),${srid})`;
|
|
16
|
-
}
|
|
17
|
-
return `"${key}"=$${i + 2}`;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export default async function dataUpdate({
|
|
21
|
-
table, tokenData, referer, id, data, pg: pg1, uid,
|
|
22
|
-
}) {
|
|
23
|
-
if (!data || !table || !id) return null;
|
|
24
|
-
|
|
25
|
-
const pg = pg1 || getPG({ name: 'client' });
|
|
26
|
-
const { columns, pk } = await getMeta({ pg, table });
|
|
27
|
-
|
|
28
|
-
const names = columns?.map((el) => el.name);
|
|
29
|
-
|
|
30
|
-
const filterData = Object.keys(data)
|
|
31
|
-
.filter((el) => (/* typeof data[el] === 'boolean' ? true : data[el] && */ names?.includes(el) && !['editor_date', 'editor_id'].includes(el)));
|
|
32
|
-
|
|
33
|
-
const systemColumns = [['editor_date', 'now()'], uid ? ['editor_id', `'${uid.replace(/'/g, "''")}'`] : []].filter((el) => names.includes(el[0])).map((el) => `${el[0]} = ${el[1]}`).join(',');
|
|
34
|
-
|
|
35
|
-
const filterValue = filterData.map((el) => {
|
|
36
|
-
const { dataTypeID = 25 } = columns?.find?.((col) => col?.name === el) || {};
|
|
37
|
-
if (pg.pgType[dataTypeID]?.endsWith('[]') && ['string', 'number'].includes(typeof data[el])) {
|
|
38
|
-
Object.assign(data, { [el]: data[el].split(',') });
|
|
39
|
-
}
|
|
40
|
-
return [el, data[el]];
|
|
41
|
-
}).map((el) => (typeof el[1] === 'object' && el[1] && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]));
|
|
42
|
-
|
|
43
|
-
// update geometry with srid
|
|
44
|
-
if (!srids[table]) {
|
|
45
|
-
const { srids1 } = await pg.query(`select json_object_agg(_table,rel) as srids1 from (
|
|
46
|
-
select f_table_schema||'.'||f_table_name as _table,
|
|
47
|
-
json_object_agg(f_geometry_column, case when srid = 0 then 4326 else srid end) as rel
|
|
48
|
-
from public.geometry_columns group by f_table_schema||'.'||f_table_name
|
|
49
|
-
)q`).then((res1) => res1.rows?.[0] || {});
|
|
50
|
-
Object.assign(srids, srids1);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const updateQuery = `UPDATE ${table} SET ${systemColumns ? `${systemColumns}${filterData?.length ? ',' : ''}` : ''}
|
|
54
|
-
${filterData?.map((key, i) => assignValue(key, i, srids[table]?.[key] || 4326, pg.pgType?.[columns.find(col => col.name === key)?.dataTypeID || '']))?.join(',')}
|
|
55
|
-
WHERE ${pk} = $1 returning *`;
|
|
56
|
-
// console.log(updateQuery, filterValue);
|
|
57
|
-
const res = await pg.query(updateQuery, [id, ...filterValue]).then(el => el?.rows?.[0]) || {};
|
|
58
|
-
|
|
59
|
-
await logChanges({
|
|
60
|
-
pg, table, tokenData, referer, data, id, uid, type: 'UPDATE',
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
rclient.incr(`pg:${table}:crud`);
|
|
64
|
-
return res;
|
|
65
|
-
}
|
|
1
|
+
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
+
import getRedis from '../../redis/funcs/getRedis.js';
|
|
4
|
+
|
|
5
|
+
import logChanges from './utils/logChanges.js';
|
|
6
|
+
|
|
7
|
+
const rclient = getRedis();
|
|
8
|
+
const srids = {};
|
|
9
|
+
|
|
10
|
+
function assignValue(key, i, srid = 4326, columnType = 'text') {
|
|
11
|
+
if (key === 'geom' && columnType === 'geometry') {
|
|
12
|
+
return `"${key}"=st_setsrid(st_geomfromgeojson($${i + 2}::json),4326)`;
|
|
13
|
+
}
|
|
14
|
+
if (key?.includes('geom') && columnType === 'geometry') {
|
|
15
|
+
return `"${key}"=st_setsrid(st_geomfromgeojson($${i + 2}::json),${srid})`;
|
|
16
|
+
}
|
|
17
|
+
return `"${key}"=$${i + 2}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default async function dataUpdate({
|
|
21
|
+
table, tokenData, referer, id, data, pg: pg1, uid,
|
|
22
|
+
}) {
|
|
23
|
+
if (!data || !table || !id) return null;
|
|
24
|
+
|
|
25
|
+
const pg = pg1 || getPG({ name: 'client' });
|
|
26
|
+
const { columns, pk } = await getMeta({ pg, table });
|
|
27
|
+
|
|
28
|
+
const names = columns?.map((el) => el.name);
|
|
29
|
+
|
|
30
|
+
const filterData = Object.keys(data)
|
|
31
|
+
.filter((el) => (/* typeof data[el] === 'boolean' ? true : data[el] && */ names?.includes(el) && !['editor_date', 'editor_id'].includes(el)));
|
|
32
|
+
|
|
33
|
+
const systemColumns = [['editor_date', 'now()'], uid ? ['editor_id', `'${uid.replace(/'/g, "''")}'`] : []].filter((el) => names.includes(el[0])).map((el) => `${el[0]} = ${el[1]}`).join(',');
|
|
34
|
+
|
|
35
|
+
const filterValue = filterData.map((el) => {
|
|
36
|
+
const { dataTypeID = 25 } = columns?.find?.((col) => col?.name === el) || {};
|
|
37
|
+
if (pg.pgType[dataTypeID]?.endsWith('[]') && ['string', 'number'].includes(typeof data[el])) {
|
|
38
|
+
Object.assign(data, { [el]: data[el].split(',') });
|
|
39
|
+
}
|
|
40
|
+
return [el, data[el]];
|
|
41
|
+
}).map((el) => (typeof el[1] === 'object' && el[1] && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]));
|
|
42
|
+
|
|
43
|
+
// update geometry with srid
|
|
44
|
+
if (!srids[table]) {
|
|
45
|
+
const { srids1 } = await pg.query(`select json_object_agg(_table,rel) as srids1 from (
|
|
46
|
+
select f_table_schema||'.'||f_table_name as _table,
|
|
47
|
+
json_object_agg(f_geometry_column, case when srid = 0 then 4326 else srid end) as rel
|
|
48
|
+
from public.geometry_columns group by f_table_schema||'.'||f_table_name
|
|
49
|
+
)q`).then((res1) => res1.rows?.[0] || {});
|
|
50
|
+
Object.assign(srids, srids1);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const updateQuery = `UPDATE ${table} SET ${systemColumns ? `${systemColumns}${filterData?.length ? ',' : ''}` : ''}
|
|
54
|
+
${filterData?.map((key, i) => assignValue(key, i, srids[table]?.[key] || 4326, pg.pgType?.[columns.find(col => col.name === key)?.dataTypeID || '']))?.join(',')}
|
|
55
|
+
WHERE ${pk} = $1 returning *`;
|
|
56
|
+
// console.log(updateQuery, filterValue);
|
|
57
|
+
const res = await pg.query(updateQuery, [id, ...filterValue]).then(el => el?.rows?.[0]) || {};
|
|
58
|
+
|
|
59
|
+
await logChanges({
|
|
60
|
+
pg, table, tokenData, referer, data, id, uid, type: 'UPDATE',
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
rclient.incr(`pg:${table}:crud`);
|
|
64
|
+
return res;
|
|
65
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import getRedis from '../../redis/funcs/getRedis.js';
|
|
2
|
-
|
|
3
|
-
// import { getRedis } from '../../../../utils.js';
|
|
4
|
-
|
|
5
|
-
export default async function getOpt(token, uid = 0) {
|
|
6
|
-
const rclient = getRedis({ db: 0 });
|
|
7
|
-
|
|
8
|
-
const key = `opt:${uid}:${token}`;
|
|
9
|
-
// console.log(key);
|
|
10
|
-
const data = await rclient.get(key);
|
|
11
|
-
if (!data) return null;
|
|
12
|
-
return JSON.parse(data);
|
|
13
|
-
}
|
|
1
|
+
import getRedis from '../../redis/funcs/getRedis.js';
|
|
2
|
+
|
|
3
|
+
// import { getRedis } from '../../../../utils.js';
|
|
4
|
+
|
|
5
|
+
export default async function getOpt(token, uid = 0) {
|
|
6
|
+
const rclient = getRedis({ db: 0 });
|
|
7
|
+
|
|
8
|
+
const key = `opt:${uid}:${token}`;
|
|
9
|
+
// console.log(key);
|
|
10
|
+
const data = await rclient.get(key);
|
|
11
|
+
if (!data) return null;
|
|
12
|
+
return JSON.parse(data);
|
|
13
|
+
}
|
|
@@ -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
|
+
}
|