@opengis/fastify-table 2.0.106 → 2.0.107

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.
Files changed (102) hide show
  1. package/dist/config.d.ts.map +1 -1
  2. package/dist/script/adduser +15 -0
  3. package/dist/script/dump.js +176 -0
  4. package/dist/script/migrate.js +25 -0
  5. package/dist/server/plugins/auth/funcs/verifyPassword.d.ts.map +1 -1
  6. package/dist/server/plugins/auth/funcs/verifyPassword.js +3 -1
  7. package/dist/server/plugins/crud/funcs/dataInsert.js +1 -1
  8. package/dist/server/plugins/crud/funcs/dataUpdate.d.ts.map +1 -1
  9. package/dist/server/plugins/crud/funcs/dataUpdate.js +7 -4
  10. package/dist/server/plugins/logger/getLogger.d.ts.map +1 -1
  11. package/dist/server/plugins/logger/getLogger.js +13 -10
  12. package/dist/server/plugins/logger/index.d.ts.map +1 -1
  13. package/dist/server/plugins/logger/index.js +2 -1
  14. package/dist/server/plugins/pg/funcs/getPG.d.ts.map +1 -1
  15. package/dist/server/plugins/pg/funcs/getPG.js +1 -0
  16. package/dist/server/plugins/pg/funcs/getPGAsync.js +1 -1
  17. package/dist/server/plugins/pg/funcs/init.d.ts +1 -1
  18. package/dist/server/plugins/pg/funcs/init.d.ts.map +1 -1
  19. package/dist/server/plugins/pg/funcs/init.js +20 -5
  20. package/dist/server/plugins/pg/funcs/pool.d.ts.map +1 -1
  21. package/dist/server/plugins/pg/funcs/pool.js +10 -16
  22. package/dist/server/plugins/pg/index.d.ts.map +1 -1
  23. package/dist/server/plugins/pg/index.js +3 -2
  24. package/dist/server/plugins/redis/funcs/getRedis.d.ts.map +1 -1
  25. package/dist/server/plugins/redis/funcs/getRedis.js +6 -4
  26. package/dist/server/plugins/redis/index.d.ts.map +1 -1
  27. package/dist/server/plugins/redis/index.js +4 -1
  28. package/dist/server/plugins/sqlite/index.d.ts.map +1 -1
  29. package/dist/server/plugins/sqlite/index.js +7 -3
  30. package/dist/server/plugins/table/funcs/getFilter.d.ts +1 -1
  31. package/dist/server/plugins/table/funcs/getFilter.d.ts.map +1 -1
  32. package/dist/server/plugins/table/funcs/getFilter.js +14 -1
  33. package/dist/server/plugins/table/funcs/getSelectMeta.d.ts.map +1 -1
  34. package/dist/server/plugins/table/funcs/getSelectMeta.js +2 -4
  35. package/dist/server/plugins/table/funcs/gisIRColumn.d.ts +2 -2
  36. package/dist/server/plugins/table/funcs/gisIRColumn.js +1 -1
  37. package/dist/server/plugins/util/funcs/unflattenObject.d.ts.map +1 -1
  38. package/dist/server/plugins/util/funcs/unflattenObject.js +3 -1
  39. package/dist/server/routes/access/controllers/access.group.d.ts +2 -2
  40. package/dist/server/routes/access/controllers/access.group.d.ts.map +1 -1
  41. package/dist/server/routes/access/controllers/access.group.js +0 -1
  42. package/dist/server/routes/access/controllers/access.group.post.d.ts +2 -2
  43. package/dist/server/routes/access/controllers/access.group.post.d.ts.map +1 -1
  44. package/dist/server/routes/access/controllers/access.group.post.js +0 -1
  45. package/dist/server/routes/auth/controllers/core/registration.d.ts +1 -4
  46. package/dist/server/routes/auth/controllers/core/registration.d.ts.map +1 -1
  47. package/dist/server/routes/auth/controllers/core/registration.js +28 -9
  48. package/dist/server/routes/auth/controllers/core/updateUserInfo.js +1 -1
  49. package/dist/server/routes/auth/controllers/jwt/authorize.js +5 -5
  50. package/dist/server/routes/auth/controllers/jwt/token.d.ts.map +1 -1
  51. package/dist/server/routes/auth/controllers/jwt/token.js +10 -12
  52. package/dist/server/routes/cron/controllers/cronApi.d.ts +1 -1
  53. package/dist/server/routes/cron/controllers/cronApi.d.ts.map +1 -1
  54. package/dist/server/routes/cron/controllers/cronApi.js +5 -3
  55. package/dist/server/routes/crud/controllers/insert.d.ts +1 -4
  56. package/dist/server/routes/crud/controllers/insert.d.ts.map +1 -1
  57. package/dist/server/routes/crud/controllers/insert.js +24 -16
  58. package/dist/server/routes/crud/controllers/table.d.ts.map +1 -1
  59. package/dist/server/routes/crud/controllers/table.js +13 -6
  60. package/dist/server/routes/crud/controllers/update.d.ts.map +1 -1
  61. package/dist/server/routes/crud/controllers/update.js +23 -15
  62. package/dist/server/routes/file/controllers/delete.d.ts +1 -15
  63. package/dist/server/routes/file/controllers/delete.d.ts.map +1 -1
  64. package/dist/server/routes/file/controllers/delete.js +13 -20
  65. package/dist/server/routes/file/controllers/download.d.ts +2 -2
  66. package/dist/server/routes/file/controllers/download.d.ts.map +1 -1
  67. package/dist/server/routes/file/controllers/download.js +39 -30
  68. package/dist/server/routes/file/controllers/files.d.ts +2 -1
  69. package/dist/server/routes/file/controllers/files.d.ts.map +1 -1
  70. package/dist/server/routes/file/controllers/files.js +15 -11
  71. package/dist/server/routes/file/controllers/resize.d.ts +1 -2
  72. package/dist/server/routes/file/controllers/resize.d.ts.map +1 -1
  73. package/dist/server/routes/file/controllers/resize.js +17 -6
  74. package/dist/server/routes/file/controllers/upload.d.ts.map +1 -1
  75. package/dist/server/routes/file/controllers/upload.js +17 -16
  76. package/dist/server/routes/file/controllers/uploadImage.d.ts +11 -13
  77. package/dist/server/routes/file/controllers/uploadImage.d.ts.map +1 -1
  78. package/dist/server/routes/file/controllers/uploadImage.js +13 -15
  79. package/dist/server/routes/logger/controllers/logger.file.js +1 -1
  80. package/dist/server/routes/menu/controllers/interfaces.d.ts +1 -7
  81. package/dist/server/routes/menu/controllers/interfaces.d.ts.map +1 -1
  82. package/dist/server/routes/table/controllers/card.d.ts +1 -1
  83. package/dist/server/routes/table/controllers/card.d.ts.map +1 -1
  84. package/dist/server/routes/table/controllers/card.js +15 -9
  85. package/dist/server/routes/table/controllers/filter.d.ts +1 -1
  86. package/dist/server/routes/table/controllers/filter.d.ts.map +1 -1
  87. package/dist/server/routes/table/controllers/filter.js +2 -2
  88. package/dist/server/routes/table/controllers/form.d.ts +1 -1
  89. package/dist/server/routes/table/controllers/form.d.ts.map +1 -1
  90. package/dist/server/routes/table/controllers/form.js +8 -5
  91. package/dist/server/routes/table/controllers/search.d.ts +1 -1
  92. package/dist/server/routes/table/controllers/search.d.ts.map +1 -1
  93. package/dist/server/routes/table/controllers/search.js +5 -6
  94. package/dist/server/routes/table/controllers/suggest.d.ts +1 -1
  95. package/dist/server/routes/table/controllers/suggest.d.ts.map +1 -1
  96. package/dist/server/routes/table/controllers/suggest.js +30 -15
  97. package/dist/server/routes/table/functions/getData.d.ts +1 -1
  98. package/dist/server/routes/table/functions/getData.d.ts.map +1 -1
  99. package/dist/server/routes/table/functions/getData.js +60 -34
  100. package/dist/server/types/core.d.ts +7 -0
  101. package/dist/server/types/core.d.ts.map +1 -1
  102. package/package.json +3 -3
