@opengis/cms 0.0.56 → 0.0.58

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 (149) hide show
  1. package/README.md +131 -131
  2. package/dist/AddNewItemInTree-05PSSEFi.js +76 -0
  3. package/dist/ArticlesPage-CFjE_cw_.js +298 -0
  4. package/dist/CollectionsBreadcrumb-BCxeRikP.js +4 -0
  5. package/dist/CollectionsBreadcrumb.vue_vue_type_script_setup_true_lang-umRzB5mY.js +53 -0
  6. package/dist/CollectionsPage-DHfPNql6.js +124 -0
  7. package/dist/{CreateForm-BMOBeP4G.js → CreateForm-5FvT45vH.js} +1 -1
  8. package/dist/Dashboard-C1eGscNd.js +358 -0
  9. package/dist/EditCollectionPage-DIr1tdtn.js +187 -0
  10. package/dist/{EmptyData-DaZt_nAm.js → EmptyData-DxPrSXhV.js} +1 -1
  11. package/dist/{MenuAddPage-Bf48Z-ah.js → MenuAddPage-D-p3gFgm.js} +40 -35
  12. package/dist/MenuBody-rN5j4YBu.js +125 -0
  13. package/dist/MenuItemPage-BoJw885D.js +1027 -0
  14. package/dist/MenuList-DFEBS0NB.js +172 -0
  15. package/dist/MenuPage-BCZB_S8j.js +107 -0
  16. package/dist/MenuWrapper-AZ_8s-zd.js +12 -0
  17. package/dist/MonacoEditor-Db-3Jc3E.js +4 -0
  18. package/dist/{UniversalTable.vue_vue_type_script_setup_true_lang-CJGTsd1V.js → UniversalTable-CzqPG-tY.js} +12 -12
  19. package/dist/{UniversalTablePagination.vue_vue_type_script_setup_true_lang-GYZd_gkA.js → UniversalTablePagination-4gL47A7I.js} +1 -1
  20. package/dist/VsFormTags-CMjiu9sY.js +114 -0
  21. package/dist/VsPreview-DwETkOpb.js +63 -0
  22. package/dist/contentForm-CtMhQTG0.js +489 -0
  23. package/dist/getField-CpwVE28P.js +179 -0
  24. package/dist/index.d.ts +8 -0
  25. package/dist/index.html +29 -29
  26. package/dist/index.js +72 -71
  27. package/dist/style.css +1 -1
  28. package/dist/vs-builder-edit-D-q1o8tF.js +604 -0
  29. package/dist/vs-builder-monaco-B3Jj0V31.js +33 -0
  30. package/dist/vs-builder-preview-BH4VAM3a.js +44 -0
  31. package/dist/vs-form-custom-datatable-BDZo48w3.js +317 -0
  32. package/dist/vs-form-integer-BZ855R3g.js +61 -0
  33. package/dist/vs-form-media-select-NY27EaG1.js +837 -0
  34. package/dist/vs-form-reference-list-Dtv8fJJU.js +1536 -0
  35. package/dist/vs-form-reletion-link-BhzNQszm.js +34 -0
  36. package/dist/vs-form-tiptap-DDFQjRjY.js +4 -0
  37. package/dist/vs-form-tiptap.vue_vue_type_script_setup_true_lang-DGgsqXwg.js +11 -0
  38. package/dist/vs-richtext-md-C098v_6Q.js +4 -0
  39. package/dist/vs-richtext-md.vue_vue_type_script_setup_true_lang-Ct8uTV-J.js +14 -0
  40. package/input-types.json +9 -9
  41. package/locales/en.json +815 -814
  42. package/locales/uk.json +813 -812
  43. package/module/cms/cls/content.status.json +17 -17
  44. package/module/cms/cls/user_type.json +9 -9
  45. package/module/cms/form/admin.users.form.json +77 -77
  46. package/module/cms/select/cms.page_type.sql +1 -1
  47. package/module/cms/select/news_tag_id.sql +11 -11
  48. package/module/cms/table/admin.users.table.json +53 -53
  49. package/module/cms/table/collection.default.table.json +96 -96
  50. package/module/cms/table/single.default.table.json +116 -116
  51. package/package.json +68 -68
  52. package/plugin.js +43 -43
  53. package/server/app.js +35 -35
  54. package/server/config.js +4 -4
  55. package/server/functions/getContent.js +45 -45
  56. package/server/functions/getDraftKey.js +22 -22
  57. package/server/functions/getSearchData.js +31 -31
  58. package/server/functions/getTags.js +30 -30
  59. package/server/functions/getUser.js +27 -27
  60. package/server/functions/utils/mock.reply.js +55 -55
  61. package/server/index.js +22 -22
  62. package/server/migrations/fixes.sql +129 -129
  63. package/server/migrations/site.sql +595 -595
  64. package/server/plugins/adminHook.js +78 -78
  65. package/server/plugins/hook.js +59 -59
  66. package/server/plugins/vite.js +75 -75
  67. package/server/routes/category/controllers/cms.category.delete.js +21 -21
  68. package/server/routes/category/controllers/cms.category.get.js +17 -17
  69. package/server/routes/category/controllers/cms.category.list.js +16 -16
  70. package/server/routes/category/controllers/cms.category.post.js +21 -21
  71. package/server/routes/category/controllers/cms.category.put.js +23 -23
  72. package/server/routes/category/index.mjs +22 -22
  73. package/server/routes/cms/controllers/cmsStat.js +55 -55
  74. package/server/routes/cms/controllers/cmsSuggest.js +57 -57
  75. package/server/routes/cms/controllers/deleteContent.js +113 -113
  76. package/server/routes/cms/controllers/deleteMedia.js +76 -76
  77. package/server/routes/cms/controllers/downloadMedia.js +84 -84
  78. package/server/routes/cms/controllers/getContent.js +113 -113
  79. package/server/routes/cms/controllers/getContentBySlug.js +93 -93
  80. package/server/routes/cms/controllers/insertContent.js +217 -217
  81. package/server/routes/cms/controllers/listMedia.js +155 -155
  82. package/server/routes/cms/controllers/metadataMedia.js +39 -39
  83. package/server/routes/cms/controllers/properties.get.js +18 -18
  84. package/server/routes/cms/controllers/properties.post.js +99 -99
  85. package/server/routes/cms/controllers/searchContent.js +214 -214
  86. package/server/routes/cms/controllers/translate.js +89 -89
  87. package/server/routes/cms/controllers/updateContent.js +266 -264
  88. package/server/routes/cms/controllers/uploadMedia.js +79 -79
  89. package/server/routes/cms/functions/getSettings.js +48 -48
  90. package/server/routes/cms/index.mjs +112 -112
  91. package/server/routes/cms/utils/additionalData.js +35 -35
  92. package/server/routes/cms/utils/getCollection.js +89 -89
  93. package/server/routes/cms/utils/getSingle.js +188 -183
  94. package/server/routes/cms/utils/inputTypes.js +5 -5
  95. package/server/routes/cms/utils/insertContentLocalization.js +104 -104
  96. package/server/routes/cms/utils/requestTranslation.js +85 -85
  97. package/server/routes/cms/utils/updateLocalization.js +47 -47
  98. package/server/routes/cmsSpace/controllers/deleteSpace.js +25 -25
  99. package/server/routes/cmsSpace/controllers/getSpaces.js +27 -27
  100. package/server/routes/cmsSpace/controllers/insertSpace.js +21 -21
  101. package/server/routes/cmsSpace/controllers/updateSpace.js +23 -23
  102. package/server/routes/cmsSpace/index.mjs +20 -20
  103. package/server/routes/contentType/controllers/addContentType.js +160 -160
  104. package/server/routes/contentType/controllers/contentTypeList.js +54 -54
  105. package/server/routes/contentType/controllers/delContentType.js +75 -75
  106. package/server/routes/contentType/controllers/editContentType.js +88 -81
  107. package/server/routes/contentType/controllers/getContentType.js +65 -57
  108. package/server/routes/contentType/index.mjs +35 -35
  109. package/server/routes/contentType/utils/updateContents.js +44 -44
  110. package/server/routes/contentType/utils/updateCustomContentTable.js +53 -53
  111. package/server/routes/feedback/controllers/email.list.js +24 -24
  112. package/server/routes/feedback/controllers/feedback.js +48 -48
  113. package/server/routes/feedback/controllers/feedback.list.js +37 -37
  114. package/server/routes/feedback/controllers/news.subscriptions.js +44 -44
  115. package/server/routes/feedback/index.mjs +71 -71
  116. package/server/routes/logs/controllers/export.user.logs.js +77 -77
  117. package/server/routes/logs/controllers/user.logs.js +44 -44
  118. package/server/routes/logs/index.mjs +9 -9
  119. package/server/routes/menu/controllers/addMenu.js +37 -37
  120. package/server/routes/menu/controllers/delMenu.js +31 -31
  121. package/server/routes/menu/controllers/editMenu.js +41 -41
  122. package/server/routes/menu/controllers/getMenu.js +24 -24
  123. package/server/routes/menu/functions/getMenu.js +50 -50
  124. package/server/routes/menu/index.mjs +13 -13
  125. package/server/routes/migration/controllers/collectionToCustom.js +137 -137
  126. package/server/routes/migration/index.mjs +8 -8
  127. package/server/routes/root.mjs +8 -8
  128. package/server/routes/tags/controllers/add.tags.js +24 -24
  129. package/server/routes/tags/controllers/del.tags.js +19 -19
  130. package/server/routes/tags/controllers/edit.tags.js +25 -25
  131. package/server/routes/tags/controllers/get.tags.js +15 -15
  132. package/server/routes/tags/index.mjs +14 -14
  133. package/server/templates/cls/cms.category_type.json +9 -9
  134. package/server/templates/cls/cms.content_review_status.json +9 -9
  135. package/server/templates/cls/cms.content_status.json +9 -9
  136. package/server/templates/cls/cms.content_type.json +9 -9
  137. package/server/templates/cls/cms.lang.json +9 -9
  138. package/server/templates/page/login.html +126 -126
  139. package/utils.d.ts +52 -52
  140. package/utils.js +8 -8
  141. package/dist/ArticlesPage-BcR1hbds.js +0 -286
  142. package/dist/BuilderPage-CK_osM89.js +0 -386
  143. package/dist/CollectionsBreadcrumb.vue_vue_type_script_setup_true_lang-CnOe9ORD.js +0 -45
  144. package/dist/CollectionsPage-JfmrHNR_.js +0 -110
  145. package/dist/EditCollectionPage-Cw3GQYRe.js +0 -809
  146. package/dist/MenuItemPage-CXn5HC8j.js +0 -1366
  147. package/dist/MenuPage-tJZtK46W.js +0 -106
  148. package/dist/contentForm-B6gHgGkz.js +0 -586
  149. package/dist/getField-Y5WXnRR0.js +0 -2948
