@opengis/admin 0.1.26 → 0.1.27

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.
Files changed (101) hide show
  1. package/README.md +29 -29
  2. package/config.js +4 -4
  3. package/dist/{IconSearch-Dzh7isDo.js → IconSearch-CTjruqP_.js} +1 -1
  4. package/dist/{add-page-Bqo89ZhV.js → add-page-_f-u6pKm.js} +1 -1
  5. package/dist/{admin-interface-_aBJ2Q5B.js → admin-interface-BEGo6Nou.js} +288 -285
  6. package/dist/{admin-view-oqNsQ8Yh.js → admin-view-KQUUMduA.js} +3 -3
  7. package/dist/admin.js +1 -1
  8. package/dist/admin.umd.cjs +53 -53
  9. package/dist/{card-page-DtL44Dyl.js → card-page-aj2AtGvv.js} +3 -3
  10. package/dist/{card-view-CJXpyOcM.js → card-view-jKx2Oevk.js} +1 -1
  11. package/dist/{edit-page-Rw4844su.js → edit-page-BuolDXZx.js} +1 -1
  12. package/dist/{import-file-De3lGFop.js → import-file-BB530Z8E.js} +8250 -8615
  13. package/dist/style.css +1 -1
  14. package/module/settings/card/admin.roles.table/access.hbs +27 -27
  15. package/module/settings/card/admin.roles.table/general_info.hbs +16 -16
  16. package/module/settings/card/admin.roles.table/index.yml +12 -12
  17. package/module/settings/card/admin.roles.table/users.hbs +27 -27
  18. package/module/settings/card/admin.routes.table/general_info.hbs +40 -40
  19. package/module/settings/card/admin.routes.table/index.yml +8 -8
  20. package/module/settings/card/admin.routes.table/users.hbs +33 -33
  21. package/module/settings/card/admin.users.table/general_info.hbs +25 -25
  22. package/module/settings/card/admin.users.table/index.yml +12 -12
  23. package/module/settings/card/admin.users.table/logs.hbs +30 -30
  24. package/module/settings/card/admin.users.table/user_roles.hbs +24 -24
  25. package/module/settings/cls/core.actions.json +13 -13
  26. package/module/settings/cls/core.scope.json +13 -13
  27. package/module/settings/cls/properties.site_status.json +13 -13
  28. package/module/settings/cls/properties.widget_status.json +13 -13
  29. package/module/settings/cls/users.user_type.json +13 -13
  30. package/module/settings/form/admin.access.form.json +36 -36
  31. package/module/settings/form/admin.properties.form.json +15 -15
  32. package/module/settings/form/admin.roles.form.json +19 -19
  33. package/module/settings/form/admin.routes.form.json +25 -25
  34. package/module/settings/form/admin.user_properties.form.json +15 -15
  35. package/module/settings/form/admin.user_roles.form.json +21 -21
  36. package/module/settings/form/admin.users.form.json +164 -164
  37. package/module/settings/form/user.user_roles.form.json +13 -13
  38. package/module/settings/interface/admin.properties.json +4 -4
  39. package/module/settings/interface/admin.roles.json +4 -4
  40. package/module/settings/interface/admin.routes.json +4 -4
  41. package/module/settings/interface/admin.users.json +4 -4
  42. package/module/settings/menu.json +39 -39
  43. package/module/settings/select/core.roles.json +2 -2
  44. package/module/settings/select/core.user_uid.sql +1 -1
  45. package/module/settings/table/admin.access.table.json +77 -77
  46. package/module/settings/table/admin.properties.table.json +33 -33
  47. package/module/settings/table/admin.roles.table.json +58 -58
  48. package/module/settings/table/admin.routes.table.json +55 -55
  49. package/module/settings/table/admin.user_properties.table.json +28 -28
  50. package/module/settings/table/admin.user_roles.table.json +66 -66
  51. package/module/settings/table/admin.users.table.json +125 -125
  52. package/package.json +66 -66
  53. package/plugin.js +25 -25
  54. package/server/helpers/controllers/badge.js +11 -11
  55. package/server/helpers/controllers/hb.js +2 -2
  56. package/server/helpers/controllers/map.js +2 -2
  57. package/server/helpers/controllers/mls.js +2 -2
  58. package/server/helpers/controllers/vue.js +2 -2
  59. package/server/helpers/index.mjs +13 -13
  60. package/server/plugins/docs.js +28 -28
  61. package/server/plugins/hook.js +161 -161
  62. package/server/plugins/vite.js +69 -69
  63. package/server/routes/data/controllers/cardData.js +31 -31
  64. package/server/routes/data/controllers/funcs/getFilterSQL/index.js +85 -82
  65. package/server/routes/data/controllers/funcs/getFilterSQL/util/formatValue.js +142 -142
  66. package/server/routes/data/controllers/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
  67. package/server/routes/data/controllers/funcs/getFilterSQL/util/getFilterQuery.js +67 -67
  68. package/server/routes/data/controllers/funcs/getFilterSQL/util/getOptimizedQuery.js +12 -12
  69. package/server/routes/data/controllers/funcs/getFilterSQL/util/getTableSql.js +34 -34
  70. package/server/routes/data/controllers/tableData.js +121 -121
  71. package/server/routes/data/controllers/tableDataId.js +27 -27
  72. package/server/routes/data/controllers/tableFilter.js +54 -54
  73. package/server/routes/data/controllers/utils/assignTokens.js +30 -30
  74. package/server/routes/data/controllers/utils/getColumns.js +21 -21
  75. package/server/routes/data/index.mjs +10 -10
  76. package/server/routes/menu/controllers/getMenu.js +33 -33
  77. package/server/routes/menu/index.mjs +5 -5
  78. package/server/routes/properties/controllers/admin.properties.get.js +29 -29
  79. package/server/routes/properties/controllers/user.properties.get.js +34 -34
  80. package/server/routes/properties/controllers/user.properties.post.js +30 -30
  81. package/server/routes/properties/funcs/getSettings.js +56 -56
  82. package/server/routes/properties/funcs/setSettings.js +44 -44
  83. package/server/routes/properties/funcs/utils/dataInsert.js +26 -26
  84. package/server/routes/properties/index.mjs +26 -26
  85. package/server/routes/root.mjs +3 -3
  86. package/server/routes/templates/controllers/getTemplate.js +14 -14
  87. package/server/routes/templates/index.mjs +14 -14
  88. package/server/templates/cls/itree.recrzone_category.json +73 -73
  89. package/server/templates/cls/test.json +9 -9
  90. package/server/templates/form/admin.user_cls.data.form.json +49 -49
  91. package/server/templates/form/admin.user_group_rel.form.json +21 -21
  92. package/server/templates/form/cp_building.form.json +32 -32
  93. package/server/templates/form/form-user-pass.json +10 -10
  94. package/server/templates/form/form-user_group.json +39 -39
  95. package/server/templates/form/form-users.json +156 -156
  96. package/server/templates/form/user_group_access.form.json +22 -22
  97. package/server/templates/select/account_id.json +2 -2
  98. package/server/templates/table/gis.dataset.table.json +43 -43
  99. package/server/templates/table/management.user_group.table.json +112 -112
  100. package/server/templates/table/management.users.table.json +126 -126
  101. package/utils.js +8 -8
