@opengis/bi 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 +92 -92
- package/dist/bi.js +1 -1
- package/dist/bi.umd.cjs +68 -68
- package/dist/{import-file-D-ISqB7l.js → import-file-BwxPX622.js} +1132 -1079
- package/dist/style.css +1 -1
- package/dist/{vs-funnel-bar-aoZzvriV.js → vs-funnel-bar-BV18EA4K.js} +3 -3
- package/dist/{vs-list-CBkyJSBj.js → vs-list-WrrWQ5KF.js} +32 -53
- package/dist/{vs-map-C3C11qmT.js → vs-map-CYd9vdrd.js} +3 -3
- package/dist/{vs-map-cluster-BsPmHIMx.js → vs-map-cluster-5TnGPuBH.js} +3 -3
- package/dist/{vs-number-d58ftpH5.js → vs-number-DUeRr7uz.js} +3 -3
- package/dist/{vs-table-BHa5Velm.js → vs-table-CZJnXfUv.js} +6 -6
- package/dist/{vs-text-Bq87gMTx.js → vs-text-D3nCPkgk.js} +4 -4
- package/package.json +77 -77
- package/plugin.js +21 -21
- package/server/helpers/mdToHTML.js +17 -17
- package/server/migrations/bi.dataset.sql +46 -46
- package/server/migrations/bi.sql +114 -114
- package/server/plugins/docs.js +48 -48
- package/server/plugins/hook.js +89 -89
- package/server/routes/dashboard/controllers/dashboard.import.js +103 -103
- package/server/routes/dashboard/controllers/dashboard.js +158 -158
- package/server/routes/dashboard/controllers/dashboard.list.js +60 -60
- package/server/routes/dashboard/controllers/utils/yaml.js +11 -11
- package/server/routes/dashboard/index.mjs +26 -26
- package/server/routes/data/controllers/data.js +230 -230
- package/server/routes/data/controllers/util/chartSQL.js +49 -49
- package/server/routes/data/controllers/util/normalizeData.js +65 -65
- package/server/routes/data/index.mjs +38 -38
- package/server/routes/dataset/controllers/bi.dataset.list.js +29 -29
- package/server/routes/dataset/controllers/bi.db.list.js +19 -19
- package/server/routes/dataset/controllers/comment.js +55 -55
- package/server/routes/dataset/controllers/createDatasetPost.js +134 -134
- package/server/routes/dataset/controllers/data.js +149 -149
- package/server/routes/dataset/controllers/dbTablePreview.js +58 -58
- package/server/routes/dataset/controllers/dbTables.js +34 -34
- package/server/routes/dataset/controllers/delete.js +40 -40
- package/server/routes/dataset/controllers/deleteDataset.js +52 -52
- package/server/routes/dataset/controllers/editDataset.js +90 -90
- package/server/routes/dataset/controllers/export.js +214 -214
- package/server/routes/dataset/controllers/form.js +99 -99
- package/server/routes/dataset/controllers/format.js +46 -46
- package/server/routes/dataset/controllers/insert.js +47 -47
- package/server/routes/dataset/controllers/table.js +68 -68
- package/server/routes/dataset/controllers/update.js +43 -43
- package/server/routes/dataset/index.mjs +132 -132
- package/server/routes/dataset/utils/convertJSONToCSV.js +17 -17
- package/server/routes/dataset/utils/convertJSONToXls.js +47 -47
- package/server/routes/dataset/utils/createTableQuery.js +59 -59
- package/server/routes/dataset/utils/datasetForms.js +1 -1
- package/server/routes/dataset/utils/descriptionList.js +45 -45
- package/server/routes/dataset/utils/downloadRemoteFile.js +58 -58
- package/server/routes/dataset/utils/executeQuery.js +46 -46
- package/server/routes/dataset/utils/getLayersData.js +106 -106
- package/server/routes/dataset/utils/getTableData.js +46 -46
- package/server/routes/dataset/utils/insertDataQuery.js +12 -12
- package/server/routes/dataset/utils/metaFormat.js +24 -24
- package/server/routes/edit/controllers/dashboard.add.js +36 -36
- package/server/routes/edit/controllers/dashboard.delete.js +39 -39
- package/server/routes/edit/controllers/dashboard.edit.js +61 -61
- package/server/routes/edit/controllers/widget.add.js +78 -78
- package/server/routes/edit/controllers/widget.del.js +58 -58
- package/server/routes/edit/controllers/widget.edit.js +115 -115
- package/server/routes/edit/index.mjs +33 -33
- package/server/routes/map/controllers/cluster.js +125 -125
- package/server/routes/map/controllers/clusterVtile.js +166 -166
- package/server/routes/map/controllers/geojson.js +127 -127
- package/server/routes/map/controllers/heatmap.js +118 -118
- package/server/routes/map/controllers/map.js +69 -69
- package/server/routes/map/controllers/utils/downloadClusterData.js +44 -44
- package/server/routes/map/controllers/vtile.js +183 -183
- package/server/routes/map/index.mjs +32 -32
- package/server/templates/page/login.html +58 -58
- package/server/utils/getWidget.js +118 -118
- package/utils.js +12 -12
package/server/migrations/bi.sql
CHANGED
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
create schema if not exists bi;
|
|
2
|
-
|
|
3
|
-
CREATE TABLE if not exists bi.dashboard ();
|
|
4
|
-
alter table bi.dashboard drop constraint if exists dashboard_id_pkey cascade;
|
|
5
|
-
|
|
6
|
-
alter table bi.dashboard add column if not exists dashboard_id text;
|
|
7
|
-
alter table bi.dashboard alter column dashboard_id set not null;
|
|
8
|
-
alter table bi.dashboard alter column dashboard_id set default next_id();
|
|
9
|
-
|
|
10
|
-
alter table bi.dashboard add column if not exists title text;
|
|
11
|
-
alter table bi.dashboard add column if not exists description text;
|
|
12
|
-
alter table bi.dashboard add column if not exists widgets json;
|
|
13
|
-
alter table bi.dashboard add column if not exists table_name text;
|
|
14
|
-
alter table bi.dashboard add column if not exists style json;
|
|
15
|
-
alter table bi.dashboard add column if not exists name text;
|
|
16
|
-
alter table bi.dashboard alter column name set not null;
|
|
17
|
-
alter table bi.dashboard add column if not exists panels json;
|
|
18
|
-
alter table bi.dashboard add column if not exists grid json;
|
|
19
|
-
alter table bi.dashboard add column if not exists filters json;
|
|
20
|
-
alter table bi.dashboard add column if not exists words text;
|
|
21
|
-
alter table bi.dashboard add column if not exists public boolean;
|
|
22
|
-
alter table bi.dashboard add column if not exists db text;
|
|
23
|
-
alter table bi.dashboard add column if not exists uid text;
|
|
24
|
-
alter table bi.dashboard add column if not exists cdate timestamp without time zone;
|
|
25
|
-
alter table bi.dashboard add column if not exists source text;
|
|
26
|
-
|
|
27
|
-
alter table bi.dashboard add CONSTRAINT dashboard_id_pkey PRIMARY KEY (dashboard_id);
|
|
28
|
-
|
|
29
|
-
COMMENT ON TABLE bi.dashboard IS 'Дашборди';
|
|
30
|
-
COMMENT ON COLUMN bi.dashboard.dashboard_id IS 'PK';
|
|
31
|
-
COMMENT ON COLUMN bi.dashboard.title IS 'Заголовок';
|
|
32
|
-
COMMENT ON COLUMN bi.dashboard.description IS 'Опис';
|
|
33
|
-
COMMENT ON COLUMN bi.dashboard.widgets IS 'Віджети';
|
|
34
|
-
COMMENT ON COLUMN bi.dashboard.table_name IS 'Назва таблиці';
|
|
35
|
-
COMMENT ON COLUMN bi.dashboard.style IS 'Стилі';
|
|
36
|
-
COMMENT ON COLUMN bi.dashboard.name IS 'Назва';
|
|
37
|
-
COMMENT ON COLUMN bi.dashboard.panels IS 'Панелі віджетів';
|
|
38
|
-
COMMENT ON COLUMN bi.dashboard.grid IS 'Сітка';
|
|
39
|
-
COMMENT ON COLUMN bi.dashboard.filters IS 'Фільтри';
|
|
40
|
-
COMMENT ON COLUMN bi.dashboard.words IS 'Ключові слова';
|
|
41
|
-
COMMENT ON COLUMN bi.dashboard.public IS 'Публічний доступ';
|
|
42
|
-
COMMENT ON COLUMN bi.dashboard.db IS 'БД';
|
|
43
|
-
COMMENT ON COLUMN bi.dashboard.uid IS 'User ID';
|
|
44
|
-
COMMENT ON COLUMN bi.dashboard.cdate IS 'Creation date';
|
|
45
|
-
COMMENT ON COLUMN bi.dashboard.source IS 'Джерело (file)';
|
|
46
|
-
|
|
47
|
-
CREATE TABLE if not exists bi.widget ();
|
|
48
|
-
alter table bi.widget drop constraint if exists widget_id_pk;
|
|
49
|
-
alter table bi.widget drop constraint if exists widget_id_fkey;
|
|
50
|
-
|
|
51
|
-
alter table bi.widget add column if not exists widget_id text;
|
|
52
|
-
alter table bi.widget alter column widget_id set not null;
|
|
53
|
-
alter table bi.widget alter column widget_id set default next_id();
|
|
54
|
-
alter table bi.widget add column if not exists type text;
|
|
55
|
-
alter table bi.widget add column if not exists title text;
|
|
56
|
-
alter table bi.widget add column if not exists style json;
|
|
57
|
-
alter table bi.widget add column if not exists data json;
|
|
58
|
-
alter table bi.widget add column if not exists table_name text;
|
|
59
|
-
alter table bi.widget add column if not exists dashboard_id text;
|
|
60
|
-
alter table bi.widget add column if not exists name text;
|
|
61
|
-
alter table bi.widget add column if not exists x text;
|
|
62
|
-
alter table bi.widget add column if not exists col numeric;
|
|
63
|
-
alter table bi.widget add column if not exists metrics text;
|
|
64
|
-
alter table bi.widget add column if not exists yml text;
|
|
65
|
-
alter table bi.widget add column if not exists query text;
|
|
66
|
-
alter table bi.widget add column if not exists cls text;
|
|
67
|
-
|
|
68
|
-
alter table bi.widget add CONSTRAINT widget_id_pk PRIMARY KEY (widget_id);
|
|
69
|
-
alter table bi.widget add CONSTRAINT widget_id_fkey FOREIGN KEY (dashboard_id) REFERENCES bi.dashboard (dashboard_id);
|
|
70
|
-
|
|
71
|
-
COMMENT ON TABLE bi.widget IS 'Віджети';
|
|
72
|
-
COMMENT ON COLUMN bi.widget.widget_id IS 'PK';
|
|
73
|
-
COMMENT ON COLUMN bi.widget.type IS 'Тип';
|
|
74
|
-
COMMENT ON COLUMN bi.widget.title IS 'Назва';
|
|
75
|
-
COMMENT ON COLUMN bi.widget.style IS 'Стилі';
|
|
76
|
-
COMMENT ON COLUMN bi.widget.yml IS 'Yml';
|
|
77
|
-
COMMENT ON COLUMN bi.widget.query IS 'Запит до таблиці';
|
|
78
|
-
COMMENT ON COLUMN bi.widget.x IS 'Колонка для осі метрик';
|
|
79
|
-
COMMENT ON COLUMN bi.widget.cls IS 'Класифікатор метрик';
|
|
80
|
-
COMMENT ON COLUMN bi.widget.yml IS 'Yml';
|
|
81
|
-
COMMENT ON COLUMN bi.widget.data IS 'Дані';
|
|
82
|
-
COMMENT ON COLUMN bi.widget.table_name IS 'Назва таблиці';
|
|
83
|
-
COMMENT ON COLUMN bi.widget.dashboard_id IS 'Ідентифікатор дашборду';
|
|
84
|
-
|
|
85
|
-
create table if not exists bi.cluster();
|
|
86
|
-
alter table bi.cluster drop constraint if exists bi_cluster_cluster_id_pkey;
|
|
87
|
-
alter table bi.cluster drop constraint if exists bi_cluster_title_type_unique;
|
|
88
|
-
|
|
89
|
-
alter table bi.cluster add column if not exists cluster_id text;
|
|
90
|
-
alter table bi.cluster alter column cluster_id set not null;
|
|
91
|
-
alter table bi.cluster alter column cluster_id set default next_id();
|
|
92
|
-
|
|
93
|
-
alter table bi.cluster alter column cluster_id set default next_id();
|
|
94
|
-
ALTER TABLE bi.cluster ADD COLUMN IF NOT EXISTS title text;
|
|
95
|
-
ALTER TABLE bi.cluster ADD COLUMN IF NOT EXISTS type text;
|
|
96
|
-
ALTER TABLE bi.cluster ADD COLUMN IF NOT EXISTS codifier text;
|
|
97
|
-
ALTER TABLE bi.cluster ADD COLUMN IF NOT EXISTS geom geometry(MultiPolygon,4326);
|
|
98
|
-
|
|
99
|
-
ALTER TABLE bi.cluster ADD COLUMN IF NOT EXISTS uid text;
|
|
100
|
-
ALTER TABLE bi.cluster ADD COLUMN IF NOT EXISTS files json;
|
|
101
|
-
ALTER TABLE bi.cluster ADD COLUMN IF NOT EXISTS cdate timestamp without time zone;
|
|
102
|
-
alter table bi.cluster alter column cdate set DEFAULT (now())::timestamp without time zone;
|
|
103
|
-
ALTER TABLE bi.cluster ADD COLUMN IF NOT EXISTS editor_id text;
|
|
104
|
-
ALTER TABLE bi.cluster ADD COLUMN IF NOT EXISTS editor_date timestamp without time zone;
|
|
105
|
-
|
|
106
|
-
ALTER TABLE bi.cluster ADD CONSTRAINT bi_cluster_cluster_id_pkey PRIMARY KEY (cluster_id);
|
|
107
|
-
ALTER TABLE bi.cluster ADD CONSTRAINT bi_cluster_title_type_unique UNIQUE(title, type);
|
|
108
|
-
|
|
109
|
-
comment on table bi.cluster is 'Дані для побудови cluster віджетів';
|
|
110
|
-
|
|
111
|
-
comment on column bi.cluster.title is 'Назва';
|
|
112
|
-
comment on column bi.cluster.type is 'Тип кластеру';
|
|
113
|
-
|
|
114
|
-
alter table bi.dashboard add column if not exists updated_at timestamp without time zone NOT NULL DEFAULT date_trunc('seconds'::text, now());
|
|
1
|
+
create schema if not exists bi;
|
|
2
|
+
|
|
3
|
+
CREATE TABLE if not exists bi.dashboard ();
|
|
4
|
+
alter table bi.dashboard drop constraint if exists dashboard_id_pkey cascade;
|
|
5
|
+
|
|
6
|
+
alter table bi.dashboard add column if not exists dashboard_id text;
|
|
7
|
+
alter table bi.dashboard alter column dashboard_id set not null;
|
|
8
|
+
alter table bi.dashboard alter column dashboard_id set default next_id();
|
|
9
|
+
|
|
10
|
+
alter table bi.dashboard add column if not exists title text;
|
|
11
|
+
alter table bi.dashboard add column if not exists description text;
|
|
12
|
+
alter table bi.dashboard add column if not exists widgets json;
|
|
13
|
+
alter table bi.dashboard add column if not exists table_name text;
|
|
14
|
+
alter table bi.dashboard add column if not exists style json;
|
|
15
|
+
alter table bi.dashboard add column if not exists name text;
|
|
16
|
+
alter table bi.dashboard alter column name set not null;
|
|
17
|
+
alter table bi.dashboard add column if not exists panels json;
|
|
18
|
+
alter table bi.dashboard add column if not exists grid json;
|
|
19
|
+
alter table bi.dashboard add column if not exists filters json;
|
|
20
|
+
alter table bi.dashboard add column if not exists words text;
|
|
21
|
+
alter table bi.dashboard add column if not exists public boolean;
|
|
22
|
+
alter table bi.dashboard add column if not exists db text;
|
|
23
|
+
alter table bi.dashboard add column if not exists uid text;
|
|
24
|
+
alter table bi.dashboard add column if not exists cdate timestamp without time zone;
|
|
25
|
+
alter table bi.dashboard add column if not exists source text;
|
|
26
|
+
|
|
27
|
+
alter table bi.dashboard add CONSTRAINT dashboard_id_pkey PRIMARY KEY (dashboard_id);
|
|
28
|
+
|
|
29
|
+
COMMENT ON TABLE bi.dashboard IS 'Дашборди';
|
|
30
|
+
COMMENT ON COLUMN bi.dashboard.dashboard_id IS 'PK';
|
|
31
|
+
COMMENT ON COLUMN bi.dashboard.title IS 'Заголовок';
|
|
32
|
+
COMMENT ON COLUMN bi.dashboard.description IS 'Опис';
|
|
33
|
+
COMMENT ON COLUMN bi.dashboard.widgets IS 'Віджети';
|
|
34
|
+
COMMENT ON COLUMN bi.dashboard.table_name IS 'Назва таблиці';
|
|
35
|
+
COMMENT ON COLUMN bi.dashboard.style IS 'Стилі';
|
|
36
|
+
COMMENT ON COLUMN bi.dashboard.name IS 'Назва';
|
|
37
|
+
COMMENT ON COLUMN bi.dashboard.panels IS 'Панелі віджетів';
|
|
38
|
+
COMMENT ON COLUMN bi.dashboard.grid IS 'Сітка';
|
|
39
|
+
COMMENT ON COLUMN bi.dashboard.filters IS 'Фільтри';
|
|
40
|
+
COMMENT ON COLUMN bi.dashboard.words IS 'Ключові слова';
|
|
41
|
+
COMMENT ON COLUMN bi.dashboard.public IS 'Публічний доступ';
|
|
42
|
+
COMMENT ON COLUMN bi.dashboard.db IS 'БД';
|
|
43
|
+
COMMENT ON COLUMN bi.dashboard.uid IS 'User ID';
|
|
44
|
+
COMMENT ON COLUMN bi.dashboard.cdate IS 'Creation date';
|
|
45
|
+
COMMENT ON COLUMN bi.dashboard.source IS 'Джерело (file)';
|
|
46
|
+
|
|
47
|
+
CREATE TABLE if not exists bi.widget ();
|
|
48
|
+
alter table bi.widget drop constraint if exists widget_id_pk;
|
|
49
|
+
alter table bi.widget drop constraint if exists widget_id_fkey;
|
|
50
|
+
|
|
51
|
+
alter table bi.widget add column if not exists widget_id text;
|
|
52
|
+
alter table bi.widget alter column widget_id set not null;
|
|
53
|
+
alter table bi.widget alter column widget_id set default next_id();
|
|
54
|
+
alter table bi.widget add column if not exists type text;
|
|
55
|
+
alter table bi.widget add column if not exists title text;
|
|
56
|
+
alter table bi.widget add column if not exists style json;
|
|
57
|
+
alter table bi.widget add column if not exists data json;
|
|
58
|
+
alter table bi.widget add column if not exists table_name text;
|
|
59
|
+
alter table bi.widget add column if not exists dashboard_id text;
|
|
60
|
+
alter table bi.widget add column if not exists name text;
|
|
61
|
+
alter table bi.widget add column if not exists x text;
|
|
62
|
+
alter table bi.widget add column if not exists col numeric;
|
|
63
|
+
alter table bi.widget add column if not exists metrics text;
|
|
64
|
+
alter table bi.widget add column if not exists yml text;
|
|
65
|
+
alter table bi.widget add column if not exists query text;
|
|
66
|
+
alter table bi.widget add column if not exists cls text;
|
|
67
|
+
|
|
68
|
+
alter table bi.widget add CONSTRAINT widget_id_pk PRIMARY KEY (widget_id);
|
|
69
|
+
alter table bi.widget add CONSTRAINT widget_id_fkey FOREIGN KEY (dashboard_id) REFERENCES bi.dashboard (dashboard_id);
|
|
70
|
+
|
|
71
|
+
COMMENT ON TABLE bi.widget IS 'Віджети';
|
|
72
|
+
COMMENT ON COLUMN bi.widget.widget_id IS 'PK';
|
|
73
|
+
COMMENT ON COLUMN bi.widget.type IS 'Тип';
|
|
74
|
+
COMMENT ON COLUMN bi.widget.title IS 'Назва';
|
|
75
|
+
COMMENT ON COLUMN bi.widget.style IS 'Стилі';
|
|
76
|
+
COMMENT ON COLUMN bi.widget.yml IS 'Yml';
|
|
77
|
+
COMMENT ON COLUMN bi.widget.query IS 'Запит до таблиці';
|
|
78
|
+
COMMENT ON COLUMN bi.widget.x IS 'Колонка для осі метрик';
|
|
79
|
+
COMMENT ON COLUMN bi.widget.cls IS 'Класифікатор метрик';
|
|
80
|
+
COMMENT ON COLUMN bi.widget.yml IS 'Yml';
|
|
81
|
+
COMMENT ON COLUMN bi.widget.data IS 'Дані';
|
|
82
|
+
COMMENT ON COLUMN bi.widget.table_name IS 'Назва таблиці';
|
|
83
|
+
COMMENT ON COLUMN bi.widget.dashboard_id IS 'Ідентифікатор дашборду';
|
|
84
|
+
|
|
85
|
+
create table if not exists bi.cluster();
|
|
86
|
+
alter table bi.cluster drop constraint if exists bi_cluster_cluster_id_pkey;
|
|
87
|
+
alter table bi.cluster drop constraint if exists bi_cluster_title_type_unique;
|
|
88
|
+
|
|
89
|
+
alter table bi.cluster add column if not exists cluster_id text;
|
|
90
|
+
alter table bi.cluster alter column cluster_id set not null;
|
|
91
|
+
alter table bi.cluster alter column cluster_id set default next_id();
|
|
92
|
+
|
|
93
|
+
alter table bi.cluster alter column cluster_id set default next_id();
|
|
94
|
+
ALTER TABLE bi.cluster ADD COLUMN IF NOT EXISTS title text;
|
|
95
|
+
ALTER TABLE bi.cluster ADD COLUMN IF NOT EXISTS type text;
|
|
96
|
+
ALTER TABLE bi.cluster ADD COLUMN IF NOT EXISTS codifier text;
|
|
97
|
+
ALTER TABLE bi.cluster ADD COLUMN IF NOT EXISTS geom geometry(MultiPolygon,4326);
|
|
98
|
+
|
|
99
|
+
ALTER TABLE bi.cluster ADD COLUMN IF NOT EXISTS uid text;
|
|
100
|
+
ALTER TABLE bi.cluster ADD COLUMN IF NOT EXISTS files json;
|
|
101
|
+
ALTER TABLE bi.cluster ADD COLUMN IF NOT EXISTS cdate timestamp without time zone;
|
|
102
|
+
alter table bi.cluster alter column cdate set DEFAULT (now())::timestamp without time zone;
|
|
103
|
+
ALTER TABLE bi.cluster ADD COLUMN IF NOT EXISTS editor_id text;
|
|
104
|
+
ALTER TABLE bi.cluster ADD COLUMN IF NOT EXISTS editor_date timestamp without time zone;
|
|
105
|
+
|
|
106
|
+
ALTER TABLE bi.cluster ADD CONSTRAINT bi_cluster_cluster_id_pkey PRIMARY KEY (cluster_id);
|
|
107
|
+
ALTER TABLE bi.cluster ADD CONSTRAINT bi_cluster_title_type_unique UNIQUE(title, type);
|
|
108
|
+
|
|
109
|
+
comment on table bi.cluster is 'Дані для побудови cluster віджетів';
|
|
110
|
+
|
|
111
|
+
comment on column bi.cluster.title is 'Назва';
|
|
112
|
+
comment on column bi.cluster.type is 'Тип кластеру';
|
|
113
|
+
|
|
114
|
+
alter table bi.dashboard add column if not exists updated_at timestamp without time zone NOT NULL DEFAULT date_trunc('seconds'::text, now());
|
|
115
115
|
alter table bi.widget add column if not exists updated_at timestamp without time zone NOT NULL DEFAULT date_trunc('seconds'::text, now());
|
package/server/plugins/docs.js
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import path, { dirname } from 'path';
|
|
2
|
-
import { fileURLToPath } from 'url';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
|
|
5
|
-
const dir = dirname(fileURLToPath(import.meta.url));
|
|
6
|
-
const root = `${dir}/../../`;
|
|
7
|
-
|
|
8
|
-
async function plugin(fastify, opts) {
|
|
9
|
-
fastify.get('/docs*', async (req, reply) => {
|
|
10
|
-
if (!fs.existsSync(path.join(root, 'docs/.vitepress/dist/'))) {
|
|
11
|
-
return reply.status(404).send('docs not exists');
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const { params } = req;
|
|
15
|
-
const url = params['*'];
|
|
16
|
-
|
|
17
|
-
const filePath =
|
|
18
|
-
url && url[url.length - 1] !== '/'
|
|
19
|
-
? path.join(root, 'docs/.vitepress/dist/', url)
|
|
20
|
-
: path.join(root, 'docs/.vitepress/dist/', url, 'index.html');
|
|
21
|
-
|
|
22
|
-
if (!fs.existsSync(filePath)) {
|
|
23
|
-
return reply.status(404).send('File not found');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const ext = path.extname(filePath);
|
|
27
|
-
const mime = {
|
|
28
|
-
'.js': 'text/javascript',
|
|
29
|
-
'.css': 'text/css',
|
|
30
|
-
'.woff2': 'application/font-woff',
|
|
31
|
-
'.png': 'image/png',
|
|
32
|
-
'.svg': 'image/svg+xml',
|
|
33
|
-
'.jpg': 'image/jpg',
|
|
34
|
-
'.html': 'text/html',
|
|
35
|
-
'.json': 'application/json',
|
|
36
|
-
'.pdf': 'application/pdf',
|
|
37
|
-
}[ext];
|
|
38
|
-
|
|
39
|
-
const stream = fs.createReadStream(filePath);
|
|
40
|
-
stream.on('error', (err) => {
|
|
41
|
-
reply.status(500).send('Error reading file');
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
return mime ? reply.type(mime).send(stream) : reply.send(stream);
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export default plugin;
|
|
1
|
+
import path, { dirname } from 'path';
|
|
2
|
+
import { fileURLToPath } from 'url';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
|
|
5
|
+
const dir = dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
const root = `${dir}/../../`;
|
|
7
|
+
|
|
8
|
+
async function plugin(fastify, opts) {
|
|
9
|
+
fastify.get('/docs*', async (req, reply) => {
|
|
10
|
+
if (!fs.existsSync(path.join(root, 'docs/.vitepress/dist/'))) {
|
|
11
|
+
return reply.status(404).send('docs not exists');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const { params } = req;
|
|
15
|
+
const url = params['*'];
|
|
16
|
+
|
|
17
|
+
const filePath =
|
|
18
|
+
url && url[url.length - 1] !== '/'
|
|
19
|
+
? path.join(root, 'docs/.vitepress/dist/', url)
|
|
20
|
+
: path.join(root, 'docs/.vitepress/dist/', url, 'index.html');
|
|
21
|
+
|
|
22
|
+
if (!fs.existsSync(filePath)) {
|
|
23
|
+
return reply.status(404).send('File not found');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const ext = path.extname(filePath);
|
|
27
|
+
const mime = {
|
|
28
|
+
'.js': 'text/javascript',
|
|
29
|
+
'.css': 'text/css',
|
|
30
|
+
'.woff2': 'application/font-woff',
|
|
31
|
+
'.png': 'image/png',
|
|
32
|
+
'.svg': 'image/svg+xml',
|
|
33
|
+
'.jpg': 'image/jpg',
|
|
34
|
+
'.html': 'text/html',
|
|
35
|
+
'.json': 'application/json',
|
|
36
|
+
'.pdf': 'application/pdf',
|
|
37
|
+
}[ext];
|
|
38
|
+
|
|
39
|
+
const stream = fs.createReadStream(filePath);
|
|
40
|
+
stream.on('error', (err) => {
|
|
41
|
+
reply.status(500).send('Error reading file');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return mime ? reply.type(mime).send(stream) : reply.send(stream);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default plugin;
|
package/server/plugins/hook.js
CHANGED
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
import fp from 'fastify-plugin';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
|
|
4
|
-
// the use of fastify-plugin is required to be able
|
|
5
|
-
// to export the decorators to the outer scope
|
|
6
|
-
|
|
7
|
-
async function plugin(fastify) {
|
|
8
|
-
// preSerialization
|
|
9
|
-
fastify.addHook('preSerialization', async (req, reply, payload) => {
|
|
10
|
-
if (!req.session?.passport?.user?.uid) {
|
|
11
|
-
// return reply.redirect('/login');
|
|
12
|
-
}
|
|
13
|
-
if (req.url.includes('/suggest/') && !req.query.json) {
|
|
14
|
-
return payload?.data;
|
|
15
|
-
}
|
|
16
|
-
if (payload.redirect) {
|
|
17
|
-
return reply.redirect(payload.redirect);
|
|
18
|
-
}
|
|
19
|
-
if (reply.sent) {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if ([200, 400, 403, 409, 404, 500].includes(payload.status)) {
|
|
24
|
-
reply.status(payload.status);
|
|
25
|
-
}
|
|
26
|
-
/* if (payload.headers) {
|
|
27
|
-
reply.headers(payload.headers);
|
|
28
|
-
} */
|
|
29
|
-
if (payload.buffer) {
|
|
30
|
-
return payload.buffer;
|
|
31
|
-
}
|
|
32
|
-
if (payload.file) {
|
|
33
|
-
// const buffer = await readFile(payload.file);
|
|
34
|
-
// return reply.send(buffer);
|
|
35
|
-
const stream = fs.createReadStream(payload.file);
|
|
36
|
-
return stream;
|
|
37
|
-
// return reply.send(stream);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (payload.message) {
|
|
41
|
-
return payload.message;
|
|
42
|
-
}
|
|
43
|
-
return payload;
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
// preValidation
|
|
47
|
-
fastify.addHook('preValidation', async (req) => {
|
|
48
|
-
const parseRawBody =
|
|
49
|
-
['POST', 'PUT'].includes(req.method) &&
|
|
50
|
-
req.body &&
|
|
51
|
-
typeof req.body === 'string' &&
|
|
52
|
-
req.body.trim(/\r\n/g).startsWith('{') &&
|
|
53
|
-
req.body.trim(/\r\n/g).endsWith('}');
|
|
54
|
-
if (parseRawBody) {
|
|
55
|
-
try {
|
|
56
|
-
req.body = JSON.parse(req.body || '{}');
|
|
57
|
-
} catch (err) {
|
|
58
|
-
// throw new Error('invalid body');
|
|
59
|
-
// return { error: 'invalid body', status: 400 };
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// allow upload file
|
|
65
|
-
// const kIsMultipart = Symbol.for('[FastifyMultipart.isMultipart]');
|
|
66
|
-
// fastify.addContentTypeParser('multipart', (request, _, done) => {
|
|
67
|
-
// request[kIsMultipart] = true;
|
|
68
|
-
// done(null);
|
|
69
|
-
// });
|
|
70
|
-
|
|
71
|
-
// parse Body
|
|
72
|
-
function contentParser(req, body, done) {
|
|
73
|
-
const parseBody = decodeURIComponent(body.toString())
|
|
74
|
-
.split('&')
|
|
75
|
-
.reduce((acc, el) => {
|
|
76
|
-
const [key, val] = el.split('=');
|
|
77
|
-
return { ...acc, [key]: val };
|
|
78
|
-
}, {});
|
|
79
|
-
done(null, parseBody);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
fastify.addContentTypeParser(
|
|
83
|
-
'application/x-www-form-urlencoded',
|
|
84
|
-
{ parseAs: 'buffer' },
|
|
85
|
-
contentParser
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export default fp(plugin);
|
|
1
|
+
import fp from 'fastify-plugin';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
|
|
4
|
+
// the use of fastify-plugin is required to be able
|
|
5
|
+
// to export the decorators to the outer scope
|
|
6
|
+
|
|
7
|
+
async function plugin(fastify) {
|
|
8
|
+
// preSerialization
|
|
9
|
+
fastify.addHook('preSerialization', async (req, reply, payload) => {
|
|
10
|
+
if (!req.session?.passport?.user?.uid) {
|
|
11
|
+
// return reply.redirect('/login');
|
|
12
|
+
}
|
|
13
|
+
if (req.url.includes('/suggest/') && !req.query.json) {
|
|
14
|
+
return payload?.data;
|
|
15
|
+
}
|
|
16
|
+
if (payload.redirect) {
|
|
17
|
+
return reply.redirect(payload.redirect);
|
|
18
|
+
}
|
|
19
|
+
if (reply.sent) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if ([200, 400, 403, 409, 404, 500].includes(payload.status)) {
|
|
24
|
+
reply.status(payload.status);
|
|
25
|
+
}
|
|
26
|
+
/* if (payload.headers) {
|
|
27
|
+
reply.headers(payload.headers);
|
|
28
|
+
} */
|
|
29
|
+
if (payload.buffer) {
|
|
30
|
+
return payload.buffer;
|
|
31
|
+
}
|
|
32
|
+
if (payload.file) {
|
|
33
|
+
// const buffer = await readFile(payload.file);
|
|
34
|
+
// return reply.send(buffer);
|
|
35
|
+
const stream = fs.createReadStream(payload.file);
|
|
36
|
+
return stream;
|
|
37
|
+
// return reply.send(stream);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (payload.message) {
|
|
41
|
+
return payload.message;
|
|
42
|
+
}
|
|
43
|
+
return payload;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// preValidation
|
|
47
|
+
fastify.addHook('preValidation', async (req) => {
|
|
48
|
+
const parseRawBody =
|
|
49
|
+
['POST', 'PUT'].includes(req.method) &&
|
|
50
|
+
req.body &&
|
|
51
|
+
typeof req.body === 'string' &&
|
|
52
|
+
req.body.trim(/\r\n/g).startsWith('{') &&
|
|
53
|
+
req.body.trim(/\r\n/g).endsWith('}');
|
|
54
|
+
if (parseRawBody) {
|
|
55
|
+
try {
|
|
56
|
+
req.body = JSON.parse(req.body || '{}');
|
|
57
|
+
} catch (err) {
|
|
58
|
+
// throw new Error('invalid body');
|
|
59
|
+
// return { error: 'invalid body', status: 400 };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// allow upload file
|
|
65
|
+
// const kIsMultipart = Symbol.for('[FastifyMultipart.isMultipart]');
|
|
66
|
+
// fastify.addContentTypeParser('multipart', (request, _, done) => {
|
|
67
|
+
// request[kIsMultipart] = true;
|
|
68
|
+
// done(null);
|
|
69
|
+
// });
|
|
70
|
+
|
|
71
|
+
// parse Body
|
|
72
|
+
function contentParser(req, body, done) {
|
|
73
|
+
const parseBody = decodeURIComponent(body.toString())
|
|
74
|
+
.split('&')
|
|
75
|
+
.reduce((acc, el) => {
|
|
76
|
+
const [key, val] = el.split('=');
|
|
77
|
+
return { ...acc, [key]: val };
|
|
78
|
+
}, {});
|
|
79
|
+
done(null, parseBody);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
fastify.addContentTypeParser(
|
|
83
|
+
'application/x-www-form-urlencoded',
|
|
84
|
+
{ parseAs: 'buffer' },
|
|
85
|
+
contentParser
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export default fp(plugin);
|