@opengis/fastify-table 2.0.96 → 2.0.97

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.
@@ -1 +1 @@
1
- {"version":3,"file":"uploadMultiPart.d.ts","sourceRoot":"","sources":["../../../../server/plugins/file/uploadMultiPart.ts"],"names":[],"mappings":"AAqBA,UAAU,KAAK;IACb,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC9B;AAyCD,wBAA8B,eAAe,CAC3C,GAAG,EAAE,GAAG,EACR,EACE,UAAU,EACV,GAAG,EACH,MAAM,EACN,gBAAwB,GACzB,GAAE;IACD,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CACvB,GACL,OAAO,CAAC,KAAK,CAAC,CAgGhB"}
1
+ {"version":3,"file":"uploadMultiPart.d.ts","sourceRoot":"","sources":["../../../../server/plugins/file/uploadMultiPart.ts"],"names":[],"mappings":"AAqBA,UAAU,KAAK;IACb,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC9B;AA2CD,wBAA8B,eAAe,CAC3C,GAAG,EAAE,GAAG,EACR,EACE,UAAU,EACV,GAAG,EACH,MAAM,EACN,gBAAwB,GACzB,GAAE;IACD,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CACvB,GACL,OAAO,CAAC,KAAK,CAAC,CAmGhB"}
@@ -9,7 +9,7 @@ import providers from "./providers/index.js";
9
9
  import { all, images } from "./utils/allowedExtensions.js";
10
10
  import grpc from "../grpc/grpc.js";
11
11
  import getFileType from "./utils/getFileType.js";
12
- import { BadRequestError } from "../../types/errors.js";
12
+ import { BadRequestError, PayloadTooLargeError } from "../../types/errors.js";
13
13
  const { resizeImage } = grpc();
14
14
  const { resizeImageMinSize = 5 } = config; // resize images >= 5 MB by default
