@opengis/fastify-table 1.4.8 → 1.4.9
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 +1 -0
- package/index.js +5 -0
- package/package.json +8 -2
- package/server/plugins/file/downloadFile.js +18 -0
- package/server/plugins/file/getExport.js +38 -0
- package/server/plugins/file/isFileExists.js +17 -0
- package/server/plugins/file/providers/fs.js +100 -0
- package/server/plugins/file/providers/index.d.ts +49 -0
- package/server/plugins/file/providers/index.js +37 -0
- package/server/plugins/file/providers/mime/index.js +12 -0
- package/server/plugins/file/providers/mime/mimes.js +1180 -0
- package/server/plugins/file/providers/s3/client.js +41 -0
- package/server/plugins/file/providers/s3/funcs/downloadFile.js +50 -0
- package/server/plugins/file/providers/s3/funcs/fileExists.js +32 -0
- package/server/plugins/file/providers/s3/funcs/uploadFile.js +38 -0
- package/server/plugins/file/providers/s3/funcs/utils/getS3FilePath.js +23 -0
- package/server/plugins/file/providers/s3/index.js +12 -0
- package/server/plugins/file/providers/utils/getDataSize.js +20 -0
- package/server/plugins/file/providers/utils/getValidData.js +32 -0
- package/server/plugins/file/providers/utils/handlers/dataTypes.js +8 -0
- package/server/plugins/file/providers/utils/handlers/index.js +53 -0
- package/server/plugins/file/providers/utils/handlers/sizeHandlers.js +11 -0
- package/server/plugins/file/providers/utils/streamToBuffer.js +8 -0
- package/server/plugins/file/providers/utils/typeguards/isArray.js +3 -0
- package/server/plugins/file/providers/utils/typeguards/isBuffer.js +3 -0
- package/server/plugins/file/providers/utils/typeguards/isPath.js +5 -0
- package/server/plugins/file/providers/utils/typeguards/isReadableStream.js +8 -0
- package/server/plugins/file/providers/utils/typeguards/isText.js +3 -0
- package/server/plugins/file/uploadFile.js +19 -0
- package/server/plugins/file/uploadMultiPart.js +63 -0
- package/server/plugins/file/utils/allowedExtensions.js +25 -0
- package/server/plugins/file/utils/getFileType.js +10 -0
- package/server/plugins/file/utils/getPath.js +25 -0
- package/server/plugins/file/utils/isFileExists.js +15 -0
- package/server/plugins/file/utils/uploadFileDisk.js +87 -0
- package/server/plugins/grpc/file2json.js +54 -0
- package/server/plugins/grpc/grpc.js +295 -0
- package/server/plugins/grpc/office2pdf.js +68 -0
- package/server/plugins/grpc/utils/convertp.proto +137 -0
- package/server/plugins/grpc/utils/csv2xls.js +8 -0
- package/server/plugins/grpc/utils/excel2Json.js +8 -0
- package/server/plugins/grpc/utils/html2doc.js +19 -0
- package/server/plugins/grpc/utils/html2img.js +18 -0
- package/server/plugins/grpc/utils/html2pdf.js +23 -0
- package/server/plugins/grpc/utils/htmlTemplate.js +14 -0
- package/server/plugins/grpc/utils/json2xls.js +13 -0
- package/server/plugins/grpc/utils/mergePdf.js +20 -0
- package/server/plugins/grpc/utils/office2pdf.proto +14 -0
- package/server/routes/file/controllers/delete.js +108 -0
- package/server/routes/file/controllers/download.js +66 -0
- package/server/routes/file/controllers/export.js +283 -0
- package/server/routes/file/controllers/files.js +72 -0
- package/server/routes/file/controllers/resize.js +90 -0
- package/server/routes/file/controllers/resizeAll.js +164 -0
- package/server/routes/file/controllers/upload.js +53 -0
- package/server/routes/file/controllers/uploadImage.js +47 -0
- package/server/routes/file/controllers/utils/convertJSONToCSV.js +36 -0
- package/server/routes/file/controllers/utils/convertJSONToXls.js +44 -0
- package/server/routes/file/controllers/utils/formatResult.js +17 -0
- package/server/routes/file/index.mjs +26 -0
- package/server/routes/file/schema.js +16 -0
- package/server/routes/grpc/controllers/file2geojson.js +60 -0
- package/server/routes/grpc/controllers/filePreview.js +89 -0
- package/server/routes/grpc/index.mjs +12 -0
- package/server/routes/table/controllers/tableData.js +2 -2
- package/server/routes/table/functions/getData.js +16 -10
- package/utils.js +30 -2
package/config.js
CHANGED
|
@@ -10,6 +10,7 @@ const config = fileName ? JSON.parse(readFileSync(fileName)) : {};
|
|
|
10
10
|
// npm run dev === cross-env NODE_ENV=development
|
|
11
11
|
// alt: node --env=development
|
|
12
12
|
Object.assign(config, {
|
|
13
|
+
storageList: {},
|
|
13
14
|
allTemplates: config?.allTemplates || {},
|
|
14
15
|
skipCheckPolicyRoutes: [],
|
|
15
16
|
env: process.env?.NODE_ENV || process.argv[2]?.split?.('=')?.pop?.(),
|
package/index.js
CHANGED
|
@@ -112,6 +112,11 @@ async function plugin(fastify, opt) {
|
|
|
112
112
|
menuRoutes(fastify, opt);
|
|
113
113
|
templatesRoutes(fastify, opt);
|
|
114
114
|
|
|
115
|
+
// from fastify-file
|
|
116
|
+
fastify.register(import('./server/routes/file/index.mjs'), opt);
|
|
117
|
+
fastify.register(import('./server/routes/grpc/index.mjs'), opt);
|
|
118
|
+
await fastify.register(import('@fastify/multipart')); // file upload
|
|
119
|
+
|
|
115
120
|
fastify.get('/api/test-proxy', {}, (req) => ({ ...req.headers || {}, sessionId: req.session?.sessionId }));
|
|
116
121
|
fastify.get('/api/config', { config: { policy: ['admin', 'site'] } }, () => config);
|
|
117
122
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengis/fastify-table",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "core-plugins",
|
|
6
6
|
"keywords": [
|
|
@@ -42,7 +42,13 @@
|
|
|
42
42
|
"pino-abstract-transport": "2.0.0",
|
|
43
43
|
"promised-handlebars": "2.0.1",
|
|
44
44
|
"qrcode": "1.5.4",
|
|
45
|
-
"uglify-js": "3.19.3"
|
|
45
|
+
"uglify-js": "3.19.3",
|
|
46
|
+
"@aws-sdk/client-s3": "3.554.0",
|
|
47
|
+
"@fastify/multipart": "9.0.3",
|
|
48
|
+
"@grpc/grpc-js": "1.10.6",
|
|
49
|
+
"@grpc/proto-loader": "0.7.12",
|
|
50
|
+
"formidable": "3.5.1",
|
|
51
|
+
"image-size": "1.2.0"
|
|
46
52
|
},
|
|
47
53
|
"devDependencies": {
|
|
48
54
|
"cross-env": "7.0.3",
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import providers from './providers/index.js';
|
|
3
|
+
|
|
4
|
+
async function downloadFile(filePath, options = {}) {
|
|
5
|
+
if (!filePath) return null;
|
|
6
|
+
const filename = path.basename(filePath);
|
|
7
|
+
|
|
8
|
+
// prefix
|
|
9
|
+
const prefix = (options.prefix === 'date' ? new Date().toISOString().split('T')[0] : null)
|
|
10
|
+
|| (options.prefix === '3s' ? filename.substring(0, 3) : '');
|
|
11
|
+
|
|
12
|
+
const relativePath = path.join(path.dirname(filePath), prefix, filename);
|
|
13
|
+
|
|
14
|
+
const fp = providers(options);
|
|
15
|
+
return fp.downloadFile(relativePath, options);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default downloadFile;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import routeExport from '../../routes/file/controllers/export.js';
|
|
2
|
+
|
|
3
|
+
export default async function getExport({
|
|
4
|
+
pg,
|
|
5
|
+
user,
|
|
6
|
+
host,
|
|
7
|
+
unittest,
|
|
8
|
+
columns,
|
|
9
|
+
cls,
|
|
10
|
+
id,
|
|
11
|
+
cols,
|
|
12
|
+
search,
|
|
13
|
+
format,
|
|
14
|
+
table,
|
|
15
|
+
tableSql,
|
|
16
|
+
sourceName,
|
|
17
|
+
filter,
|
|
18
|
+
nocache,
|
|
19
|
+
formatAnswer,
|
|
20
|
+
sql,
|
|
21
|
+
}, reply) {
|
|
22
|
+
const query = {
|
|
23
|
+
id,
|
|
24
|
+
cols,
|
|
25
|
+
search,
|
|
26
|
+
format,
|
|
27
|
+
table,
|
|
28
|
+
filter,
|
|
29
|
+
nocache,
|
|
30
|
+
formatAnswer,
|
|
31
|
+
sql,
|
|
32
|
+
};
|
|
33
|
+
const result = await routeExport({
|
|
34
|
+
pg, user, host, unittest, columns, cls, query, tableSql, sourceName,
|
|
35
|
+
}, reply);
|
|
36
|
+
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import providers from './providers/index.js';
|
|
3
|
+
|
|
4
|
+
async function isFileExists(filePath, options = { }) {
|
|
5
|
+
const filename = path.basename(filePath);
|
|
6
|
+
|
|
7
|
+
// prefix
|
|
8
|
+
const prefix = (options.prefix === 'date' ? new Date().toISOString().split('T')[0] : null)
|
|
9
|
+
|| (options.prefix === '3s' ? filename.substring(0, 3) : '');
|
|
10
|
+
|
|
11
|
+
const relativePath = path.join(path.dirname(filePath), prefix, filename);
|
|
12
|
+
|
|
13
|
+
const fp = providers(options);
|
|
14
|
+
return fp.fileExists(relativePath, options);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default isFileExists;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
|
|
3
|
+
import fsp from 'node:fs/promises';
|
|
4
|
+
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import isFileExists from '../utils/isFileExists.js';
|
|
7
|
+
|
|
8
|
+
import isBuffer from './utils/typeguards/isBuffer.js';
|
|
9
|
+
import isReadableStream from './utils/typeguards/isReadableStream.js';
|
|
10
|
+
|
|
11
|
+
import getValidData from './utils/getValidData.js';
|
|
12
|
+
import dataTypes from './utils/handlers/dataTypes.js';
|
|
13
|
+
|
|
14
|
+
import getPath from '../utils/getPath.js';
|
|
15
|
+
|
|
16
|
+
const deleteFile = () => async (fp) => {
|
|
17
|
+
const filepath = getPath(fp);
|
|
18
|
+
if (!await isFileExists(filepath)) {
|
|
19
|
+
throw new Error('Файл не знайдено');
|
|
20
|
+
}
|
|
21
|
+
await fsp.rm(filepath);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const moveFile = () => async (fp, destFilepath) => {
|
|
25
|
+
const filepath = getPath(fp);
|
|
26
|
+
if (!await isFileExists(filepath)) {
|
|
27
|
+
throw new Error('Файл не знайдено');
|
|
28
|
+
}
|
|
29
|
+
await fsp.mkdir(path.dirname(filepath), { recursive: true });
|
|
30
|
+
await fsp.mkdir(path.dirname(destFilepath), { recursive: true });
|
|
31
|
+
|
|
32
|
+
await fsp.copyFile(filepath, destFilepath, fs.constants.COPYFILE_FICLONE);
|
|
33
|
+
await fsp.deleteFile(filepath);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const downloadFile = () => async (fp, options = {}) => {
|
|
37
|
+
const filepath = getPath(fp, options);
|
|
38
|
+
if (options.debug) {
|
|
39
|
+
return { original: fp, full: filepath };
|
|
40
|
+
}
|
|
41
|
+
if (!await isFileExists(filepath, options)) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
if (options.buffer) {
|
|
45
|
+
// const test = await readFile(filepath);
|
|
46
|
+
return fsp.readFile(filepath);
|
|
47
|
+
}
|
|
48
|
+
const fileStream = fs.createReadStream(filepath);
|
|
49
|
+
return fileStream;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const fileExists = () => async (filepath, opt = {}) => isFileExists(getPath(filepath, opt), opt);
|
|
53
|
+
|
|
54
|
+
const uploadFile = () => async (fp, data, opt = {}) => {
|
|
55
|
+
const filepath = getPath(fp, opt);
|
|
56
|
+
const validData = await getValidData({ data, types: [dataTypes.buffer, dataTypes.path, dataTypes.stream] });
|
|
57
|
+
// const validData = data;
|
|
58
|
+
await fsp.mkdir(path.dirname(filepath), { recursive: true });
|
|
59
|
+
try {
|
|
60
|
+
const exists = await isFileExists(validData);
|
|
61
|
+
|
|
62
|
+
if (!exists) {
|
|
63
|
+
await fsp.writeFile(filepath, validData, opt);
|
|
64
|
+
}
|
|
65
|
+
else if (isBuffer(validData) || isReadableStream(validData)) {
|
|
66
|
+
await fsp.writeFile(filepath, validData, opt);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
await fsp.copyFile(validData, filepath);
|
|
70
|
+
}
|
|
71
|
+
return filepath;
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
// console.log(err.toString());
|
|
75
|
+
|
|
76
|
+
throw new Error(`Can't upload a file ${err.toString()}`);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const stat = () => async (filepath) => fsp.stat(getPath(filepath));
|
|
81
|
+
|
|
82
|
+
const getFileSize = () => async (filepath) => (await fsp.stat(getPath(filepath))).size;
|
|
83
|
+
|
|
84
|
+
const getMDate = () => async (filepath) => new Date((await fsp.stat(getPath(filepath))).mtime);
|
|
85
|
+
|
|
86
|
+
const readdir = () => async (filepath) => fsp.readdir(getPath(getPath(filepath)));
|
|
87
|
+
|
|
88
|
+
export default function fsStorage(opt) {
|
|
89
|
+
return {
|
|
90
|
+
deleteFile: deleteFile(opt),
|
|
91
|
+
downloadFile: downloadFile(opt),
|
|
92
|
+
uploadFile: uploadFile(opt),
|
|
93
|
+
fileExists: fileExists(opt),
|
|
94
|
+
stat: stat(opt),
|
|
95
|
+
moveFile: moveFile(opt),
|
|
96
|
+
getFileSize: getFileSize(opt),
|
|
97
|
+
getMDate: getMDate(opt),
|
|
98
|
+
readdir: readdir(opt),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Readable } from 'stream';
|
|
2
|
+
|
|
3
|
+
interface IListElement {
|
|
4
|
+
login?: string;
|
|
5
|
+
password?: string;
|
|
6
|
+
endpoint?: string;
|
|
7
|
+
containerName?: string;
|
|
8
|
+
accessKeyId?: string;
|
|
9
|
+
secretAccessKey?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface IList {
|
|
13
|
+
[key: string]: IListElement;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface IArgs {
|
|
17
|
+
name: string;
|
|
18
|
+
list: IList;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface IUploadArgs {
|
|
22
|
+
filepath: string;
|
|
23
|
+
data: string | Buffer | ReadableStream;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface IInputArgs {
|
|
27
|
+
filepath: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface IObjects {
|
|
31
|
+
Key: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface IDownloadOptions {
|
|
35
|
+
buffer: boolean
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface Ifuncs {
|
|
39
|
+
deleteFile: (filepath: string) => Promise<any>;
|
|
40
|
+
downloadFile: (filepath: string, options: IDownloadOptions) => Promise<Readable | Buffer>;
|
|
41
|
+
uploadFile: (opt: IUploadArgs) => Promise<any>;
|
|
42
|
+
moveFile: (filepath: string, destFilepath: string) => Promise<any>;
|
|
43
|
+
fileExists: (filepath: string) => Promise<boolean>;
|
|
44
|
+
readdir: (filepath: string) => Promise<[IObjects]>
|
|
45
|
+
getFileSize: (filepath) => Promise<number>;
|
|
46
|
+
getMDate: (filepath) => Promise<Date>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export = function (opt?: IArgs): Ifuncs { }
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import s3 from './s3/index.js';
|
|
2
|
+
import fs from './fs.js';
|
|
3
|
+
|
|
4
|
+
const providers = (opt) => ({
|
|
5
|
+
fs: fs(opt),
|
|
6
|
+
s3: s3(opt),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
// import config from '@opengis/fastify-file/config.js';
|
|
10
|
+
import config from '../../../../config.js';
|
|
11
|
+
|
|
12
|
+
// storage s3 or file
|
|
13
|
+
function dataStorage(opt) {
|
|
14
|
+
const { storageList } = config;
|
|
15
|
+
const providerName = opt?.provider || (config.s3 ? 's3' : 'fs');
|
|
16
|
+
|
|
17
|
+
if (storageList[providerName]) {
|
|
18
|
+
return storageList[providerName];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (storageList[providerName] && !['fs', 's3'].includes(providerName)) {
|
|
22
|
+
return storageList[providerName];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const confS3 = {
|
|
26
|
+
containerName: 'work',
|
|
27
|
+
accessKeyId: config.s3?.user,
|
|
28
|
+
secretAccessKey: config.s3?.password,
|
|
29
|
+
...config.s3 || {},
|
|
30
|
+
};
|
|
31
|
+
const provider = providers(confS3)[providerName];
|
|
32
|
+
|
|
33
|
+
storageList[providerName] = provider;
|
|
34
|
+
return provider;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default dataStorage;
|