@@ -1,161 +1,161 @@
1
- import fp from 'fastify-plugin';
2
- import fs from 'node:fs';
3
- import path from 'node:path';
4
-
5
- import { userTemplateDir, getTemplate, pgClients } from '@opengis/fastify-table/utils.js';
6
-
7
- import getMenu from '../routes/menu/controllers/getMenu.js';
8
-
9
- import config from '../../config.js';
10
-
11
- // to export the decorators to the outer scope
12
-
13
- async function plugin(fastify) {
14
- fastify.decorate('config', config);
15
-
16
- fastify.addHook('onListen', async () => {
17
- const { client } = pgClients;
18
- const json = await getMenu();
19
- // insert interface list to db (user access management)
20
- if (client?.pk?.['admin.routes'] && json?.length) {
21
- const menuList = json.filter((el) => el?.menu?.length && el?.ua || el?.en || el?.name);
22
- const interfaces = menuList.reduce((acc, curr) => { curr.menu.forEach((el) => acc.push(el.path)); return acc; }, []);
23
- await client.query('update admin.routes set enabled=false where not array[route_id] <@ $1::text[]', [interfaces]);
24
-
25
- const q = `insert into admin.menu(name, ord) values${
26
- menuList.map((el, i) => `('${(el?.ua || el?.en || el?.name).replace(/'/g, '’')}', ${i}) `).join(',')
27
- } on conflict (name) do update set ord=excluded.ord, enabled=true returning name, menu_id`;
28
- const { rows = [] } = await client.query(q);
29
- await client.query('update admin.menu set enabled=false where not array[menu_id] <@ $1::text[]', [rows.map((el) => el.menu_id)]);
30
-
31
- const menus = rows.reduce((acc, curr) => Object.assign(acc, { [curr.menu_id]: menuList.find((item) => (item?.ua || item?.en || item?.name) === curr.name) }), {});
32
- const values = Object.entries(menus).reduce((acc, curr) => { curr[1]?.menu?.forEach((el) => acc.push({ ...el, menuId: curr[0] })); return acc; }, []);
33
-
34
- await Promise.all(values.filter((el) => el?.table).map(async (el) => Object.assign(el, { table: (await getTemplate('table', el.table))?.table || el.table })));
35
-
36
- const q1 = `insert into admin.routes(route_id, alias, title, menu_id, table_name) values ${values.map((el) => `('${el.path}', '${el.path}', '${el.title}', '${el.menuId}', '${el.table}')`).join(',')}
37
- on conflict (route_id) do update set menu_id=excluded.menu_id, title=excluded.title, enabled=true,
38
- table_name=excluded.table_name returning route_id, table_name`;
39
- try {
40
- const { rowCount } = await client.query(q1);
41
- console.log('interface insert ok', values, rowCount);
42
- } catch (err) {
43
- console.log('interface insert error', values, q1, err);
44
- }
45
- }
46
- });
47
-
48
- fastify.addHook('onListen', async () => {
49
- const { client: pg } = pgClients;
50
- const clsQuery = [];
51
- if (!pg.pk?.['admin.cls']) return;
52
-
53
- const cls = ['cls', 'select']
54
- .filter((el) => fs.existsSync(`${userTemplateDir[0]}/${el}`))
55
- .map((el) => fs.readdirSync(`${userTemplateDir[0]}/${el}`).filter((item) => el === 'cls' ? true : path.extname(item) === '.sql'))
56
- .reduce((acc, curr) => { curr?.forEach((el) => acc.push(el)); return acc; }, []);
57
-
58
- try {
59
- await Promise.all(cls.map(async (el) => {
60
- const { ext, name } = path.parse(el);
61
- const type = { '.json': 'cls', '.sql': 'select' }[ext];
62
- const loadTemplate = await getTemplate(type, name);
63
- console.log(name, type);
64
- if (type === 'select') {
65
- clsQuery.push(`insert into admin.cls(name,type,data) values('${name}','sql','${(loadTemplate?.sql || loadTemplate)?.replace(/'/g, "''")}')`);
66
- } else if (type === 'cls') {
67
- clsQuery.push(`insert into admin.cls(name,type) values('${name}','json');
68
- insert into admin.cls(code,name,parent,icon)
69
- select value->>'id',value->>'text','${name}',value->>'icon'
70
- from json_array_elements('${JSON.stringify(loadTemplate).replace(/'/g, "''")}'::json)`);
71
- }
72
- }));
73
-
74
- await pg.query('truncate admin.cls');
75
- if (clsQuery.filter((el) => el).length) {
76
- await pg.query(clsQuery.filter((el) => el).join(';'));
77
- console.log('cls insert ok', clsQuery?.length);
78
- }
79
- } catch (err) {
80
- console.error('cls insert error', err.toString());
81
- }
82
- });
83
-
84
- // pre Request
85
- fastify.addHook('onRequest', async (req) => {
86
- req.funcs = fastify;
87
- const { user } = req.session?.passport || {};
88
- req.user = user;
89
- });
90
-
91
- // preSerialization
92
- fastify.addHook('preSerialization', async (req, reply, payload) => {
93
- if (req.url.includes('/suggest/') && !req.query.json) {
94
- return payload?.data;
95
- }
96
- if (payload?.redirect) {
97
- return reply.redirect(payload.redirect);
98
- }
99
- if (reply.sent) {
100
- return null;
101
- }
102
-
103
- if (['200', '400', '500', '403', '404'].includes(payload?.status)) {
104
- reply.status(payload.status);
105
- }
106
- /* if (payload.headers) {
107
- reply.headers(payload.headers);
108
- } */
109
- if (payload?.buffer) {
110
- return payload.buffer;
111
- }
112
- if (payload?.file) {
113
- // const buffer = await readFile(payload.file);
114
- // return reply.send(buffer);
115
- const stream = fs.createReadStream(payload.file);
116
- return stream;
117
- // return reply.send(stream);
118
- }
119
-
120
- if (payload?.message) {
121
- return payload.message;
122
- }
123
- return payload;
124
- });
125
-
126
- // preValidation
127
- fastify.addHook('preValidation', async (req) => {
128
- const parseRawBody = ['POST', 'PUT'].includes(req.method) && req.body && typeof req.body === 'string'
129
- && req.body.trim(/\r\n/g).startsWith('{')
130
- && req.body.trim(/\r\n/g).endsWith('}');
131
- if (parseRawBody) {
132
- try {
133
- req.body = JSON.parse(req.body || '{}');
134
- }
135
- catch (err) {
136
- // throw new Error('invalid body');
137
- // return { error: 'invalid body', status: 400 };
138
- }
139
- }
140
- });
141
-
142
- // allow upload file
143
- const kIsMultipart = Symbol.for('[FastifyMultipart.isMultipart]');
144
- fastify.addContentTypeParser('multipart', (request, _, done) => {
145
- request[kIsMultipart] = true;
146
- done(null);
147
- });
148
-
149
- // parse Body
150
- function contentParser(req, body, done) {
151
- const parseBody = decodeURIComponent(body.toString()).split('&').reduce((acc, el) => {
152
- const [key, val] = el.split('=');
153
- return { ...acc, [key]: val };
154
- }, {});
155
- done(null, parseBody);
156
- }
157
-
158
- fastify.addContentTypeParser('application/x-www-form-urlencoded', { parseAs: 'buffer' }, contentParser);
159
- }
160
-
161
- export default fp(plugin);
1
+ import fp from 'fastify-plugin';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+
5
+ import { userTemplateDir, getTemplate, pgClients } from '@opengis/fastify-table/utils.js';
6
+
7
+ import getMenu from '../routes/menu/controllers/getMenu.js';
8
+
9
+ import config from '../../config.js';
10
+
11
+ // to export the decorators to the outer scope
12
+
13
+ async function plugin(fastify) {
14
+ fastify.decorate('config', config);
15
+
16
+ fastify.addHook('onListen', async () => {
17
+ const { client } = pgClients;
18
+ const json = await getMenu();
19
+ // insert interface list to db (user access management)
20
+ if (client?.pk?.['admin.routes'] && json?.length) {
21
+ const menuList = json.filter((el) => el?.menu?.length && el?.ua || el?.en || el?.name);
22
+ const interfaces = menuList.reduce((acc, curr) => { curr.menu.forEach((el) => acc.push(el.path)); return acc; }, []);
23
+ await client.query('update admin.routes set enabled=false where not array[route_id] <@ $1::text[]', [interfaces]);
24
+
25
+ const q = `insert into admin.menu(name, ord) values${
26
+ menuList.map((el, i) => `('${(el?.ua || el?.en || el?.name).replace(/'/g, '’')}', ${i}) `).join(',')
27
+ } on conflict (name) do update set ord=excluded.ord, enabled=true returning name, menu_id`;
28
+ const { rows = [] } = await client.query(q);
29
+ await client.query('update admin.menu set enabled=false where not array[menu_id] <@ $1::text[]', [rows.map((el) => el.menu_id)]);
30
+
31
+ const menus = rows.reduce((acc, curr) => Object.assign(acc, { [curr.menu_id]: menuList.find((item) => (item?.ua || item?.en || item?.name) === curr.name) }), {});
32
+ const values = Object.entries(menus).reduce((acc, curr) => { curr[1]?.menu?.forEach((el) => acc.push({ ...el, menuId: curr[0] })); return acc; }, []);
33
+
34
+ await Promise.all(values.filter((el) => el?.table).map(async (el) => Object.assign(el, { table: (await getTemplate('table', el.table))?.table || el.table })));
35
+
36
+ const q1 = `insert into admin.routes(route_id, alias, title, menu_id, table_name) values ${values.map((el) => `('${el.path}', '${el.path}', '${el.title}', '${el.menuId}', '${el.table}')`).join(',')}
37
+ on conflict (route_id) do update set menu_id=excluded.menu_id, title=excluded.title, enabled=true,
38
+ table_name=excluded.table_name returning route_id, table_name`;
39
+ try {
40
+ const { rowCount } = await client.query(q1);
41
+ console.log('interface insert ok', values, rowCount);
42
+ } catch (err) {
43
+ console.log('interface insert error', values, q1, err);
44
+ }
45
+ }
46
+ });
47
+
48
+ fastify.addHook('onListen', async () => {
49
+ const { client: pg } = pgClients;
50
+ const clsQuery = [];
51
+ if (!pg.pk?.['admin.cls']) return;
52
+
53
+ const cls = ['cls', 'select']
54
+ .filter((el) => fs.existsSync(`${userTemplateDir[0]}/${el}`))
55
+ .map((el) => fs.readdirSync(`${userTemplateDir[0]}/${el}`).filter((item) => el === 'cls' ? true : path.extname(item) === '.sql'))
56
+ .reduce((acc, curr) => { curr?.forEach((el) => acc.push(el)); return acc; }, []);
57
+
58
+ try {
59
+ await Promise.all(cls.map(async (el) => {
60
+ const { ext, name } = path.parse(el);
61
+ const type = { '.json': 'cls', '.sql': 'select' }[ext];
62
+ const loadTemplate = await getTemplate(type, name);
63
+ console.log(name, type);
64
+ if (type === 'select') {
65
+ clsQuery.push(`insert into admin.cls(name,type,data) values('${name}','sql','${(loadTemplate?.sql || loadTemplate)?.replace(/'/g, "''")}')`);
66
+ } else if (type === 'cls') {
67
+ clsQuery.push(`insert into admin.cls(name,type) values('${name}','json');
68
+ insert into admin.cls(code,name,parent,icon)
69
+ select value->>'id',value->>'text','${name}',value->>'icon'
70
+ from json_array_elements('${JSON.stringify(loadTemplate).replace(/'/g, "''")}'::json)`);
71
+ }
72
+ }));
73
+
74
+ await pg.query('truncate admin.cls');
75
+ if (clsQuery.filter((el) => el).length) {
76
+ await pg.query(clsQuery.filter((el) => el).join(';'));
77
+ console.log('cls insert ok', clsQuery?.length);
78
+ }
79
+ } catch (err) {
80
+ console.error('cls insert error', err.toString());
81
+ }
82
+ });
83
+
84
+ // pre Request
85
+ fastify.addHook('onRequest', async (req) => {
86
+ req.funcs = fastify;
87
+ const { user } = req.session?.passport || {};
88
+ req.user = user;
89
+ });
90
+
91
+ // preSerialization
92
+ fastify.addHook('preSerialization', async (req, reply, payload) => {
93
+ if (req.url.includes('/suggest/') && !req.query.json) {
94
+ return payload?.data;
95
+ }
96
+ if (payload?.redirect) {
97
+ return reply.redirect(payload.redirect);
98
+ }
99
+ if (reply.sent) {
100
+ return null;
101
+ }
102
+
103
+ if (['200', '400', '500', '403', '404'].includes(payload?.status)) {
104
+ reply.status(payload.status);
105
+ }
106
+ /* if (payload.headers) {
107
+ reply.headers(payload.headers);
108
+ } */
109
+ if (payload?.buffer) {
110
+ return payload.buffer;
111
+ }
112
+ if (payload?.file) {
113
+ // const buffer = await readFile(payload.file);
114
+ // return reply.send(buffer);
115
+ const stream = fs.createReadStream(payload.file);
116
+ return stream;
117
+ // return reply.send(stream);
118
+ }
119
+
120
+ if (payload?.message) {
121
+ return payload.message;
122
+ }
123
+ return payload;
124
+ });
125
+
126
+ // preValidation
127
+ fastify.addHook('preValidation', async (req) => {
128
+ const parseRawBody = ['POST', 'PUT'].includes(req.method) && req.body && typeof req.body === 'string'
129
+ && req.body.trim(/\r\n/g).startsWith('{')
130
+ && req.body.trim(/\r\n/g).endsWith('}');
131
+ if (parseRawBody) {
132
+ try {
133
+ req.body = JSON.parse(req.body || '{}');
134
+ }
135
+ catch (err) {
136
+ // throw new Error('invalid body');
137
+ // return { error: 'invalid body', status: 400 };
138
+ }
139
+ }
140
+ });
141
+
142
+ // allow upload file
143
+ const kIsMultipart = Symbol.for('[FastifyMultipart.isMultipart]');
144
+ fastify.addContentTypeParser('multipart', (request, _, done) => {
145
+ request[kIsMultipart] = true;
146
+ done(null);
147
+ });
148
+
149
+ // parse Body
150
+ function contentParser(req, body, done) {
151
+ const parseBody = decodeURIComponent(body.toString()).split('&').reduce((acc, el) => {
152
+ const [key, val] = el.split('=');
153
+ return { ...acc, [key]: val };
154
+ }, {});
155
+ done(null, parseBody);
156
+ }
157
+
158
+ fastify.addContentTypeParser('application/x-www-form-urlencoded', { parseAs: 'buffer' }, contentParser);
159
+ }
160
+
161
+ export default fp(plugin);
@@ -1,69 +1,69 @@
1
- import fs from 'fs';
2
- import path, { dirname } from 'path';
3
- import { fileURLToPath } from 'url';
4
-
5
- const dir = dirname(fileURLToPath(import.meta.url));
6
- const root = `${dir}/../..`;
7
-
8
- const isProduction = process.env.NODE_ENV === 'production';
9
-
10
- async function plugin(fastify) {
11
- // vite server
12
- if (!isProduction) {
13
- const vite = await import('vite');
14
-
15
- const viteServer = await vite.createServer({
16
- server: {
17
- middlewareMode: true,
18
- },
19
- });
20
- // hot reload
21
- viteServer.watcher.on('all', function (d, t) {
22
- if (!t.includes('module')) return;
23
- console.log(d, t);
24
- viteServer.ws.send({ type: 'full-reload' });
25
- });
26
-
27
- // this is middleware for vite's dev servert
28
- fastify.addHook('onRequest', async (req, reply) => {
29
- const { user } = req.session?.passport || {};
30
- const { disableAuth } = req.funcs?.config || {};
31
- if (!user && !disableAuth) {
32
- // return reply.send('access restricted');
33
- }
34
-
35
- const next = () => new Promise((resolve) => {
36
- viteServer.middlewares(req.raw, reply.raw, () => resolve());
37
- });
38
- await next();
39
- });
40
- fastify.get('*', async () => { });
41
- return;
42
- }
43
-
44
- // From Build
45
- fastify.get('*', async (req, reply) => {
46
- const { user } = req.session?.passport || {};
47
-
48
- // if (!user) return reply.redirect('/login');
49
- const stream = fs.createReadStream('dist/index.html');
50
- return reply.type('text/html').send(stream);
51
- });
52
-
53
- async function staticFile(req, reply) {
54
- const assetsDir = 'dist';
55
- const filePath = path.join(root, assetsDir, req.url);
56
- const ext = path.extname(filePath);
57
- const mime = {
58
- '.js': 'text/javascript', '.css': 'text/css', '.woff2': 'application/font-woff', '.png': 'image/png', '.svg': 'image/svg+xml', '.jpg': 'image/jpg',
59
- }[ext];
60
- reply.headers({ 'Cache-control': 'max-age=3600, public' });
61
- const stream = fs.createReadStream(filePath);
62
- return mime ? reply.type(mime).send(stream) : stream;
63
- }
64
-
65
- fastify.get('/assets/*', staticFile);
66
- fastify.get('/public/*', staticFile);
67
- }
68
-
69
- export default plugin;
1
+ import fs from 'fs';
2
+ import path, { dirname } from 'path';
3
+ import { fileURLToPath } from 'url';
4
+
5
+ const dir = dirname(fileURLToPath(import.meta.url));
6
+ const root = `${dir}/../..`;
7
+
8
+ const isProduction = process.env.NODE_ENV === 'production';
9
+
10
+ async function plugin(fastify) {
11
+ // vite server
12
+ if (!isProduction) {
13
+ const vite = await import('vite');
14
+
15
+ const viteServer = await vite.createServer({
16
+ server: {
17
+ middlewareMode: true,
18
+ },
19
+ });
20
+ // hot reload
21
+ viteServer.watcher.on('all', function (d, t) {
22
+ if (!t.includes('module')) return;
23
+ console.log(d, t);
24
+ viteServer.ws.send({ type: 'full-reload' });
25
+ });
26
+
27
+ // this is middleware for vite's dev servert
28
+ fastify.addHook('onRequest', async (req, reply) => {
29
+ const { user } = req.session?.passport || {};
30
+ const { disableAuth } = req.funcs?.config || {};
31
+ if (!user && !disableAuth) {
32
+ // return reply.send('access restricted');
33
+ }
34
+
35
+ const next = () => new Promise((resolve) => {
36
+ viteServer.middlewares(req.raw, reply.raw, () => resolve());
37
+ });
38
+ await next();
39
+ });
40
+ fastify.get('*', async () => { });
41
+ return;
42
+ }
43
+
44
+ // From Build
45
+ fastify.get('*', async (req, reply) => {
46
+ const { user } = req.session?.passport || {};
47
+
48
+ // if (!user) return reply.redirect('/login');
49
+ const stream = fs.createReadStream('dist/index.html');
50
+ return reply.type('text/html').send(stream);
51
+ });
52
+
53
+ async function staticFile(req, reply) {
54
+ const assetsDir = 'dist';
55
+ const filePath = path.join(root, assetsDir, req.url);
56
+ const ext = path.extname(filePath);
57
+ const mime = {
58
+ '.js': 'text/javascript', '.css': 'text/css', '.woff2': 'application/font-woff', '.png': 'image/png', '.svg': 'image/svg+xml', '.jpg': 'image/jpg',
59
+ }[ext];
60
+ reply.headers({ 'Cache-control': 'max-age=3600, public' });
61
+ const stream = fs.createReadStream(filePath);
62
+ return mime ? reply.type(mime).send(stream) : stream;
63
+ }
64
+
65
+ fastify.get('/assets/*', staticFile);
66
+ fastify.get('/public/*', staticFile);
67
+ }
68
+
69
+ export default plugin;
@@ -1,32 +1,32 @@
1
- import { getTemplate } from "@opengis/fastify-table/utils.js";
2
- // import yaml from 'js-yaml';
3
- import getTableData from "./tableData.js";
4
-
5
- export default async function getCardData({
6
- pg, funcs, params = {}, session = {},
7
- }) {
8
- const { table, id } = params;
9
- const time = Date.now();
10
-
11
- const template = await getTemplate('card', table);
12
-
13
- const tableTemplate = await getTemplate('table', table);
14
- const index = template?.find(el => el[0] === 'index.yml')?.[1] || {}
15
- //return template
16
-
17
- const data = {};
18
- const { message, rows = [] } = await getTableData({ pg, funcs, params: { table, id }, session, mode: 'card' });
19
-
20
- if (message) return { message };
21
-
22
- if (template) {
23
- await Promise.all(template.filter(el => el[0].includes('.hbs')).map(async (el) => {
24
- const htmlContent = await funcs.handlebars.compile(el[1])(rows[0]);
25
- const name = el[0].substring(0, el[0].lastIndexOf('.'))
26
- data[name] = htmlContent;
27
- }));
28
- }
29
-
30
- return { time: Date.now() - time, ...index, data, rows, columns: tableTemplate?.columns || tableTemplate?.colModel };
31
-
1
+ import { getTemplate } from "@opengis/fastify-table/utils.js";
2
+ // import yaml from 'js-yaml';
3
+ import getTableData from "./tableData.js";
4
+
5
+ export default async function getCardData({
6
+ pg, funcs, params = {}, session = {},
7
+ }) {
8
+ const { table, id } = params;
9
+ const time = Date.now();
10
+
11
+ const template = await getTemplate('card', table);
12
+
13
+ const tableTemplate = await getTemplate('table', table);
14
+ const index = template?.find(el => el[0] === 'index.yml')?.[1] || {}
15
+ //return template
16
+
17
+ const data = {};
18
+ const { message, rows = [] } = await getTableData({ pg, funcs, params: { table, id }, session, mode: 'card' });
19
+
20
+ if (message) return { message };
21
+
22
+ if (template) {
23
+ await Promise.all(template.filter(el => el[0].includes('.hbs')).map(async (el) => {
24
+ const htmlContent = await funcs.handlebars.compile(el[1])(rows[0]);
25
+ const name = el[0].substring(0, el[0].lastIndexOf('.'))
26
+ data[name] = htmlContent;
27
+ }));
28
+ }
29
+
30
+ return { time: Date.now() - time, ...index, data, rows, columns: tableTemplate?.columns || tableTemplate?.colModel };
31
+
32
32
  }