@@ -1,22 +1,22 @@
1
- import cmsCategoryGet from './controllers/cms.category.get.js';
2
- import cmsCategoryList from './controllers/cms.category.list.js';
3
- import cmsCategoryPut from './controllers/cms.category.put.js';
4
- import cmsCategoryPost from './controllers/cms.category.post.js';
5
- import cmsCategoryDelete from './controllers/cms.category.delete.js'
6
-
7
- export default async function route(app) {
8
- // category add
9
- app.post('/cms-category', {}, cmsCategoryPost);
10
-
11
- // category edit
12
- app.put('/cms-category/:id', {}, cmsCategoryPut);
13
-
14
- // category list
15
- app.get('/cms-category', { config: { policy: ['site'] }}, cmsCategoryList);
16
-
17
- // category get
18
- app.get('/cms-category/:id', {}, cmsCategoryGet);
19
-
20
- // category delete
21
- app.delete('/cms-category/:id', { config: { policy: ['site'] }}, cmsCategoryDelete);
22
- }
1
+ import cmsCategoryGet from './controllers/cms.category.get.js';
2
+ import cmsCategoryList from './controllers/cms.category.list.js';
3
+ import cmsCategoryPut from './controllers/cms.category.put.js';
4
+ import cmsCategoryPost from './controllers/cms.category.post.js';
5
+ import cmsCategoryDelete from './controllers/cms.category.delete.js'
6
+
7
+ export default async function route(app) {
8
+ // category add
9
+ app.post('/cms-category', {}, cmsCategoryPost);
10
+
11
+ // category edit
12
+ app.put('/cms-category/:id', {}, cmsCategoryPut);
13
+
14
+ // category list
15
+ app.get('/cms-category', { config: { policy: ['site'] }}, cmsCategoryList);
16
+
17
+ // category get
18
+ app.get('/cms-category/:id', {}, cmsCategoryGet);
19
+
20
+ // category delete
21
+ app.delete('/cms-category/:id', { config: { policy: ['site'] }}, cmsCategoryDelete);
22
+ }
@@ -1,56 +1,56 @@
1
- import { metaFormat, pgClients } from '@opengis/fastify-table/utils.js';
2
-
3
- const q = `select
4
- count(distinct object_id) as cdtotal,
5
- count(distinct object_id) filter( where date_trunc('month', created_at) = date_trunc('month', CURRENT_DATE) ) as cdnewcount from site.content_data`;
6
-
7
- const q1 = `select
8
- count(*) as usercount,
9
- count(*) filter( where date_trunc('month', cdate) = date_trunc('month', CURRENT_DATE) ) as usernewcount from admin.users`;
10
-
11
- const q2 = `select
12
- count(*) as mediacount,
13
- count(*) filter( where date_trunc('month', created_at) = date_trunc('month', CURRENT_DATE) ) as medianewcount from site.media`;
14
-
15
- const q3 = `select type, title, updated_at, content_type_id as object_id, slug as content_id from site.contents a
16
- left join lateral (select type from site.content_types where content_type_id=a.content_type_id limit 1)b on 1=1
17
- where 1=1 order by updated_at desc limit 5`;
18
-
19
- export default async function cmsStat({ pg = pgClients.client }, reply) {
20
- if (!pg) {
21
- return reply.status(500).send('empty pg');
22
- }
23
-
24
- const { cdtotal = 0, cdnewcount = 0 } = await pg.query(q).then(el => el.rows?.[0] || {});
25
-
26
- const customTables = await pg.query(`select array_agg(table_name) from site.content_types where type='collection' and table_name is not null`).then(el => el.rows?.[0]?.array_agg || []);
27
-
28
- const custom = await Promise.all(customTables.filter(table => pg?.pk?.[`data.${table}`]).map(async table => {
29
- // await pg.query(`alter table data.${table} add column if not exists created_at timestamp with time zone not null default now()`);
30
- const { total = 0, newcount = 0 } = await pg.queryCache(`select count(*) as total, count(*) filter( where date_trunc('month', created_at) = date_trunc('month', CURRENT_DATE) ) as newcount from data.${table}`, { table: `data.${table}` }).then(el => el.rows?.[0] || {});
31
- return { table, total, newcount };
32
- }));
33
-
34
- const totalContent = custom.reduce((acc, el) => acc + +el.total, +cdtotal);
35
- const newContent = custom.reduce((acc, el) => acc + +el.newcount, +cdnewcount);
36
-
37
- const { usercount = 0, usernewcount = 0 } = await pg.query(q1).then(el => el.rows?.[0] || {});
38
-
39
- const { mediacount = 0, medianewcount = 0 } = await pg.query(q2).then(el => el.rows?.[0] || {});
40
-
41
- const { rows = [] } = await pg.query(q3);
42
-
43
- await metaFormat({ rows, cls: { updated_by: 'core.user_mentioned' }, sufix: false }, pg);
44
-
45
- return {
46
- stat: {
47
- totalContent,
48
- newContent,
49
- totalUsers: +usercount,
50
- newUsers: +usernewcount,
51
- totalMediaFiles: +mediacount,
52
- newMediaFiles: +medianewcount,
53
- },
54
- recentContent: rows,
55
- };
1
+ import { metaFormat, pgClients } from '@opengis/fastify-table/utils.js';
2
+
3
+ const q = `select
4
+ count(distinct object_id) as cdtotal,
5
+ count(distinct object_id) filter( where date_trunc('month', created_at) = date_trunc('month', CURRENT_DATE) ) as cdnewcount from site.content_data`;
6
+
7
+ const q1 = `select
8
+ count(*) as usercount,
9
+ count(*) filter( where date_trunc('month', cdate) = date_trunc('month', CURRENT_DATE) ) as usernewcount from admin.users`;
10
+
11
+ const q2 = `select
12
+ count(*) as mediacount,
13
+ count(*) filter( where date_trunc('month', created_at) = date_trunc('month', CURRENT_DATE) ) as medianewcount from site.media`;
14
+
15
+ const q3 = `select type, title, updated_at, content_type_id as object_id, slug as content_id from site.contents a
16
+ left join lateral (select type from site.content_types where content_type_id=a.content_type_id limit 1)b on 1=1
17
+ where 1=1 order by updated_at desc limit 5`;
18
+
19
+ export default async function cmsStat({ pg = pgClients.client }, reply) {
20
+ if (!pg) {
21
+ return reply.status(500).send('empty pg');
22
+ }
23
+
24
+ const { cdtotal = 0, cdnewcount = 0 } = await pg.query(q).then(el => el.rows?.[0] || {});
25
+
26
+ const customTables = await pg.query(`select array_agg(table_name) from site.content_types where type='collection' and table_name is not null`).then(el => el.rows?.[0]?.array_agg || []);
27
+
28
+ const custom = await Promise.all(customTables.filter(table => pg?.pk?.[`data.${table}`]).map(async table => {
29
+ // await pg.query(`alter table data.${table} add column if not exists created_at timestamp with time zone not null default now()`);
30
+ const { total = 0, newcount = 0 } = await pg.queryCache(`select count(*) as total, count(*) filter( where date_trunc('month', created_at) = date_trunc('month', CURRENT_DATE) ) as newcount from data.${table}`, { table: `data.${table}` }).then(el => el.rows?.[0] || {});
31
+ return { table, total, newcount };
32
+ }));
33
+
34
+ const totalContent = custom.reduce((acc, el) => acc + +el.total, +cdtotal);
35
+ const newContent = custom.reduce((acc, el) => acc + +el.newcount, +cdnewcount);
36
+
37
+ const { usercount = 0, usernewcount = 0 } = await pg.query(q1).then(el => el.rows?.[0] || {});
38
+
39
+ const { mediacount = 0, medianewcount = 0 } = await pg.query(q2).then(el => el.rows?.[0] || {});
40
+
41
+ const { rows = [] } = await pg.query(q3);
42
+
43
+ await metaFormat({ rows, cls: { updated_by: 'core.user_mentioned' }, sufix: false }, pg);
44
+
45
+ return {
46
+ stat: {
47
+ totalContent,
48
+ newContent,
49
+ totalUsers: +usercount,
50
+ newUsers: +usernewcount,
51
+ totalMediaFiles: +mediacount,
52
+ newMediaFiles: +medianewcount,
53
+ },
54
+ recentContent: rows,
55
+ };
56
56
  }
@@ -1,58 +1,58 @@
1
- import { config, pgClients } from '@opengis/fastify-table/utils.js';
2
-
3
- const maxLimit = 50;
4
-
5
- export default async function suggest({ pg = pgClients.client, params = {}, query = {}, user = {} }, reply) {
6
- const t1 = Date.now();
7
-
8
- const { id } = params;
9
- const { key, val } = query;
10
-
11
- if (!pg?.pk) {
12
- return reply.status(500).send('empty pg');
13
- }
14
-
15
- if (!id) {
16
- return reply.status(400).send('not enough params');
17
- }
18
-
19
- const limit = Math.min(query.limit || 16, maxLimit);
20
- const offset = query.page && query.page > 0 ? (query.page - 1) * limit : 0;
21
-
22
- const { ctid, table } = await pg.query(
23
- 'select content_type_id as ctid, table_name as table, columns from site.content_types where $1 in (content_type_id, name)',
24
- [id],
25
- ).then(el => el.rows?.[0] || {});
26
-
27
- if (!ctid) {
28
- return reply.status(404).send('content type not found');
29
- }
30
-
31
- // site.content_data
32
- if (!table) {
33
- const q = `select content_id as id, title as text from site.contents where content_type_id=$1 and ${key ? `lower(title) ~ lower($2)` : (val ? 'content_id=$2' : '1=1')} limit ${limit}`;
34
-
35
- const { rows = [] } = await pg.query(q, [ctid, (key || val)].filter(Boolean));
36
-
37
- return {
38
- time: Date.now() - t1,
39
- limit,
40
- count: rows.length,
41
- mode: 'array',
42
- sql: (config.local || user?.user_type?.includes?.('admin')) ? q : undefined,
43
- data: rows,
44
- };
45
- }
46
-
47
- const q = `select id, title as text from data.${table} where ${key ? `lower(title) ~ lower($1)` : (val ? 'id=$1' : '1=1')} limit ${limit}`;
48
- const { rows = [] } = await pg.query(q, [key || val].filter(Boolean));
49
-
50
- return {
51
- time: Date.now() - t1,
52
- limit,
53
- count: rows.length,
54
- mode: 'array',
55
- sql: (config.local || user?.user_type?.includes?.('admin')) ? q : undefined,
56
- data: rows,
57
- };
1
+ import { config, pgClients } from '@opengis/fastify-table/utils.js';
2
+
3
+ const maxLimit = 50;
4
+
5
+ export default async function suggest({ pg = pgClients.client, params = {}, query = {}, user = {} }, reply) {
6
+ const t1 = Date.now();
7
+
8
+ const { id } = params;
9
+ const { key, val } = query;
10
+
11
+ if (!pg?.pk) {
12
+ return reply.status(500).send('empty pg');
13
+ }
14
+
15
+ if (!id) {
16
+ return reply.status(400).send('not enough params');
17
+ }
18
+
19
+ const limit = Math.min(query.limit || 16, maxLimit);
20
+ const offset = query.page && query.page > 0 ? (query.page - 1) * limit : 0;
21
+
22
+ const { ctid, table } = await pg.query(
23
+ 'select content_type_id as ctid, table_name as table, columns from site.content_types where $1 in (content_type_id, name)',
24
+ [id],
25
+ ).then(el => el.rows?.[0] || {});
26
+
27
+ if (!ctid) {
28
+ return reply.status(404).send('content type not found');
29
+ }
30
+
31
+ // site.content_data
32
+ if (!table) {
33
+ const q = `select content_id as id, title as text from site.contents where content_type_id=$1 and ${key ? `lower(title) ~ lower($2)` : (val ? 'content_id=$2' : '1=1')} limit ${limit}`;
34
+
35
+ const { rows = [] } = await pg.query(q, [ctid, (key || val)].filter(Boolean));
36
+
37
+ return {
38
+ time: Date.now() - t1,
39
+ limit,
40
+ count: rows.length,
41
+ mode: 'array',
42
+ sql: (config.local || user?.user_type?.includes?.('admin')) ? q : undefined,
43
+ data: rows,
44
+ };
45
+ }
46
+
47
+ const q = `select id, title as text from data.${table} where ${key ? `lower(title) ~ lower($1)` : (val ? 'id=$1' : '1=1')} limit ${limit}`;
48
+ const { rows = [] } = await pg.query(q, [key || val].filter(Boolean));
49
+
50
+ return {
51
+ time: Date.now() - t1,
52
+ limit,
53
+ count: rows.length,
54
+ mode: 'array',
55
+ sql: (config.local || user?.user_type?.includes?.('admin')) ? q : undefined,
56
+ data: rows,
57
+ };
58
58
  }
@@ -1,114 +1,114 @@
1
- import { config, pgClients, dataUpdate, dataDelete } from '@opengis/fastify-table/utils.js';
2
-
3
- export default async function deleteContent(req, reply) {
4
- const {
5
- pg = pgClients.client,
6
- params = {},
7
- user = {},
8
- headers = {},
9
- } = req;
10
-
11
- const { type, id } = params;
12
-
13
- if (!type) {
14
- return reply.status(400).send('not enough params: type');
15
- }
16
-
17
- if (!id) {
18
- return reply.status(400).send('not enough params: id');
19
- }
20
-
21
- if (id === 'pages') {
22
- return reply.status(403).send('access restricted: pages contents cannot be deleted');
23
- }
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
-
28
- const arr = config.pg ? await pg.query(`select array_agg(relname)::text[] from pg_class a
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 || []) : [];
31
-
32
- if (!arr.length && type !== 'pages') {
33
- return reply.status(400).send('empty schema: data');
34
- }
35
-
36
- const table = arr.find(el => el === params.type);
37
-
38
- // singletone with extra at site.content_data
39
- if (!table && !dbtable && ctid) {
40
- const { cid, status } = ctid === 'pages' && id
41
- ? await pg.query(
42
- 'select content_id as cid, status from site.contents where content_id=$1 limit 1',
43
- [id]).then(el => el.rows?.[0] || {})
44
- : await pg.query(
45
- 'select content_id as cid, status from site.contents where content_type_id=$1 limit 1',
46
- [ctid],
47
- ).then(el => el.rows?.[0] || {});
48
-
49
- if (!cid) {
50
- return reply.status(404).send('contents not found');
51
- }
52
-
53
- if (cid === 'pages') {
54
- return reply.status(403).send('access restricted: pages contents cannot be deleted');
55
- }
56
-
57
- if (status === 'archived') {
58
- const row = await dataDelete({
59
- pg,
60
- id,
61
- table: 'site.contents',
62
- referer: headers?.referer,
63
- uid: user?.uid || 0,
64
- })
65
- return { id, ...row || {} };
66
- }
67
-
68
- // archived
69
- const row = await dataUpdate({
70
- pg,
71
- id,
72
- table: 'site.contents',
73
- data: {
74
- status: 'archived',
75
- },
76
- referer: headers?.referer,
77
- uid: user?.uid || 0,
78
- })
79
- return { id, ...row || {} };
80
- }
81
-
82
- // custom table
83
- if (!table && !dbtable) {
84
- return reply.status(400).send('invalid params: type');
85
- }
86
-
87
- const status = await pg.query(`select status from data."${(table || dbtable)}" where id =$1`, [id]).then(el => el.rows?.[0]?.status);
88
-
89
- if (status === 'archived') {
90
- const row = await dataDelete({
91
- pg,
92
- id,
93
- table: 'data.' + `"${(table || dbtable)}"`,
94
- referer: headers?.referer,
95
- uid: user?.uid || 0,
96
- })
97
- return { id, ...row || {} };
98
- }
99
-
100
- // archived
101
- const result = await dataUpdate({
102
- pg,
103
- id,
104
- table: 'data.' + `"${(table || dbtable)}"`,
105
- data: {
106
- status: 'archived',
107
- },
108
- referer: headers?.referer,
109
- uid: user?.uid || 0,
110
- });
111
-
112
- const pk = pg.pk?.['data.' + table || dbtable];
113
- return reply.status(200).send({ id: result?.[pk], ...result || {} });
1
+ import { config, pgClients, dataUpdate, dataDelete } from '@opengis/fastify-table/utils.js';
2
+
3
+ export default async function deleteContent(req, reply) {
4
+ const {
5
+ pg = pgClients.client,
6
+ params = {},
7
+ user = {},
8
+ headers = {},
9
+ } = req;
10
+
11
+ const { type, id } = params;
12
+
13
+ if (!type) {
14
+ return reply.status(400).send('not enough params: type');
15
+ }
16
+
17
+ if (!id) {
18
+ return reply.status(400).send('not enough params: id');
19
+ }
20
+
21
+ if (id === 'pages') {
22
+ return reply.status(403).send('access restricted: pages contents cannot be deleted');
23
+ }
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
+
28
+ const arr = config.pg ? await pg.query(`select array_agg(relname)::text[] from pg_class a
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 || []) : [];
31
+
32
+ if (!arr.length && type !== 'pages') {
33
+ return reply.status(400).send('empty schema: data');
34
+ }
35
+
36
+ const table = arr.find(el => el === params.type);
37
+
38
+ // singletone with extra at site.content_data
39
+ if (!table && !dbtable && ctid) {
40
+ const { cid, status } = ctid === 'pages' && id
41
+ ? await pg.query(
42
+ 'select content_id as cid, status from site.contents where content_id=$1 limit 1',
43
+ [id]).then(el => el.rows?.[0] || {})
44
+ : await pg.query(
45
+ 'select content_id as cid, status from site.contents where content_type_id=$1 limit 1',
46
+ [ctid],
47
+ ).then(el => el.rows?.[0] || {});
48
+
49
+ if (!cid) {
50
+ return reply.status(404).send('contents not found');
51
+ }
52
+
53
+ if (cid === 'pages') {
54
+ return reply.status(403).send('access restricted: pages contents cannot be deleted');
55
+ }
56
+
57
+ if (status === 'archived') {
58
+ const row = await dataDelete({
59
+ pg,
60
+ id,
61
+ table: 'site.contents',
62
+ referer: headers?.referer,
63
+ uid: user?.uid || 0,
64
+ })
65
+ return { id, ...row || {} };
66
+ }
67
+
68
+ // archived
69
+ const row = await dataUpdate({
70
+ pg,
71
+ id,
72
+ table: 'site.contents',
73
+ data: {
74
+ status: 'archived',
75
+ },
76
+ referer: headers?.referer,
77
+ uid: user?.uid || 0,
78
+ })
79
+ return { id, ...row || {} };
80
+ }
81
+
82
+ // custom table
83
+ if (!table && !dbtable) {
84
+ return reply.status(400).send('invalid params: type');
85
+ }
86
+
87
+ const status = await pg.query(`select status from data."${(table || dbtable)}" where id =$1`, [id]).then(el => el.rows?.[0]?.status);
88
+
89
+ if (status === 'archived') {
90
+ const row = await dataDelete({
91
+ pg,
92
+ id,
93
+ table: 'data.' + `"${(table || dbtable)}"`,
94
+ referer: headers?.referer,
95
+ uid: user?.uid || 0,
96
+ })
97
+ return { id, ...row || {} };
98
+ }
99
+
100
+ // archived
101
+ const result = await dataUpdate({
102
+ pg,
103
+ id,
104
+ table: 'data.' + `"${(table || dbtable)}"`,
105
+ data: {
106
+ status: 'archived',
107
+ },
108
+ referer: headers?.referer,
109
+ uid: user?.uid || 0,
110
+ });
111
+
112
+ const pk = pg.pk?.['data.' + table || dbtable];
113
+ return reply.status(200).send({ id: result?.[pk], ...result || {} });
114
114
  }
@@ -1,77 +1,77 @@
1
- import path from 'node:path';
2
- import { existsSync } from 'node:fs';
3
- import { rm, stat, readdir } from 'node:fs/promises';
4
-
5
- import { config, dataDelete, getFolder, pgClients } from "@opengis/fastify-table/utils.js";
6
-
7
- // path.resolve() converts POSIX paths from getFolder to valid Windows paths (Bun/Node fs require this on Windows)
8
- const rootDir = path.resolve(getFolder(config, 'local'));
9
- const dir = '/files';
10
-
11
- export default async function deleteMedia({
12
- pg = pgClients.client, params = {}, query = {}, user = {}, method = 'DELETE',
13
- }, reply) {
14
- if (!config.debug && method !== 'DELETE') {
15
- return reply.status(403).send('access restricted');
16
- }
17
-
18
- if (!params.id && query.subdir) {
19
- const dirpath = path.join(rootDir, dir, query.subdir || '');
20
- const exists = existsSync(dirpath);
21
- const stats = await stat(dirpath);
22
-
23
- if (!stats.isDirectory()) {
24
- return reply.status(400).send('not a directory');
25
- }
26
-
27
- if (!exists) {
28
- return reply.status(404).send('subdir not found: ' + query.subdir);
29
- }
30
-
31
- const content = await readdir(dirpath, { recursive: true });
32
-
33
- if (query.subdir.startsWith('uploads') && !query.subdir.split('/')[1]) {
34
- return reply.status(403).send('access restricted: uploads directory');
35
- }
36
-
37
- // only admins are allowed to delete non-empty directories
38
- if (content?.length && !user?.user_type?.includes?.('admin')) {
39
- return reply.status(400).send('directory is not empty');
40
- }
41
-
42
- await rm(dirpath, { recursive: true });
43
- return reply.status(200).send('subdirectory successfully deleted');
44
- }
45
-
46
- if (!params?.id) {
47
- return reply.status(400).send('not enough params: id');
48
- }
49
-
50
- if (!pg.pk?.['site.media']) {
51
- return reply.status(404).send('table not found');
52
- }
53
-
54
- const { url: relpath, id } = await pg.query(
55
- 'select media_id as id, url from site.media where media_id = $1 and url is not null',
56
- [params.id],
57
- ).then(el => el.rows?.[0] || {});
58
-
59
- if (!id) {
60
- return reply.status(404).send('media not found: ' + params.id);
61
- }
62
-
63
- const res = await dataDelete({
64
- pg,
65
- id,
66
- table: 'site.media',
67
- uid: user?.uid || 0,
68
- });
69
-
70
- const filepath = path.join(rootDir, relpath);
71
-
72
- if (existsSync(filepath)) {
73
- await rm(filepath, { recursive: true });
74
- }
75
-
76
- return { id, ...res || {} };
1
+ import path from 'node:path';
2
+ import { existsSync } from 'node:fs';
3
+ import { rm, stat, readdir } from 'node:fs/promises';
4
+
5
+ import { config, dataDelete, getFolder, pgClients } from "@opengis/fastify-table/utils.js";
6
+
7
+ // path.resolve() converts POSIX paths from getFolder to valid Windows paths (Bun/Node fs require this on Windows)
8
+ const rootDir = path.resolve(getFolder(config, 'local'));
9
+ const dir = '/files';
10
+
11
+ export default async function deleteMedia({
12
+ pg = pgClients.client, params = {}, query = {}, user = {}, method = 'DELETE',
13
+ }, reply) {
14
+ if (!config.debug && method !== 'DELETE') {
15
+ return reply.status(403).send('access restricted');
16
+ }
17
+
18
+ if (!params.id && query.subdir) {
19
+ const dirpath = path.join(rootDir, dir, query.subdir || '');
20
+ const exists = existsSync(dirpath);
21
+ const stats = await stat(dirpath);
22
+
23
+ if (!stats.isDirectory()) {
24
+ return reply.status(400).send('not a directory');
25
+ }
26
+
27
+ if (!exists) {
28
+ return reply.status(404).send('subdir not found: ' + query.subdir);
29
+ }
30
+
31
+ const content = await readdir(dirpath, { recursive: true });
32
+
33
+ if (query.subdir.startsWith('uploads') && !query.subdir.split('/')[1]) {
34
+ return reply.status(403).send('access restricted: uploads directory');
35
+ }
36
+
37
+ // only admins are allowed to delete non-empty directories
38
+ if (content?.length && !user?.user_type?.includes?.('admin')) {
39
+ return reply.status(400).send('directory is not empty');
40
+ }
41
+
42
+ await rm(dirpath, { recursive: true });
43
+ return reply.status(200).send('subdirectory successfully deleted');
44
+ }
45
+
46
+ if (!params?.id) {
47
+ return reply.status(400).send('not enough params: id');
48
+ }
49
+
50
+ if (!pg.pk?.['site.media']) {
51
+ return reply.status(404).send('table not found');
52
+ }
53
+
54
+ const { url: relpath, id } = await pg.query(
55
+ 'select media_id as id, url from site.media where media_id = $1 and url is not null',
56
+ [params.id],
57
+ ).then(el => el.rows?.[0] || {});
58
+
59
+ if (!id) {
60
+ return reply.status(404).send('media not found: ' + params.id);
61
+ }
62
+
63
+ const res = await dataDelete({
64
+ pg,
65
+ id,
66
+ table: 'site.media',
67
+ uid: user?.uid || 0,
68
+ });
69
+
70
+ const filepath = path.join(rootDir, relpath);
71
+
72
+ if (existsSync(filepath)) {
73
+ await rm(filepath, { recursive: true });
74
+ }
75
+
76
+ return { id, ...res || {} };
77
77
  }