@@ -4,7 +4,7 @@ import insert from "./insert.js";
4
4
  export default async function update(req, reply) {
5
5
  const { pg = pgClients.client, user, params = {}, body = {}, headers = {}, unittest, } = req;
6
6
  if (!user) {
7
- return reply.status(403).send("access restricted");
7
+ return reply.status(403).send({ error: "access restricted", code: 403 });
8
8
  }
9
9
  const hookData = (await applyHook("preUpdate", {
10
10
  pg,
@@ -13,7 +13,10 @@ export default async function update(req, reply) {
13
13
  user,
14
14
  }));
15
15
  if (hookData?.message && hookData?.status) {
16
- return { message: hookData?.message, status: hookData?.status };
16
+ const response = hookData.status >= 400
17
+ ? { error: hookData.message, code: hookData.status }
18
+ : hookData.message;
19
+ return reply.status(hookData.status).send(response);
17
20
  }
18
21
  const { referer } = headers;
19
22
  const tokenData = await getToken({
@@ -37,19 +40,21 @@ export default async function update(req, reply) {
37
40
  !config.local &&
38
41
  !config.security?.disableToken &&
39
42
  !config.auth?.disable) {
40
- return reply.status(400).send("invalid token");
43
+ return reply.status(400).send({ error: "invalid token", code: 400 });
41
44
  }
42
45
  if (!actions.includes("edit") && !config.local && !tokenData) {
43
- return reply.status(403).send("access restricted: actions");
46
+ return reply
47
+ .status(403)
48
+ .send({ error: "access restricted: actions", code: 403 });
44
49
  }
45
50
  if (!edit) {
46
- return reply.status(400).send("table is required");
51
+ return reply.status(400).send({ error: "table is required", code: 400 });
47
52
  }
48
53
  if (!id && tokenData?.table) {
49
54
  return insert(req, reply);
50
55
  }
51
56
  if (!id) {
52
- return reply.status(400).send("id is required");
57
+ return reply.status(400).send({ error: "id is required", code: 400 });
53
58
  }
54
59
  const loadTemplate = await getTemplate("table", edit);
55
60
  const { table } = loadTemplate || hookData || tokenData || params || {};
@@ -69,9 +74,10 @@ export default async function update(req, reply) {
69
74
  const xssCheck = checkXSS({ body, schema });
70
75
  if (xssCheck.error && formData?.xssCheck !== false) {
71
76
  logger.file("injection/xss", { msg: xssCheck.error, table }, req);
72
- return reply
73
- .status(409)
74
- .send("Дані містять заборонені символи. Приберіть їх та спробуйте ще раз");
77
+ return reply.status(409).send({
78
+ error: "Дані містять заборонені символи. Приберіть їх та спробуйте ще раз",
79
+ code: 409,
80
+ });
75
81
  }
76
82
  const fieldCheck = validateData({ body, schema });
77
83
  if (fieldCheck.error) {
@@ -81,9 +87,10 @@ export default async function update(req, reply) {
81
87
  uid: user?.uid,
82
88
  ...fieldCheck,
83
89
  });
84
- return reply
85
- .status(409)
86
- .send("Дані не пройшли валідацію. Приберіть некоректні дані та спробуйте ще раз");
90
+ return reply.status(409).send({
91
+ error: "Дані не пройшли валідацію. Приберіть некоректні дані та спробуйте ще раз",
92
+ code: 409,
93
+ });
87
94
  }
88
95
  const sqlCheck = checkSQL({ body, schema });
89
96
  if (sqlCheck.error) {
@@ -93,9 +100,10 @@ export default async function update(req, reply) {
93
100
  uid: user?.uid,
94
101
  ...sqlCheck,
95
102
  });
96
- return reply
97
- .status(409)
98
- .send("Дані містять заборонені sql символи. Приберіть їх та спробуйте ще раз");
103
+ return reply.status(409).send({
104
+ error: "Дані містять заборонені sql символи. Приберіть їх та спробуйте ще раз",
105
+ code: 409,
106
+ });
99
107
  }
100
108
  if (tokenData?.obj) {
101
109
  const objData = tokenData.obj?.split("#").reduce((p, el) => ({
@@ -16,19 +16,5 @@
16
16
  * @returns {Object} headers Заголовки HTTP
17
17
  * @returns {String} message Повідомлення про успішне виконання або об'єкт з параметрами
18
18
  */
19
- export default function deleteFileAPI(req: any): Promise<{
20
- message: string;
21
- status: number;
22
- } | {
23
- message: {
24
- id: any;
25
- filepath: any;
26
- };
27
- status: number;
28
- error?: undefined;
29
- } | {
30
- error: any;
31
- status: number;
32
- message?: undefined;
33
- }>;
19
+ export default function deleteFileAPI(req: any, reply: any): Promise<any>;
34
20
  //# sourceMappingURL=delete.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/delete.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;GAiBG;AAEH,wBAA8B,aAAa,CAAC,GAAG,EAAE,GAAG;;;;;;;;;;;;;;GAyFnD"}
1
+ {"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/delete.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AAEH,wBAA8B,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,gBAoF/D"}
@@ -1,5 +1,4 @@
1
1
  import { config, dataUpdate, logger, pgClients } from "../../../../utils.js";
2
- const resp = { message: "File not found", status: 404 };
3
2
  /**
4
3
  * Апі використовується для видалення файлів за допомогою fs або s3
5
4
  *
@@ -18,15 +17,15 @@ const resp = { message: "File not found", status: 404 };
18
17
  * @returns {Object} headers Заголовки HTTP
19
18
  * @returns {String} message Повідомлення про успішне виконання або об'єкт з параметрами
20
19
  */
21
- export default async function deleteFileAPI(req) {
20
+ export default async function deleteFileAPI(req, reply) {
22
21
  const { pg = pgClients.client, params = {}, user = {} } = req;
22
+ const { uid, user_rnokpp: rnokpp } = user;
23
23
  if (!params["*"]) {
24
- return resp;
24
+ return reply.status(404).send({ error: "File not found", code: 404 });
25
25
  }
26
26
  const filename = params["*"].startsWith("/") || /^[0-9]+$/.test(params["*"])
27
27
  ? params["*"]
28
28
  : `/${params["*"]}`;
29
- const { uid, user_rnokpp: rnokpp } = user;
30
29
  if (!filename) {
31
30
  logger.file("file", {
32
31
  level: "INFO",
@@ -36,7 +35,7 @@ export default async function deleteFileAPI(req) {
36
35
  uid,
37
36
  rnokpp,
38
37
  });
39
- return resp;
38
+ return reply.status(404).send({ error: "File not found", code: 404 });
40
39
  }
41
40
  if (filename.includes("..")) {
42
41
  logger.file("file", {
@@ -47,7 +46,7 @@ export default async function deleteFileAPI(req) {
47
46
  uid,
48
47
  rnokpp,
49
48
  });
50
- return resp;
49
+ return reply.status(404).send({ error: "File not found", code: 404 });
51
50
  }
52
51
  try {
53
52
  const result = await pg
@@ -64,36 +63,30 @@ export default async function deleteFileAPI(req) {
64
63
  logger.file("file", {
65
64
  level: "INFO",
66
65
  type: "delete",
67
- message: resp.message,
66
+ message: "file not found",
68
67
  file: params["*"],
69
68
  uid,
70
69
  rnokpp,
71
70
  });
72
- return resp;
71
+ return reply.status(404).send({ error: "File not found", code: 404 });
73
72
  }
74
73
  const message = { id: res.file_id, filepath: res.file_path };
75
- logger.file("file", {
76
- level: "INFO",
77
- type: "delete",
74
+ logger.file("file/delete", {
78
75
  message,
79
76
  file: params["*"],
80
77
  uid,
81
78
  rnokpp,
82
79
  });
83
- return { message, status: 200 };
80
+ return message;
84
81
  }
85
82
  catch (err) {
86
- logger.file("file", {
87
- level: "ERROR",
88
- type: "delete",
89
- message: err.toString(),
83
+ logger.file("file/delete", {
84
+ error: err.toString(),
90
85
  file: params["*"],
91
86
  uid,
92
87
  rnokpp,
93
88
  });
94
- return {
95
- error: config?.local ? err.toString() : "Помилка видалення файлу",
96
- status: 500,
97
- };
89
+ const error = config.local ? err.toString() : "Помилка видалення файлу";
90
+ return reply.status(500).send({ error, code: 500 });
98
91
  }
99
92
  }
@@ -1,3 +1,4 @@
1
+ import type { FastifyReply } from "fastify";
1
2
  /**
2
3
  * Апі використовується для скачування файлів за допомогою fs або s3
3
4
  *
@@ -15,6 +16,5 @@
15
16
  * @returns {Object} headers Заголовки HTTP
16
17
  * @returns {String} pipe Шлях до файла для скачування або відображення
17
18
  */
18
- declare function download({ params }: any, reply: any): Promise<any>;
19
- export default download;
19
+ export default function download({ params, user }: any, reply: FastifyReply): Promise<any>;
20
20
  //# sourceMappingURL=download.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/download.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;;;GAgBG;AAEH,iBAAe,QAAQ,CAAC,EACtB,MAAM,EACP,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,gBAkCjB;AAED,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/download.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAgB5C;;;;;;;;;;;;;;;;GAgBG;AAEH,wBAA8B,QAAQ,CACpC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,GAAG,EACrB,KAAK,EAAE,YAAY,gBAgDpB"}
@@ -1,6 +1,9 @@
1
- import path from 'node:path';
2
- import providers from '../../../plugins/file/providers/index.js';
3
- import getMimeType from '../../../plugins/file/providers/mime/index.js';
1
+ import path from "node:path";
2
+ import providers from "../../../plugins/file/providers/index.js";
3
+ import getMimeType from "../../../plugins/file/providers/mime/index.js";
4
+ import logger from "../../../plugins/logger/getLogger.js";
5
+ import applyHook from "../../../plugins/hook/applyHook.js";
6
+ const { downloadFile } = providers();
4
7
  /* const allowedPublicDirs = [
5
8
  'upload', 'page', 'site', 'maps', 'tmp', 'uploads', 'site_slider', 'module', 'product', 'image', 'geo_works_file',
6
9
  ]; */
@@ -21,36 +24,42 @@ import getMimeType from '../../../plugins/file/providers/mime/index.js';
21
24
  * @returns {Object} headers Заголовки HTTP
22
25
  * @returns {String} pipe Шлях до файла для скачування або відображення
23
26
  */
24
- async function download({ params }, reply) {
25
- if (!params?.['*'])
26
- return { message: 'not enough params', status: 400 };
27
- const filename = params['*'].startsWith('/') ? params['*'].slice(1) : params['*'];
28
- if (!filename)
29
- return { message: "required param 'filename'", status: 400 };
30
- if (filename?.includes?.('..'))
31
- return { message: 'wrong params', status: 400 };
32
- /* const { security } = getSettings();
33
- const { enabled: externalAccess } = await pg.one('select enabled from admin.data_api where account_name = $1 and api_key = $2', { args: [account, key] });
34
- if ((sid === 35 && !isUser && !externalAccess)
35
- || (sid === 1
36
- && !allowedPublicDirs.some((dir) => filename?.includes?.(`${dir}/`))
37
- && !security?.public_dirs?.split(',')?.some((dir) => filename?.includes?.(`${dir}/`)))
38
- ) {
39
- return { error: 'Немає доступу', status: 403 };
40
- } */
41
- const filepath = filename.startsWith('files/')
27
+ export default async function download({ params, user }, reply) {
28
+ if (!params?.["*"]) {
29
+ return reply.status(400).send({ error: "not enough params", code: 400 });
30
+ }
31
+ const filename = params["*"].startsWith("/")
32
+ ? params["*"].slice(1)
33
+ : params["*"];
34
+ if (!filename) {
35
+ return reply
36
+ .status(400)
37
+ .send({ error: "required param 'filename'", code: 400 });
38
+ }
39
+ if (filename.includes?.("../")) {
40
+ return reply.status(403).send({ error: "wrong params", code: 403 });
41
+ }
42
+ const filepath = filename.startsWith("files/")
42
43
  ? filename
43
- : path.join('files', filename);
44
- // download
45
- const fp = providers({});
46
- const fileStream = await fp.downloadFile(filepath);
47
- if (!fileStream)
48
- return { error: `Файл не знайдено - ${filename}`, status: 404 };
44
+ : path.join("files", filename);
45
+ const hookData = await applyHook("preDownload", {
46
+ user,
47
+ relpath: filepath,
48
+ reply,
49
+ });
50
+ if (hookData)
51
+ return hookData;
52
+ const fileStream = await downloadFile(filepath);
53
+ if (!fileStream) {
54
+ return reply
55
+ .status(404)
56
+ .send({ error: `Файл не знайдено - ${filename}`, code: 404 });
57
+ }
49
58
  const headers = {
50
- 'Content-Disposition': `attachment; filename=${path.basename(filename)}`,
51
- 'Content-Type': getMimeType(filepath),
59
+ "Content-Disposition": `attachment; filename=${path.basename(filename)}`,
60
+ "Content-Type": getMimeType(filepath),
52
61
  };
62
+ logger.file("file/download", { filepath: params["*"], uid: user?.uid });
53
63
  reply.headers(headers);
54
64
  return fileStream;
55
65
  }
56
- export default download;
@@ -17,9 +17,10 @@ import type { FastifyReply } from "fastify";
17
17
  * @returns {Object} headers Заголовки HTTP
18
18
  * @returns {String} pipe Шлях до файла для скачування або відображення
19
19
  */
20
- export default function getFile({ params }: {
20
+ export default function getFile({ params, user }: {
21
21
  params: {
22
22
  "*": string;
23
23
  };
24
+ user?: Record<string, any>;
24
25
  }, reply: FastifyReply): Promise<any>;
25
26
  //# sourceMappingURL=files.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/files.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAU5C;;;;;;;;;;;;;;;;;GAiBG;AAEH,wBAA8B,OAAO,CACnC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,EACvC,KAAK,EAAE,YAAY,gBAgDpB"}
1
+ {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/files.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAW5C;;;;;;;;;;;;;;;;;GAiBG;AAEH,wBAA8B,OAAO,CACnC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE;IAAE,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAAE,EACzE,KAAK,EAAE,YAAY,gBAqDpB"}
@@ -2,7 +2,8 @@ import path from "node:path";
2
2
  import mime from "../../../plugins/file/providers/mime/index.js";
3
3
  import isFileExists from "../../../plugins/file/isFileExists.js";
4
4
  import downloadFile from "../../../plugins/file/downloadFile.js";
5
- import { applyHook } from "../../../../utils.js";
5
+ import logger from "../../../plugins/logger/getLogger.js";
6
+ import applyHook from "../../../plugins/hook/applyHook.js";
6
7
  /**
7
8
  * Апі використовується для отримання різних файлів і можливістю змінювати їх
8
9
  *
@@ -21,31 +22,33 @@ import { applyHook } from "../../../../utils.js";
21
22
  * @returns {Object} headers Заголовки HTTP
22
23
  * @returns {String} pipe Шлях до файла для скачування або відображення
23
24
  */
24
- export default async function getFile({ params }, reply) {
25
+ export default async function getFile({ params, user }, reply) {
25
26
  if (!params?.["*"]) {
26
- return { message: "not enough params", status: 400 };
27
+ return reply.status(400).send({ error: "not enough params", code: 400 });
27
28
  }
28
- if (params["*"]?.includes("../")) {
29
- return { message: "wrong params", status: 403 };
29
+ if (params["*"].includes("../")) {
30
+ return reply.status(403).send({ error: "wrong params", code: 403 });
30
31
  }
31
32
  const relpath = (params["*"].startsWith("/") ? params["*"].slice(1) : params["*"]).replace(/files\//g, "") + (params["*"].endsWith("/") ? "index.html" : "");
32
33
  if (!relpath) {
33
- return { message: "No required param 'filename'", status: 400 };
34
+ return reply
35
+ .status(400)
36
+ .send({ error: "required param 'filename'", code: 400 });
34
37
  }
35
- if (relpath.includes("..")) {
36
- return { message: "wrong params", status: 400 };
38
+ if (relpath.includes("../")) {
39
+ return reply.status(403).send({ error: "wrong params", code: 403 });
37
40
  }
38
- const hookData = await applyHook("preFile", { relpath, reply });
41
+ const hookData = await applyHook("preFile", { user, relpath, reply });
39
42
  if (hookData)
40
43
  return hookData;
41
44
  const filepath = path.join("files", relpath);
42
45
  const exists = await isFileExists(filepath);
43
46
  if (!exists) {
44
- return { message: "file not found", status: 404 };
47
+ return reply.status(404).send({ error: "Файл не знайдено", code: 404 });
45
48
  }
46
49
  const fileStream = await downloadFile(filepath);
47
50
  if (!fileStream) {
48
- return { message: "file not found", status: 404 };
51
+ return reply.status(404).send({ error: "Файл не знайдено", code: 404 });
49
52
  }
50
53
  const headers = {
51
54
  "Content-Disposition": `inline; filename=${path.basename(filepath)}`,
@@ -53,5 +56,6 @@ export default async function getFile({ params }, reply) {
53
56
  "Content-Type": `${mime(filepath)}`, // ; charset=utf-8 --- untested
54
57
  };
55
58
  reply.headers(headers);
59
+ logger.file("file/files", { filepath: params["*"], uid: user?.uid });
56
60
  return fileStream;
57
61
  }
@@ -2,7 +2,7 @@ import type { FastifyReply } from "fastify";
2
2
  /**
3
3
  * Апі використовується для зміни розміру фото за шляхом
4
4
  */
5
- export default function resize({ query, unittest, }: {
5
+ export default function resize({ query, }: {
6
6
  query: {
7
7
  filepath: string;
8
8
  quality?: string | number;
@@ -12,6 +12,5 @@ export default function resize({ query, unittest, }: {
12
12
  nocache?: any;
13
13
  format?: string;
14
14
  };
15
- unittest?: any;
16
15
  }, reply: FastifyReply): Promise<never>;
17
16
  //# sourceMappingURL=resize.d.ts.map
@@ -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;AA+B5C;;GAEG;AAEH,wBAA8B,MAAM,CAClC,EACE,KAAK,EACL,QAAQ,GACT,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;KACjB,CAAC;IACF,QAAQ,CAAC,EAAE,GAAG,CAAC;CAChB,EACD,KAAK,EAAE,YAAY,kBAsHpB"}
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;AA+B5C;;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;KACjB,CAAC;CACH,EACD,KAAK,EAAE,YAAY,kBAmIpB"}
@@ -18,15 +18,19 @@ const { resizeImage } = grpc();
18
18
  /**
19
19
  * Апі використовується для зміни розміру фото за шляхом
20
20
  */
21
- export default async function resize({ query, unittest, }, reply) {
21
+ export default async function resize({ query, }, reply) {
22
22
  const { filepath, quality, size, w, h, nocache, format } = query || {};
23
23
  if (!filepath) {
24
- return reply.status(400).send("not enough query params: filepath");
24
+ return reply
25
+ .status(400)
26
+ .send({ error: "not enough query params: filepath", code: 400 });
25
27
  }
26
28
  const basename = path.basename(filepath);
27
29
  const mimeType = getMimeType(filepath);
28
30
  if (!mimeType) {
29
- return reply.status(400).send("invalid query params: filepath");
31
+ return reply
32
+ .status(400)
33
+ .send({ error: "invalid query params: filepath", code: 400 });
30
34
  }
31
35
  const resizePath1 = size
32
36
  ? filepath.replace(basename, `${size}_resized_${basename}`)
@@ -43,7 +47,10 @@ export default async function resize({ query, unittest, }, reply) {
43
47
  const resizeData = fileExists
44
48
  ? await downloadFile(resizePath, { buffer: true })
45
49
  : null;
46
- if (resizeData && !config.disableCache && !nocache && !unittest) {
50
+ if (resizeData &&
51
+ !config.disableCache &&
52
+ !nocache &&
53
+ process.env.NODE_ENV !== "test") {
47
54
  return reply
48
55
  .headers({
49
56
  "Content-Type": format === "webp" ? "image/webp" : mimeType,
@@ -54,7 +61,9 @@ export default async function resize({ query, unittest, }, reply) {
54
61
  // get File Data
55
62
  const fileData = await downloadFile(filepath, { buffer: true });
56
63
  if (!fileData?.length) {
57
- return reply.status(404).send(`Файл не знайдено - ${filepath}`);
64
+ return reply
65
+ .status(404)
66
+ .send({ error: `Файл не знайдено - ${filepath}`, code: 400 });
58
67
  }
59
68
  const resizeQuality = Math.min(+(quality || 75), 100);
60
69
  const { width = defaultWidth, height = defaultHeight } = imageSize(fileData) || {};
@@ -63,7 +72,9 @@ export default async function resize({ query, unittest, }, reply) {
63
72
  .concat(w || "", h || "")
64
73
  .filter((el) => el && +el > maxWidth);
65
74
  if (check.length) {
66
- return reply.status(400).send({ message: "resize image size too big" });
75
+ return reply
76
+ .status(400)
77
+ .send({ error: "resize image size too big", code: 400 });
67
78
  }
68
79
  const resizeWidth = (h && !w ? +h * ratio : null) ||
69
80
  (size?.toLowerCase?.()?.split?.("x")?.[1] &&
@@ -1 +1 @@
1
- {"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/upload.ts"],"names":[],"mappings":"AAMA,wBAA8B,MAAM,CAAC,GAAG,EAAE,GAAG,eA0D5C"}
1
+ {"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/upload.ts"],"names":[],"mappings":"AAMA,wBAA8B,MAAM,CAAC,GAAG,EAAE,GAAG,eA4D5C"}
@@ -1,5 +1,5 @@
1
1
  import path from "node:path";
2
- import { applyHook, pgClients, dataInsert } from "../../../../utils.js";
2
+ import { logger, applyHook, pgClients, dataInsert } from "../../../../utils.js";
3
3
  import uploadMultiPart from "../../../plugins/file/uploadMultiPart.js";
4
4
  export default async function upload(req) {
5
5
  const { pg = pgClients.client } = req;
@@ -35,22 +35,23 @@ export default async function upload(req) {
35
35
  relativeDirpath: path.dirname(file.relativeFilepath || ""),
36
36
  fileName: file.newFilename,
37
37
  };
38
- // req.log.info('upload', { filepath: file?.filepath, uid: session.passport?.user?.uid });
38
+ logger.file("file/upload", {
39
+ filepath: file.relativeFilepath,
40
+ objectId,
41
+ uid: req.user?.uid,
42
+ });
39
43
  return {
40
- message: {
41
- res: "ok",
42
- name: file?.originalFilename,
43
- result: {
44
- file_id: resultInsert?.file_id,
45
- format: resultInsert?.ext || file.extension,
46
- size: resultInsert?.size || file?.size,
47
- entity_id: resultInsert?.entity_id,
48
- file_path: resultInsert?.file_path ||
49
- file?.relativeFilepath?.replace(/\\/g, "/"),
50
- file_name: file?.originalFilename?.toLocaleLowerCase?.(),
51
- dir: relativeDirpath?.replace?.(/\\/g, "/"),
52
- native_file_name: fileName,
53
- },
44
+ res: "ok",
45
+ name: file?.originalFilename,
46
+ result: {
47
+ file_id: resultInsert?.file_id,
48
+ format: resultInsert?.ext || file.extension,
49
+ size: resultInsert?.size || file?.size,
50
+ entity_id: resultInsert?.entity_id,
51
+ file_path: resultInsert?.file_path || file?.relativeFilepath?.replace(/\\/g, "/"),
52
+ file_name: file?.originalFilename?.toLocaleLowerCase?.(),
53
+ dir: relativeDirpath?.replace?.(/\\/g, "/"),
54
+ native_file_name: fileName,
54
55
  },
55
56
  };
56
57
  }
@@ -1,17 +1,15 @@
1
1
  export default function uploadImage(req: any): Promise<{
2
- message: {
3
- res: string;
4
- name: string | undefined;
5
- result: {
6
- file_id: any;
7
- format: any;
8
- size: any;
9
- entity_id: any;
10
- file_path: any;
11
- file_name: string | undefined;
12
- dir: string | undefined;
13
- native_file_name: string | undefined;
14
- };
2
+ res: string;
3
+ name: string | undefined;
4
+ result: {
5
+ file_id: any;
6
+ format: any;
7
+ size: any;
8
+ entity_id: any;
9
+ file_path: any;
10
+ file_name: string | undefined;
11
+ dir: string | undefined;
12
+ native_file_name: string | undefined;
15
13
  };
16
14
  }>;
17
15
  //# sourceMappingURL=uploadImage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"uploadImage.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/uploadImage.ts"],"names":[],"mappings":"AAMA,wBAA8B,WAAW,CAAC,GAAG,EAAE,GAAG;;;;;;;;;;;;;;;GA8CjD"}
1
+ {"version":3,"file":"uploadImage.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/uploadImage.ts"],"names":[],"mappings":"AAMA,wBAA8B,WAAW,CAAC,GAAG,EAAE,GAAG;;;;;;;;;;;;;GA4CjD"}
@@ -2,8 +2,8 @@ import path from "node:path";
2
2
  import { dataInsert, pgClients } from "../../../../utils.js";
3
3
  import uploadMultiPart from "../../../plugins/file/uploadMultiPart.js";
4
4
  export default async function uploadImage(req) {
5
- const { pg = pgClients.client } = req;
6
- const { uid = 1 } = req?.user || {};
5
+ const { pg = pgClients.client, user } = req;
6
+ const { uid = 1 } = user || {};
7
7
  const file = await uploadMultiPart(req);
8
8
  const objectId = req.params["*"]; // ID from token?
9
9
  const extName = path
@@ -27,19 +27,17 @@ export default async function uploadImage(req) {
27
27
  ? path.parse(resultInsert.file_path)
28
28
  : {};
29
29
  return {
30
- message: {
31
- res: "ok",
32
- name: file?.originalFilename,
33
- result: {
34
- file_id: resultInsert.file_id,
35
- format: resultInsert.ext || extName,
36
- size: resultInsert.size || file?.size,
37
- entity_id: resultInsert.entity_id,
38
- file_path: resultInsert.file_path || file?.relativeFilepath?.replace(/\\/g, "/"),
39
- file_name: file?.originalFilename?.toLocaleLowerCase?.(),
40
- dir: relativeDirpath?.replace(/\\/g, "/"),
41
- native_file_name: fileName,
42
- },
30
+ res: "ok",
31
+ name: file?.originalFilename,
32
+ result: {
33
+ file_id: resultInsert.file_id,
34
+ format: resultInsert.ext || extName,
35
+ size: resultInsert.size || file?.size,
36
+ entity_id: resultInsert.entity_id,
37
+ file_path: resultInsert.file_path || file?.relativeFilepath?.replace(/\\/g, "/"),
38
+ file_name: file?.originalFilename?.toLocaleLowerCase?.(),
39
+ dir: relativeDirpath?.replace(/\\/g, "/"),
40
+ native_file_name: fileName,
43
41
  },
44
42
  };
45
43
  }
@@ -30,7 +30,7 @@ export default async function loggerFile(req, reply) {
30
30
  }
31
31
  if (query.full && isFile) {
32
32
  if (stat.size > 20 * 1000 * 1000) {
33
- return { message: "file size > 20MB" };
33
+ return reply.status(400).send({ error: "file size > 20MB", code: 400 });
34
34
  }
35
35
  const buffer = await readFile(filepath);
36
36
  return buffer;
@@ -1,11 +1,5 @@
1
1
  import type { ExtendedPG } from "../../../types/core.js";
2
2
  export default function getInterfaces({ pg, }: {
3
3
  pg: ExtendedPG;
4
- }): Promise<{
5
- title: any;
6
- alias: any;
7
- table: any;
8
- route: any;
9
- enabled: any;
10
- }[]>;
4
+ }): Promise<any>;
11
5
  //# sourceMappingURL=interfaces.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../../../server/routes/menu/controllers/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAIzD,wBAA8B,aAAa,CAAC,EAC1C,EAAqB,GACtB,EAAE;IACD,EAAE,EAAE,UAAU,CAAC;CAChB;;;;;;KA6BA"}
1
+ {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../../../server/routes/menu/controllers/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAIzD,wBAA8B,aAAa,CAAC,EAC1C,EAAqB,GACtB,EAAE;IACD,EAAE,EAAE,UAAU,CAAC;CAChB,gBA6BA"}
@@ -1,2 +1,2 @@
1
- export default function card(req: any): Promise<{}>;
1
+ export default function card(req: any, reply: any): Promise<any>;
2
2
  //# sourceMappingURL=card.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"card.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/card.ts"],"names":[],"mappings":"AAQA,wBAA8B,IAAI,CAAC,GAAG,EAAE,GAAG,eAuH1C"}
1
+ {"version":3,"file":"card.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/card.ts"],"names":[],"mappings":"AASA,wBAA8B,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,gBAgItD"}