@opengis/cms 0.0.49 → 0.0.51

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.49",
3
+ "version": "0.0.51",
4
4
  "description": "cms",
5
5
  "type": "module",
6
6
  "author": "Softpro",
@@ -8,6 +8,7 @@
8
8
  "license": "EULA",
9
9
  "files": [
10
10
  "module",
11
+ "locales",
11
12
  "dist",
12
13
  "server",
13
14
  "plugin.js",
@@ -40,7 +41,7 @@
40
41
  "devDependencies": {
41
42
  "@fastify/compress": "^8.1.0",
42
43
  "@opengis/core": "^0.0.30",
43
- "@opengis/fastify-table": "^2.0.137",
44
+ "@opengis/fastify-table": "^2.0.138",
44
45
  "@opengis/filter": "^0.1.31",
45
46
  "@opengis/form": "^0.0.109",
46
47
  "@opengis/richtext": "0.0.38",
@@ -23,7 +23,7 @@ export default async function getSearchData({ page = 1, limit = 12, ttl = 3600,
23
23
  // check if any crud operations performed, if not - return cached response
24
24
  const crudInc = await rclient.get(`pg:site.contents:crud`) || 0;
25
25
 
26
- const cacheKey = createHash('md5').update([config.pg?.database, 'cms:search', crudInc, page, limit, ttl, locale, tags, filter, contentType, asc].join(':')).digest('hex');
26
+ const cacheKey = createHash('md5').update([config.pg?.database, 'cms:search', crudInc, page, limit, search, locale, tags, filter, contentType, asc].join(':')).digest('hex');
27
27
  const cacheData = ttl === 0 ? null : JSON.parse(await rclient.get(cacheKey));
28
28
 
29
29
  // return from cache
@@ -2,9 +2,22 @@ import path from 'node:path';
2
2
  import { existsSync, mkdirSync } from 'node:fs';
3
3
  import { readdir, stat } from 'node:fs/promises';
4
4
 
5
- import { config, getFolder, pgClients, getMimeType } from '@opengis/fastify-table/utils.js';
5
+ import { config, getFolder, pgClients, getMimeType, getFilterSQL } from '@opengis/fastify-table/utils.js';
6
6
  import { createHash } from 'node:crypto';
7
7
 
8
+ const filterList = [
9
+ {
10
+ name: "created_at",
11
+ type: "Date",
12
+ ua: "Дата створення"
13
+ },
14
+ {
15
+ name: "updated_at",
16
+ type: "Date",
17
+ ua: "Дата редагування"
18
+ }
19
+ ]
20
+
8
21
  // path.resolve() converts POSIX paths from getFolder to valid Windows paths (Bun/Node fs require this on Windows)
9
22
  const rootDir = path.resolve(getFolder(config, 'local'));
10
23
  const dir = '/files';
@@ -39,12 +52,15 @@ export default async function listMedia(req, reply) {
39
52
  const allItems = isDirectory ? await readdir(dirpath, { withFileTypes: true, recursive: true }) : [];
40
53
  const items = isDirectory ? await readdir(dirpath, { withFileTypes: true }) : [];
41
54
 
55
+ const { q = '' } = await getFilterSQL({ table: 'site.media', filter: query?.filter, filterList, pg });
56
+
42
57
  const rows = await pg.query(
43
58
  `select
44
59
  media_id as id, filename, filetype, filesize, url, description, alt,
45
60
  mime, preview_url, created_at, updated_at, created_by, updated_by
46
61
  from site.media
47
- where ${subdir ? 'subdir = $1' : (search ? '1=1' : 'subdir is null')} ${search ? `and filename ilike '%${search.replace(/'/g, "''")}%'` : ''}`,
62
+ where ${subdir ? 'subdir = $1' : (search ? '1=1' : 'subdir is null')} ${search ? `and filename ilike '%${search.replace(/'/g, "''")}%'` : ''}
63
+ ${q ? ` and (${q})` : ''}`,
48
64
  [subdir].filter(Boolean),
49
65
  ).then(el => el.rows || []); // ?.filter(row => items.map(el => el.name).includes(row.filename))
50
66
 
@@ -1,4 +1,6 @@
1
- import { config, pgClients, getFilterSQL } from '@opengis/fastify-table/utils.js';
1
+ import { pgClients, getFilterSQL } from '@opengis/fastify-table/utils.js';
2
+
3
+ import additionalData from '../utils/additionalData.js';
2
4
 
3
5
  const filterList = [
4
6
  {
@@ -55,11 +57,12 @@ export default async function searchContent({
55
57
  const limit = Math.min(query.limit || 16, maxLimit);
56
58
  const offset = (page - 1) * limit;
57
59
 
58
- const { q } = filter ? await getFilterSQL({
60
+ const { q } = filter || search ? await getFilterSQL({
59
61
  pg,
60
62
  table: 'site.contents',
61
63
  filter,
62
64
  search,
65
+ searchColumn: 'a.slug,a.title',
63
66
  query: `status='published'`,
64
67
  filterList,
65
68
  }) : { q: `status='published'` };
@@ -121,10 +124,12 @@ export default async function searchContent({
121
124
  }[!!asc];
122
125
 
123
126
  const { optimizedSQL = `SELECT * FROM data."${table}" where status='published' ORDER BY ${order}` } =
124
- filter ? await getFilterSQL({
127
+ filter || search ? await getFilterSQL({
125
128
  pg,
126
129
  table: `data."${table}"`,
127
130
  filter,
131
+ search,
132
+ searchColumn: 'slug,title',
128
133
  query: `status='published'`,
129
134
  filterList: collectionFilters,
130
135
  order: 'published_at DESC NULLS LAST'
@@ -141,6 +146,8 @@ export default async function searchContent({
141
146
  return { rows: [], /*total: total // totals[`data.${table}`] || totals[`data."${table}"`] || 0*/ };
142
147
  });
143
148
 
149
+ // await additionalData(pg, items, locale);
150
+
144
151
  return {
145
152
  rows: items.map(el => ({
146
153
  ...row,
@@ -22,7 +22,7 @@ export default async function additionalData(pg, rows, locale, fields = '*') {
22
22
  const localization = localizations.find(el => el.object_id === row.id);
23
23
  const localizationKeys = Object.keys(localization?.json_object_agg || {}).filter(key => row[key.split(':').shift()]);
24
24
  const localizationObj1 = Object.entries(localization?.json_object_agg || {}).filter(([key]) => rows.length > 1 ? true : localizationKeys.includes(key)).reduce((acc, curr) => ({ ...acc, [curr[0]]: typeof curr[1] === 'string' && curr[1].startsWith('[') && curr[1].endsWith(']') ? JSON.parse(curr[1]) : curr[1] }), {});
25
- const localizationObj = fields?.length ? Object.fromEntries(Object.entries(localizationObj1).filter(([key]) => fields.split(',').includes(key.split(':').shift()))) : localizationObj1;
25
+ const localizationObj = fields?.length && fields !== '*' ? Object.fromEntries(Object.entries(localizationObj1).filter(([key]) => fields.split(',').includes(key.split(':').shift()))) : localizationObj1;
26
26
  if (locale && locale !== 'uk') {
27
27
  Object.assign(row, Object.keys(localizationObj).reduce((acc, curr) => ({ ...acc, [curr.replace(`:${locale}`, '')]: localizationObj[curr] }), {}));
28
28
  } else if (!locale) {