@opengis/fastify-table 1.4.35 → 1.4.37
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/config.js +3 -2
- package/package.json +1 -1
- package/server/plugins/file/uploadMultiPart.js +12 -4
- package/server/plugins/table/funcs/getData.js +2 -2
- package/server/plugins/util/funcs/unflattenObject.js +1 -1
- package/server/routes/crud/controllers/update.js +5 -0
- package/server/routes/file/controllers/upload.js +0 -1
- package/server/routes/table/functions/getData.js +3 -1
package/config.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import dotenv from 'dotenv';
|
|
1
|
+
// import dotenv from 'dotenv';
|
|
2
2
|
|
|
3
3
|
import { existsSync, readFileSync } from 'node:fs';
|
|
4
4
|
|
|
@@ -20,7 +20,8 @@ Object.assign(config, {
|
|
|
20
20
|
|
|
21
21
|
function loadEnvConfig() {
|
|
22
22
|
// node --env-file-if-exists=.env.dev --env-file-if-exists=.env server
|
|
23
|
-
|
|
23
|
+
if (config.trace) { console.log(Object.keys(process.env)); }
|
|
24
|
+
const configKeys = Object.keys(process.env).filter(key => !key.startsWith('npm_') && !skipKeys.includes(key) && (key.charAt(0) === key.charAt(0)?.toLowerCase?.() || key.includes('.'))).reduce((acc, curr) => ({ ...acc, [curr]: process.env[curr] }), {});
|
|
24
25
|
Object.assign(config, unflattenObject(configKeys));
|
|
25
26
|
}
|
|
26
27
|
|
package/package.json
CHANGED
|
@@ -3,6 +3,7 @@ import { mkdir, writeFile } from 'node:fs/promises';
|
|
|
3
3
|
import { randomUUID } from 'node:crypto';
|
|
4
4
|
import { imageSize } from 'image-size';
|
|
5
5
|
|
|
6
|
+
import { existsSync } from 'node:fs';
|
|
6
7
|
import config from '../../../config.js';
|
|
7
8
|
|
|
8
9
|
import providers from './providers/index.js';
|
|
@@ -10,6 +11,7 @@ import providers from './providers/index.js';
|
|
|
10
11
|
import { all, images } from './utils/allowedExtensions.js';
|
|
11
12
|
|
|
12
13
|
import grpc from '../grpc/grpc.js';
|
|
14
|
+
import getFileType from './utils/getFileType.js';
|
|
13
15
|
|
|
14
16
|
const { resizeImage } = grpc();
|
|
15
17
|
|
|
@@ -43,7 +45,7 @@ async function writeFileToDisk(file, buffer) {
|
|
|
43
45
|
return null;
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
export default async function uploadMultiPart(req) {
|
|
48
|
+
export default async function uploadMultiPart(req, { subdir = 'uploads', originalFilename = false } = {}) {
|
|
47
49
|
const allowedExtensions = {
|
|
48
50
|
'/file/upload-image/*': images,
|
|
49
51
|
}[req.routeOptions?.url || ''] || all;
|
|
@@ -70,8 +72,8 @@ export default async function uploadMultiPart(req) {
|
|
|
70
72
|
throw new Error('file buffer is empty');
|
|
71
73
|
}
|
|
72
74
|
|
|
73
|
-
const dir = req.params?.['*'] ||
|
|
74
|
-
const yearMonthDay = (new Date()).toISOString().split('T')[0];
|
|
75
|
+
const dir = req.params?.['*'] || subdir;
|
|
76
|
+
const yearMonthDay = subdir != null ? '' : (new Date()).toISOString().split('T')[0];
|
|
75
77
|
|
|
76
78
|
const dbname = req.pg?.options?.database || req.pg?.database || config.pg?.database; // request / config params / default config params
|
|
77
79
|
|
|
@@ -79,11 +81,17 @@ export default async function uploadMultiPart(req) {
|
|
|
79
81
|
const reldirpath = path.join('/files', dir, yearMonthDay);
|
|
80
82
|
const folder = path.join(rootDir, config.folder || '', reldirpath);
|
|
81
83
|
|
|
82
|
-
const newFilename = `${randomUUID()}${ext}`;
|
|
84
|
+
const newFilename = originalFilename ? value.filename : `${randomUUID()}${ext}`;
|
|
85
|
+
|
|
86
|
+
if (existsSync(path.join(folder, newFilename).replace(/\\/g, '/'))) {
|
|
87
|
+
throw new Error('file with specified name already exists in directory');
|
|
88
|
+
}
|
|
83
89
|
|
|
84
90
|
const file = {
|
|
85
91
|
originalFilename: value.filename,
|
|
92
|
+
newFilename,
|
|
86
93
|
filepath: path.join(folder, newFilename).replace(/\\/g, '/'),
|
|
94
|
+
filetype: getFileType(newFilename),
|
|
87
95
|
relativeFilepath: path.join(reldirpath, newFilename).replace(/\\/g, '/'),
|
|
88
96
|
size: Buffer.byteLength(buffer),
|
|
89
97
|
mimetype: value.mimetype,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import routeData from '../../../routes/table/controllers/tableData.js';
|
|
2
2
|
|
|
3
3
|
export default async function getData({
|
|
4
|
-
id, table, pg, headers, filter, state, limit, page, search, user, order, sql, contextQuery, sufix,
|
|
4
|
+
id, table, pg, headers, filter, state, limit, page, search, user, order, desc, sql, contextQuery, sufix,
|
|
5
5
|
}, reply, called) {
|
|
6
6
|
const params = { table, id };
|
|
7
7
|
const query = {
|
|
8
|
-
filter, limit, page, search, sql, state, order,
|
|
8
|
+
filter, limit, page, search, sql, state, order, desc,
|
|
9
9
|
};
|
|
10
10
|
const result = await routeData({
|
|
11
11
|
pg, headers, params, query, user, contextQuery, sufix,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable no-param-reassign */
|
|
2
2
|
export default function unflattenObject(flatObj) {
|
|
3
|
-
return Object.keys(flatObj).reduce((acc, key) => {
|
|
3
|
+
return Object.keys(flatObj || {}).reduce((acc, key) => {
|
|
4
4
|
const keys = key.split('.');
|
|
5
5
|
keys.reduce((nestedObj, part, index) => {
|
|
6
6
|
if (index === keys.length - 1) {
|
|
@@ -65,6 +65,11 @@ export default async function update(req, reply) {
|
|
|
65
65
|
Object.keys(body || {}).filter(key => !Object.keys(schema || {}).includes(key)).forEach(key => delete body[key]);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
if (tokenData?.obj) {
|
|
69
|
+
const objData = tokenData.obj?.split('#').reduce((p, el) => ({ ...p, [el.split('=')[0]]: el.split('=')[1] }), {}) || {};
|
|
70
|
+
Object.assign(body, objData);
|
|
71
|
+
}
|
|
72
|
+
|
|
68
73
|
const xssCheck = checkXSS({ body, schema });
|
|
69
74
|
|
|
70
75
|
if (xssCheck.error && formData?.xssCheck !== false) {
|
|
@@ -46,7 +46,6 @@ export default async function upload(req) {
|
|
|
46
46
|
file_name: file?.originalFilename.toLocaleLowerCase(),
|
|
47
47
|
dir: relativeDirpath?.replace(/\\/g, '/'),
|
|
48
48
|
native_file_name: fileName,
|
|
49
|
-
original: file?.relativeOriginalFilepath?.replace?.(/\\/g, '/'),
|
|
50
49
|
},
|
|
51
50
|
},
|
|
52
51
|
};
|
|
@@ -73,7 +73,9 @@ export default async function dataAPI(req, reply, called) {
|
|
|
73
73
|
|
|
74
74
|
if (!config.pg) { return reply.status(500).send('empty pg'); }
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
const pkey = pg.pk?.[params?.table] || pg.pk?.[params?.table.replace(/"/g, '')];
|
|
77
|
+
|
|
78
|
+
if (!loadTable && !(tokenData?.table && pg.pk?.[tokenData?.table]) && !(called && pkey)) {
|
|
77
79
|
return reply.status(404).send('template not found');
|
|
78
80
|
}
|
|
79
81
|
|