@opengis/fastify-table 2.2.0 → 2.2.2
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/dist/server/plugins/file/providers/fs.d.ts.map +1 -1
- package/dist/server/plugins/file/providers/fs.js +2 -0
- package/dist/server/plugins/file/providers/s3/funcs/downloadFile.d.ts.map +1 -1
- package/dist/server/plugins/file/providers/s3/funcs/downloadFile.js +7 -0
- package/dist/server/routes/cron/controllers/cronApi.js +1 -1
- package/dist/server/routes/file/controllers/files.js +1 -1
- package/dist/server/routes/file/controllers/resize.d.ts.map +1 -1
- package/dist/server/routes/file/controllers/resize.js +9 -3
- package/dist/server/routes/file/controllers/resizeAll.d.ts.map +1 -1
- package/dist/server/routes/file/controllers/resizeAll.js +6 -2
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/file/providers/fs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/file/providers/fs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AAuGzB,MAAM,CAAC,OAAO,UAAU,SAAS;qBAtFG,MAAM;uBAsB7B,MAAM,YAAW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;;;;qBAyBpC,MAAM,QAAQ,GAAG;2BALX,GAAG,QAAO,GAAG;qBAgCI,MAAM;mBAlER,MAAM,gBAAgB,MAAM;4BAqEnB,GAAG;yBAGN,GAAG;wBAGJ,GAAG;EAezC"}
|
|
@@ -2,6 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import fsp from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import isFileExists from "../utils/isFileExists.js";
|
|
5
|
+
import logger from "../../logger/getLogger.js";
|
|
5
6
|
import isBuffer from "./utils/typeguards/isBuffer.js";
|
|
6
7
|
import isReadableStream from "./utils/typeguards/isReadableStream.js";
|
|
7
8
|
import getValidData from "./utils/getValidData.js";
|
|
@@ -36,6 +37,7 @@ const downloadFile = () => async (fp, options = {}) => {
|
|
|
36
37
|
return fsp.readFile(filepath);
|
|
37
38
|
}
|
|
38
39
|
const fileStream = fs.createReadStream(filepath);
|
|
40
|
+
logger.file("file/download", { provider: "fs", relpath: fp, filepath });
|
|
39
41
|
return fileStream;
|
|
40
42
|
};
|
|
41
43
|
const fileExists = () => async (filepath, opt = {}) => isFileExists(getPath(filepath, opt));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"downloadFile.d.ts","sourceRoot":"","sources":["../../../../../../../server/plugins/file/providers/s3/funcs/downloadFile.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"downloadFile.d.ts","sourceRoot":"","sources":["../../../../../../../server/plugins/file/providers/s3/funcs/downloadFile.ts"],"names":[],"mappings":"AAiBA,QAAA,MAAM,aAAa,GAChB,aAAa,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,MAC1B,IAAI,MAAM,EAAE,UAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,iBAgDnD,CAAC;AAEJ,eAAe,aAAa,CAAC"}
|
|
@@ -3,6 +3,7 @@ import { readFile } from "node:fs/promises";
|
|
|
3
3
|
import { createReadStream } from "node:fs";
|
|
4
4
|
import s3Client from "../client.js";
|
|
5
5
|
import config from "../../../../../../config.js";
|
|
6
|
+
import logger from "../../../../logger/getLogger.js";
|
|
6
7
|
import streamToBuffer from "../../utils/streamToBuffer.js";
|
|
7
8
|
// if not found on s3 => fs
|
|
8
9
|
import fsFuncs from "../../fs.js";
|
|
@@ -17,6 +18,7 @@ const getFileStream = (s3Settings) => async (fp, options = {}) => {
|
|
|
17
18
|
};
|
|
18
19
|
try {
|
|
19
20
|
const data = await s3Client.send(new GetObjectCommand(bucketParams));
|
|
21
|
+
logger.file("file/download", { provider: "s3", filepath });
|
|
20
22
|
if (options.buffer) {
|
|
21
23
|
return streamToBuffer(data.Body);
|
|
22
24
|
}
|
|
@@ -36,6 +38,11 @@ const getFileStream = (s3Settings) => async (fp, options = {}) => {
|
|
|
36
38
|
if (!exists) {
|
|
37
39
|
return null;
|
|
38
40
|
}
|
|
41
|
+
logger.file("file/download", {
|
|
42
|
+
provider: "fs/fallback",
|
|
43
|
+
relpath: fp,
|
|
44
|
+
filepath: filepath1,
|
|
45
|
+
});
|
|
39
46
|
if (options.buffer) {
|
|
40
47
|
return readFile(filepath1);
|
|
41
48
|
}
|
|
@@ -13,6 +13,6 @@ export default async function cronApi(req, reply) {
|
|
|
13
13
|
.status(404)
|
|
14
14
|
.send({ error: `cron not found: ${params.name}`, code: 404 });
|
|
15
15
|
}
|
|
16
|
-
const result = await cronList[params.name]?.(req);
|
|
16
|
+
const result = await cronList[params.name]?.(req, reply);
|
|
17
17
|
return result;
|
|
18
18
|
}
|
|
@@ -30,7 +30,7 @@ export default async function getFile({ params, user }, reply) {
|
|
|
30
30
|
if (params["*"].includes("../")) {
|
|
31
31
|
return reply.status(403).send({ error: "wrong params", code: 403 });
|
|
32
32
|
}
|
|
33
|
-
const relpath = (params["*"].startsWith("/") ? params["*"].slice(1) : params["*"]).replace(
|
|
33
|
+
const relpath = (params["*"].startsWith("/") ? params["*"].slice(1) : params["*"]).replace(/^files\//g, "") + (params["*"].endsWith("/") ? "index.html" : "");
|
|
34
34
|
if (!relpath) {
|
|
35
35
|
return reply
|
|
36
36
|
.status(400)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resize.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/resize.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"resize.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/resize.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAwC5C;;GAEG;AAEH,wBAA8B,MAAM,CAClC,EACE,KAAK,GACN,EAAE;IACD,KAAK,EAAE;QACL,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;QAC1B,IAAI,EAAE,MAAM,CAAC;QACb,CAAC,CAAC,EAAE,MAAM,CAAC;QACX,CAAC,CAAC,EAAE,MAAM,CAAC;QACX,OAAO,CAAC,EAAE,GAAG,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,GAAG,CAAC;KACf,CAAC;CACH,EACD,KAAK,EAAE,YAAY,kBA8IpB"}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { writeFile } from "node:fs/promises";
|
|
2
3
|
import sharp from "sharp";
|
|
3
4
|
import { imageSize } from "image-size";
|
|
4
|
-
import { config, downloadFile,
|
|
5
|
+
import { config, downloadFile,
|
|
6
|
+
// uploadFile,
|
|
7
|
+
isFileExists, getFolder, } from "../../../../utils.js";
|
|
5
8
|
import grpc from "../../../plugins/grpc/grpc.js";
|
|
6
9
|
import getMimeType from "../../../plugins/file/providers/mime/index.js";
|
|
7
10
|
const defaultWidth = 400;
|
|
8
11
|
const defaultHeight = 240;
|
|
9
12
|
const maxWidth = 2000;
|
|
13
|
+
const rootDir = getFolder(config, "local");
|
|
10
14
|
const getHeight = (width, size, ratio = 1) => {
|
|
11
15
|
if (size && size.toLowerCase().split("x")[1])
|
|
12
16
|
return size.toLowerCase().split("x")[1];
|
|
@@ -102,12 +106,14 @@ export default async function resize({ query, }, reply) {
|
|
|
102
106
|
height: resizeHeight,
|
|
103
107
|
quality: resizeQuality,
|
|
104
108
|
});
|
|
105
|
-
await uploadFile(resizePath, Buffer.from(result, "base64"));
|
|
109
|
+
// await uploadFile(resizePath, Buffer.from(result, "base64"));
|
|
110
|
+
await writeFile(path.join(rootDir, resizePath), Buffer.from(result, "base64"));
|
|
106
111
|
if (format === "webp") {
|
|
107
112
|
const buffer = await sharp(Buffer.from(result, "base64"))
|
|
108
113
|
.webp({ quality: resizeQuality })
|
|
109
114
|
.toBuffer({ resolveWithObject: false });
|
|
110
|
-
await
|
|
115
|
+
await writeFile(path.join(rootDir, resizePath2), buffer);
|
|
116
|
+
// await uploadFile(resizePath2, buffer);
|
|
111
117
|
return reply.headers({ "Content-Type": "image/webp" }).send(buffer);
|
|
112
118
|
}
|
|
113
119
|
return reply
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resizeAll.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/resizeAll.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resizeAll.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/resizeAll.ts"],"names":[],"mappings":"AAyHA,wBAA8B,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,gBAsH3D"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { writeFile } from "node:fs/promises";
|
|
2
4
|
import { imageSize } from "image-size";
|
|
3
|
-
import { pgClients, eventStream, logger, isFileExists, downloadFile, uploadFile, } from "../../../../utils.js";
|
|
5
|
+
import { config, pgClients, eventStream, logger, isFileExists, downloadFile, uploadFile, getFolder, } from "../../../../utils.js";
|
|
4
6
|
import grpc from "../../../plugins/grpc/grpc.js";
|
|
5
7
|
import { images } from "../../../plugins/file/utils/allowedExtensions.js";
|
|
6
8
|
const { resizeImage } = grpc();
|
|
9
|
+
const rootDir = getFolder(config, "local");
|
|
7
10
|
async function resizeOne({ relpath: relpath1, resizeQuality = 80, maxWidth = 2048, errors = [], success = [], notfound = [], equalwidth = [], send = () => { }, }) {
|
|
8
11
|
const exists = await isFileExists(relpath1);
|
|
9
12
|
const existsOriginal = await isFileExists(relpath1.replace("files/", "files/original/"));
|
|
@@ -55,7 +58,8 @@ async function resizeOne({ relpath: relpath1, resizeQuality = 80, maxWidth = 204
|
|
|
55
58
|
height: resizeHeight,
|
|
56
59
|
quality: resizeQuality,
|
|
57
60
|
});
|
|
58
|
-
await uploadFile(relpath1, Buffer.from(result, "base64"));
|
|
61
|
+
// await uploadFile(relpath1, Buffer.from(result, "base64"));
|
|
62
|
+
await writeFile(path.join(rootDir, relpath1), Buffer.from(result, "base64"));
|
|
59
63
|
send(`resize ${relpath1} success`);
|
|
60
64
|
success.push(relpath1);
|
|
61
65
|
return null;
|