15
15
  async function writeFileToDisk(file, buffer) {
@@ -17,7 +17,7 @@ async function writeFileToDisk(file, buffer) {
17
17
  return null;
18
18
  }
19
19
  // resize big images
20
- if (images.find((el) => el === file.extension) &&
20
+ if (images.find((el) => el === file.extension && !["tif", "tiff"].includes(file.extension)) &&
21
21
  file.size >= resizeImageMinSize * 1024 * 1024) {
22
22
  const { width = 320, height = 240 } = imageSize(buffer) || {};
23
23
  const ratio = width / height;
@@ -62,6 +62,7 @@ export default async function uploadMultiPart(req, { extensions, raw, subdir, or
62
62
  value.file.on("data", (chunk) => chunks.push(chunk));
63
63
  value.file.on("end", () => res(Buffer.concat(chunks)));
64
64
  value.file.on("error", rej);
65
+ value.file.on("limit", () => rej(new PayloadTooLargeError("file size exceeds limit")));
65
66
  });
66
67
  if (!fileBuffer?.length) {
67
68
  throw new BadRequestError("file buffer is empty");
@@ -1 +1 @@
1
- {"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../../../server/routes/crud/controllers/table.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAe5C,wBAA8B,QAAQ,CACpC,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,GAAG,gBAuNZ"}
1
+ {"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../../../server/routes/crud/controllers/table.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAe5C,wBAA8B,QAAQ,CACpC,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,GAAG,gBA0NZ"}
@@ -2,7 +2,11 @@ import { config, getAccess, getTemplate, getMeta, setToken, applyHook, getToken,
2
2
  import extraDataGet from "../../../plugins/extra/extraDataGet.js";
3
3
  export default async function tableAPI(req, reply, called) {
4
4
  const { pg = pgClients.client, params, user = {}, query = {} } = req;
5
- const tokenData = (await getToken({ token: params?.table, uid: user.uid, json: 1 })) || {};
5
+ const tokenData = await getToken({
6
+ token: params?.table,
7
+ uid: user.uid,
8
+ json: 1,
9
+ });
6
10
  const hookData = (await applyHook("preTable", {
7
11
  pg,
8
12
  table: params?.table,
@@ -13,24 +17,24 @@ export default async function tableAPI(req, reply, called) {
13
17
  if (hookData?.message && hookData?.status) {
14
18
  return reply.status(hookData?.status).send(hookData?.message);
15
19
  }
16
- const templateName = hookData?.table || tokenData.table || params.table;
20
+ const templateName = hookData?.table || tokenData?.table || params.table;
17
21
  const loadTable = await getTemplate("table", templateName);
18
22
  if (!loadTable &&
19
- !pg.pk?.[tokenData.table] &&
23
+ !pg.pk?.[tokenData?.table] &&
20
24
  !(pg.pk?.[templateName] && called)) {
21
25
  return reply.status(404).send("not found");
22
26
  }
23
- const { table: table1 = params.table, form: form1, obj, } = hookData || loadTable || tokenData;
27
+ const { table: table1 = params.table, form: form1, obj, } = hookData || loadTable || tokenData || {};
24
28
  const table = loadTable?.table || table1;
25
29
  const form = loadTable?.form || form1;
26
- const id = hookData?.id || tokenData.id || params.id;
30
+ const id = hookData?.id || tokenData?.id || params.id;
27
31
  if (tokenData && !id)
28
32
  return { message: {} };
29
33
  if (!table && !id) {
30
34
  return reply.status(400).send("not enough params");
31
35
  }
32
36
  const { actions = [], query: accessQuery } = (await getAccess({
33
- table,
37
+ table: templateName,
34
38
  form,
35
39
  id,
36
40
  user,
@@ -52,7 +52,7 @@ export default async function exportTable({ pg = pgClients.client, headers, user
52
52
  }
53
53
  const slice = query.slice ? Math.min(+query.slice || 16, 16) : null;
54
54
  const date = new Date();
55
- const sufixName = `${filter}-${cols || "all"}-${search}-${query.limit || "unlimited"}-${id}`;
55
+ const sufixName = `${filter}-${cols || "all"}-${search}-${query.limit || "unlimited"}-${query.slice || "full"}-${id}`;
56
56
  const sufixDate = [
57
57
  date.getFullYear(),
58
58
  date.getMonth(),
@@ -4,7 +4,11 @@ export declare const NotFoundError: createError.FastifyErrorConstructor<{
4
4
  statusCode: 404;
5
5
  }, [any?, any?, any?]>;
6
6
  export declare const BadRequestError: createError.FastifyErrorConstructor<{
7
- code: "NOT_FOUND_ERROR";
7
+ code: "BAD_REQUEST_ERROR";
8
8
  statusCode: 400;
9
9
  }, [any?, any?, any?]>;
10
+ export declare const PayloadTooLargeError: createError.FastifyErrorConstructor<{
11
+ code: "PAYLOAD_TOO_LARGE_ERROR";
12
+ statusCode: 413;
13
+ }, [any?, any?, any?]>;
10
14
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../server/types/errors.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,gBAAgB,CAAC;AAEzC,eAAO,MAAM,aAAa;;;sBAIzB,CAAC;AACF,eAAO,MAAM,eAAe;;;sBAI3B,CAAC"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../server/types/errors.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,gBAAgB,CAAC;AACzC,eAAO,MAAM,aAAa;;;sBAIzB,CAAC;AACF,eAAO,MAAM,eAAe;;;sBAI3B,CAAC;AACF,eAAO,MAAM,oBAAoB;;;sBAIhC,CAAC"}
@@ -1,3 +1,4 @@
1
1
  import createError from "@fastify/error";
2
2
  export const NotFoundError = createError("NOT_FOUND_ERROR", "Resource not found: %s", 404);
3
- export const BadRequestError = createError("NOT_FOUND_ERROR", "Bad request: %s", 400);
3
+ export const BadRequestError = createError("BAD_REQUEST_ERROR", "Bad request: %s", 400);
4
+ export const PayloadTooLargeError = createError("PAYLOAD_TOO_LARGE_ERROR", "Payload Too Large: %s", 413);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "2.0.96",
3
+ "version": "2.0.97",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [