@opengis/cms 0.0.33 → 0.0.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengis/cms",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.34",
|
|
4
4
|
"description": "cms",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Softpro",
|
|
@@ -15,8 +15,10 @@
|
|
|
15
15
|
"patch": "npm version patch && git push && npm publish",
|
|
16
16
|
"test": "node --test test/**/*.test.js",
|
|
17
17
|
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
18
|
+
"dev": "NODE_ENV=dev bun --env-file=.env.softpro server ",
|
|
19
|
+
"admin": "vite admin",
|
|
20
|
+
"build": "vite build && vite build admin",
|
|
21
|
+
"build:lib": "vite build",
|
|
20
22
|
"proxy": "vite dev admin",
|
|
21
23
|
"build-npm": "vite build",
|
|
22
24
|
"start": "bun --env-file=.env.ip server",
|
|
@@ -25,7 +27,6 @@
|
|
|
25
27
|
"prod": "NODE_ENV=production bun --env-file=.env.ip server ",
|
|
26
28
|
"prod-ip": "PORT=3019 node server --config=ip",
|
|
27
29
|
"prod-ip-test": "PORT=3025 node server --config=ip",
|
|
28
|
-
"dev": "node server --config=softpro",
|
|
29
30
|
"debug": "bun --watch server --config=softpro",
|
|
30
31
|
"ip-test": "node server --config=ip-test",
|
|
31
32
|
"ip": "node --env-file=.env.ip server",
|
package/server/plugins/vite.js
CHANGED
|
@@ -1,58 +1,46 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
|
-
import path
|
|
3
|
-
import {
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { createServer } from 'vite';
|
|
4
4
|
|
|
5
5
|
import { config } from '@opengis/fastify-table/utils.js';
|
|
6
6
|
|
|
7
|
-
const
|
|
8
|
-
const root = `${dir}/../..`;
|
|
9
|
-
const adminRoot = path.join(root, 'admin');
|
|
10
|
-
|
|
11
|
-
const isProduction = process.env.NODE_ENV === 'production' || config.production;
|
|
7
|
+
const isProduction = process.env.NODE_ENV !== 'dev';
|
|
12
8
|
console.log({ isProduction })
|
|
13
9
|
async function plugin(fastify) {
|
|
14
10
|
// vite server
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
server: {
|
|
22
|
-
middlewareMode: true,
|
|
23
|
-
},
|
|
24
|
-
});
|
|
11
|
+
const viteServer = !isProduction ? await createServer({
|
|
12
|
+
root: 'admin',
|
|
13
|
+
server: {
|
|
14
|
+
middlewareMode: true,
|
|
15
|
+
},
|
|
16
|
+
}) : null;
|
|
25
17
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// hot relaod template
|
|
18
|
+
if (!isProduction) {
|
|
19
|
+
const dir1 = process.cwd();
|
|
20
|
+
viteServer.watcher.add(dir1);
|
|
30
21
|
viteServer.watcher.on('all', (d, t) => {
|
|
31
22
|
if (!t.includes('module')) return;
|
|
32
23
|
console.log(d, t);
|
|
33
24
|
viteServer.ws.send({ type: 'full-reload' });
|
|
34
25
|
});
|
|
35
26
|
|
|
36
|
-
// this is middleware for vite's dev
|
|
27
|
+
// this is middleware for vite's dev server
|
|
37
28
|
fastify.addHook('onRequest', async (req, reply) => {
|
|
38
29
|
const { user } = req.session?.passport || {};
|
|
39
|
-
|
|
40
|
-
return reply.redirect('/login');
|
|
41
|
-
}
|
|
30
|
+
// console.log(req.url);
|
|
42
31
|
|
|
43
32
|
const next = () => new Promise((resolve) => {
|
|
44
33
|
viteServer.middlewares(req.raw, reply.raw, () => resolve());
|
|
45
34
|
});
|
|
35
|
+
|
|
46
36
|
await next();
|
|
47
37
|
});
|
|
48
|
-
fastify.get('*', async () => { });
|
|
49
|
-
return;
|
|
50
38
|
}
|
|
51
39
|
|
|
52
40
|
// From Build
|
|
53
41
|
fastify.get('*', async (req, reply) => {
|
|
54
42
|
const { user } = req.session?.passport || {};
|
|
55
|
-
const indexPath = path.join(
|
|
43
|
+
const indexPath = path.join('admin/dist', 'index.html');
|
|
56
44
|
if (!user && config.pg && !req.url.startsWith('/src/') && !config.auth?.disable) {
|
|
57
45
|
return reply.redirect('/login');
|
|
58
46
|
}
|
|
@@ -65,8 +53,8 @@ async function plugin(fastify) {
|
|
|
65
53
|
|
|
66
54
|
const fileSize = {};
|
|
67
55
|
async function staticFile(req, reply) {
|
|
68
|
-
const assetsDir = '/dist';
|
|
69
|
-
const filePath = path.join(
|
|
56
|
+
const assetsDir = 'admin/dist';
|
|
57
|
+
const filePath = path.join( assetsDir, req.url);
|
|
70
58
|
const ext = path.extname(filePath);
|
|
71
59
|
|
|
72
60
|
if (!fs.existsSync(filePath)) return { status: 404, message: 'not found' };
|
|
@@ -18,24 +18,23 @@ export default async function deleteContent(req, reply) {
|
|
|
18
18
|
return reply.status(400).send('not enough params: id');
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
22
21
|
if (id === 'pages') {
|
|
23
22
|
return reply.status(403).send('access restricted: pages contents cannot be deleted');
|
|
24
23
|
}
|
|
25
24
|
|
|
25
|
+
const { ctid, dbtable } = await pg.query('select content_type_id as ctid, table_name as dbtable from site.content_types where $1 in (content_type_id, name)', [params.type])
|
|
26
|
+
.then(el => el.rows?.[0] || {});
|
|
27
|
+
|
|
26
28
|
const arr = config.pg ? await pg.query(`select array_agg(relname)::text[] from pg_class a
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
left join pg_namespace b on a.relnamespace=b.oid
|
|
30
|
+
where a.relam=2 and b.nspname='data'`).then(el => el.rows?.[0]?.array_agg || []) : [];
|
|
29
31
|
|
|
30
|
-
if (!arr.length) {
|
|
32
|
+
if (!arr.length && type !== 'pages') {
|
|
31
33
|
return reply.status(400).send('empty schema: data');
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
const table = arr.find(el => el === params.type);
|
|
35
37
|
|
|
36
|
-
const { ctid, dbtable } = await pg.query('select content_type_id as ctid, table_name as dbtable from site.content_types where $1 in (content_type_id, name)', [params.type])
|
|
37
|
-
.then(el => el.rows?.[0] || {});
|
|
38
|
-
|
|
39
38
|
// singletone with extra at site.content_data
|
|
40
39
|
if (!table && !dbtable && ctid) {
|
|
41
40
|
const { cid, status } = ctid === 'pages' && id
|
|
@@ -47,20 +47,19 @@ export default async function updateContent(req, reply) {
|
|
|
47
47
|
return reply.status(400).send('empty body');
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
// order priority - custom columns -> default for pages
|
|
51
|
+
const { ctid, ctname, dbtable, columns: contentColumns = [] } = await pg.query('select content_type_id as ctid, name as ctname, table_name as dbtable, columns from site.content_types where content_type_id in (select content_type_id from site.contents where content_id=$1) or content_type_id=$2 order by content_type_id = \'pages\'', [id, type]).then(el => el.rows?.[0] || {});
|
|
52
|
+
|
|
50
53
|
const arr = config.pg ? await pg.query(`select array_agg(relname)::text[] from pg_class a
|
|
51
|
-
|
|
52
|
-
|
|
54
|
+
left join pg_namespace b on a.relnamespace=b.oid
|
|
55
|
+
where a.relam=2 and b.nspname='data'`).then(el => el.rows?.[0]?.array_agg || []) : [];
|
|
53
56
|
|
|
54
|
-
if (!arr.length) {
|
|
57
|
+
if (!arr.length && type !== 'pages') {
|
|
55
58
|
return reply.status(400).send('empty schema: data');
|
|
56
59
|
}
|
|
57
60
|
|
|
58
61
|
const table = arr.find(el => el === params.type);
|
|
59
62
|
|
|
60
|
-
// order priority - custom columns -> default for pages
|
|
61
|
-
const { ctid, ctname, dbtable, columns: contentColumns = [] } = await pg.query('select content_type_id as ctid, name as ctname, table_name as dbtable, columns from site.content_types where content_type_id in (select content_type_id from site.contents where content_id=$1) or content_type_id=$2 order by content_type_id = \'pages\'', [id, type]).then(el => el.rows?.[0] || {});
|
|
62
|
-
|
|
63
|
-
|
|
64
63
|
const loadTable = type === 'pages' ? await getTemplate('table', 'single.default.table') : {};
|
|
65
64
|
const columns = type === 'pages'
|
|
66
65
|
? (loadTable?.columns || []).concat(contentColumns.filter(col => loadTable?.columns.findIndex(el => el.name === col.name) === -1))
|
|
@@ -96,13 +95,14 @@ export default async function updateContent(req, reply) {
|
|
|
96
95
|
return reply.status(404).send('contents not found');
|
|
97
96
|
}
|
|
98
97
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
98
|
+
// ? deprecated, blocks if only default columns provided, therefore commented for now
|
|
99
|
+
// const contentId = cid === 'pages'
|
|
100
|
+
// ? await pg.query('select content_id from site.content_data where object_id=$1', [id]).then(el => el.rows?.[0]?.content_id)
|
|
101
|
+
// : cid;
|
|
102
102
|
|
|
103
|
-
if (!contentId) {
|
|
104
|
-
|
|
105
|
-
}
|
|
103
|
+
// if (!contentId) {
|
|
104
|
+
// return reply.status(404).send('contents not found: 2');
|
|
105
|
+
// }
|
|
106
106
|
|
|
107
107
|
const columnList = columns?.map?.(el => el.name) || [];
|
|
108
108
|
const types = columns?.reduce?.((acc, curr) => ({ ...acc, [curr.name]: curr.type || 'text' }), {}) || {};
|
|
@@ -133,7 +133,9 @@ export default async function updateContent(req, reply) {
|
|
|
133
133
|
data: { ...body, content_type_id: ctid1 },
|
|
134
134
|
uid: user?.uid,
|
|
135
135
|
});
|
|
136
|
-
|
|
136
|
+
// if (contentId) {
|
|
137
|
+
// await client.query(`delete from site.content_data where content_id=$1`, [contentId]);
|
|
138
|
+
// }
|
|
137
139
|
const objectId = (ctname === 'pages' || ['single', 'pages'].includes(type)) && id ? id : cid;
|
|
138
140
|
await client.query(`delete from site.content_data where object_id=$1`, [objectId]);
|
|
139
141
|
await Promise.all(keys.map(async key => dataInsert({
|
|
@@ -101,6 +101,7 @@ export default async function getSingle({
|
|
|
101
101
|
and ${localeQuery || '1=1'}
|
|
102
102
|
and ${contentQuery || 'true'}
|
|
103
103
|
and ${id ? `$2 in (slug, content_id)` : 'true'}
|
|
104
|
+
and content_id<>'pages'
|
|
104
105
|
order by case when status='archived' then true else false end, published_at desc nulls last
|
|
105
106
|
LIMIT ${limit} OFFSET ${id ? 0 : offset}
|
|
106
107
|
`;
|
|
@@ -120,6 +121,7 @@ export default async function getSingle({
|
|
|
120
121
|
and $1=$1 and $2=$2 and ${contentQuery || 'true'}
|
|
121
122
|
)
|
|
122
123
|
and ${statusQuery || 'true'}
|
|
124
|
+
and content_id<>'pages'
|
|
123
125
|
`, [contentId, id]).then(el => el.rows?.[0] || {});
|
|
124
126
|
|
|
125
127
|
const { rows = [] } = await pg.query(q, [contentId, id || '']);
|