@opengis/fastify-table 1.4.39 → 1.4.41

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/fastify-table",
3
- "version": "1.4.39",
3
+ "version": "1.4.41",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [
@@ -24,11 +24,11 @@ export default async function dataDelete({
24
24
  pg.pk = pgClients.client?.pk;
25
25
  }
26
26
 
27
- const table = table1.replace(/"/g, '');
27
+ const table = pg.pk[table1] ? table1 : table1.replace(/"/g, '');
28
28
 
29
29
  const { pk } = await getMeta({ pg, table });
30
30
 
31
- if (!pg.tlist?.includes(table1)) return 'table not exist';
31
+ if (!pg.tlist?.includes(table)) return 'table not exist';
32
32
 
33
33
  const delQuery = `delete from ${table} WHERE ${pk}::text = $1::text returning *`;
34
34
 
@@ -60,7 +60,7 @@ export default async function dataInsert({
60
60
  }
61
61
  const res = await client.query(insertQuery, args).then(el => el || {});
62
62
 
63
- const id1 = res.rows?.[0]?.[pg.pk[table1]];
63
+ const id1 = res.rows?.[0]?.[pg.pk[table]];
64
64
 
65
65
  if (!id1) return null;
66
66
 
@@ -60,7 +60,7 @@ export default async function uploadMultiPart(req, { subdir, originalFilename =
60
60
 
61
61
  const value = part?.fields?.file || part;
62
62
 
63
- if (!value?.file || !value?.filename) {
63
+ if (!value?.file?.on || !value?.filename) {
64
64
  throw new Error('upload error');
65
65
  }
66
66
 
@@ -73,9 +73,9 @@ export default async function uploadMultiPart(req, { subdir, originalFilename =
73
73
 
74
74
  const buffer = await new Promise((res, rej) => {
75
75
  const chunks = [];
76
- part.file.on('data', chunk => chunks.push(chunk));
77
- part.file.on('end', () => res(Buffer.concat(chunks)));
78
- part.file.on('error', rej);
76
+ value.file.on('data', chunk => chunks.push(chunk));
77
+ value.file.on('end', () => res(Buffer.concat(chunks)));
78
+ value.file.on('error', rej);
79
79
  });
80
80
 
81
81
  if (!buffer?.length) {
@@ -6,11 +6,12 @@ const data = {};
6
6
  export default async function getMeta(opt, nocache) {
7
7
  const pg = opt?.pg || getPG({ name: 'client' });
8
8
  if (!pg) return { error: 'pg connection not established', status: 400 };
9
- const table = opt?.table || opt;
9
+ const table1 = opt?.table || opt;
10
+ const table = pg.pk[table1] ? table1 : table1?.replace?.(/"/g, '');
10
11
 
11
12
  if (pg?.options?.database && data[pg.options.database]?.[table] && !nocache) return data[pg.options.database][table];
12
13
 
13
- if (!pg?.tlist?.includes(table?.replace?.(/"/g, ''))) {
14
+ if (!pg?.tlist?.includes(table)) {
14
15
  return { error: `${table} - not found`, status: 400 };
15
16
  }
16
17
 
@@ -21,8 +22,8 @@ export default async function getMeta(opt, nocache) {
21
22
  WHERE c.contype='p'::"char" and c.conrelid::regclass = $1::regclass`, [table]).then(el => el.rows[0].pks1 || {});
22
23
 
23
24
  const pk = table.startsWith('public.')
24
- ? (pks1[table.replace('public.', '')] || pks1[table.replace('public.', '').replace(/"/g, '')])
25
- : (pks1[table] || pks1[table.replace(/"/g, '')]);
25
+ ? (pks1[table.replace('public.', '')] || pks1[table.replace('public.', '')])
26
+ : (pks1[table] || pks1[table]);
26
27
 
27
28
  const geomAttr = fields.find((el) => pg.pgType?.[el.dataTypeID] === 'geometry')?.name; // change geometry text to geometry code
28
29
 
@@ -27,6 +27,10 @@ export default async function resize({ query = {}, unittest }, reply) {
27
27
  filepath, quality, size, w, h, nocache, maxWidth = 400,
28
28
  } = query;
29
29
 
30
+ if (!filepath) {
31
+ return reply.status(400).send('not enough query params: filepath');
32
+ }
33
+
30
34
  const basename = path.basename(filepath);
31
35
  const mimeType = getMimeType(filepath);
32
36
  const resizePath1 = size