@opengis/fastify-table 2.0.106 → 2.0.108

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 (139) hide show
  1. package/dist/config.d.ts.map +1 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +5 -0
  4. package/dist/script/adduser +15 -0
  5. package/dist/script/dump.js +176 -0
  6. package/dist/script/migrate.js +25 -0
  7. package/dist/server/plugins/auth/funcs/verifyPassword.d.ts.map +1 -1
  8. package/dist/server/plugins/auth/funcs/verifyPassword.js +3 -1
  9. package/dist/server/plugins/crud/funcs/dataInsert.js +2 -2
  10. package/dist/server/plugins/crud/funcs/dataUpdate.d.ts.map +1 -1
  11. package/dist/server/plugins/crud/funcs/dataUpdate.js +9 -6
  12. package/dist/server/plugins/crud/funcs/validateData.js +1 -1
  13. package/dist/server/plugins/file/providers/fs.js +2 -2
  14. package/dist/server/plugins/file/providers/s3/funcs/downloadFile.d.ts.map +1 -1
  15. package/dist/server/plugins/file/providers/s3/funcs/downloadFile.js +1 -2
  16. package/dist/server/plugins/file/providers/s3/funcs/fileExists.d.ts.map +1 -1
  17. package/dist/server/plugins/file/providers/s3/funcs/fileExists.js +1 -2
  18. package/dist/server/plugins/file/providers/s3/funcs/uploadFile.d.ts.map +1 -1
  19. package/dist/server/plugins/file/providers/s3/funcs/uploadFile.js +1 -2
  20. package/dist/server/plugins/file/providers/s3/index.js +4 -4
  21. package/dist/server/plugins/logger/getLogger.d.ts.map +1 -1
  22. package/dist/server/plugins/logger/getLogger.js +14 -11
  23. package/dist/server/plugins/logger/index.d.ts.map +1 -1
  24. package/dist/server/plugins/logger/index.js +5 -4
  25. package/dist/server/plugins/migration/exec.migrations.js +6 -6
  26. package/dist/server/plugins/pg/funcs/getMeta.d.ts.map +1 -1
  27. package/dist/server/plugins/pg/funcs/getMeta.js +3 -5
  28. package/dist/server/plugins/pg/funcs/getPG.d.ts.map +1 -1
  29. package/dist/server/plugins/pg/funcs/getPG.js +2 -1
  30. package/dist/server/plugins/pg/funcs/getPGAsync.js +2 -2
  31. package/dist/server/plugins/pg/funcs/init.d.ts +1 -1
  32. package/dist/server/plugins/pg/funcs/init.d.ts.map +1 -1
  33. package/dist/server/plugins/pg/funcs/init.js +43 -36
  34. package/dist/server/plugins/pg/funcs/pool.d.ts.map +1 -1
  35. package/dist/server/plugins/pg/funcs/pool.js +12 -18
  36. package/dist/server/plugins/pg/index.d.ts.map +1 -1
  37. package/dist/server/plugins/pg/index.js +3 -2
  38. package/dist/server/plugins/redis/funcs/getRedis.d.ts.map +1 -1
  39. package/dist/server/plugins/redis/funcs/getRedis.js +7 -5
  40. package/dist/server/plugins/redis/index.d.ts.map +1 -1
  41. package/dist/server/plugins/redis/index.js +4 -1
  42. package/dist/server/plugins/sqlite/index.d.ts.map +1 -1
  43. package/dist/server/plugins/sqlite/index.js +7 -3
  44. package/dist/server/plugins/table/funcs/getFilter.d.ts +1 -1
  45. package/dist/server/plugins/table/funcs/getFilter.d.ts.map +1 -1
  46. package/dist/server/plugins/table/funcs/getFilter.js +14 -1
  47. package/dist/server/plugins/table/funcs/getSelectMeta.d.ts.map +1 -1
  48. package/dist/server/plugins/table/funcs/getSelectMeta.js +2 -4
  49. package/dist/server/plugins/table/funcs/gisIRColumn.d.ts +2 -2
  50. package/dist/server/plugins/table/funcs/gisIRColumn.js +1 -1
  51. package/dist/server/plugins/upload/finishUpload.d.ts +9 -0
  52. package/dist/server/plugins/upload/finishUpload.d.ts.map +1 -0
  53. package/dist/server/plugins/upload/finishUpload.js +33 -0
  54. package/dist/server/plugins/upload/getUploadStatus.d.ts +5 -0
  55. package/dist/server/plugins/upload/getUploadStatus.d.ts.map +1 -0
  56. package/dist/server/plugins/upload/getUploadStatus.js +36 -0
  57. package/dist/server/plugins/upload/index.d.ts +6 -0
  58. package/dist/server/plugins/upload/index.d.ts.map +1 -0
  59. package/dist/server/plugins/upload/index.js +12 -0
  60. package/dist/server/plugins/upload/startUpload.d.ts +8 -0
  61. package/dist/server/plugins/upload/startUpload.d.ts.map +1 -0
  62. package/dist/server/plugins/upload/startUpload.js +53 -0
  63. package/dist/server/plugins/upload/uploadChunk.d.ts +9 -0
  64. package/dist/server/plugins/upload/uploadChunk.d.ts.map +1 -0
  65. package/dist/server/plugins/upload/uploadChunk.js +47 -0
  66. package/dist/server/plugins/util/funcs/unflattenObject.d.ts.map +1 -1
  67. package/dist/server/plugins/util/funcs/unflattenObject.js +5 -3
  68. package/dist/server/routes/access/controllers/access.group.d.ts +2 -2
  69. package/dist/server/routes/access/controllers/access.group.d.ts.map +1 -1
  70. package/dist/server/routes/access/controllers/access.group.js +0 -1
  71. package/dist/server/routes/access/controllers/access.group.post.d.ts +2 -2
  72. package/dist/server/routes/access/controllers/access.group.post.d.ts.map +1 -1
  73. package/dist/server/routes/access/controllers/access.group.post.js +0 -1
  74. package/dist/server/routes/auth/controllers/2factor/providers/totp.d.ts.map +1 -1
  75. package/dist/server/routes/auth/controllers/2factor/providers/totp.js +1 -1
  76. package/dist/server/routes/auth/controllers/core/registration.d.ts +1 -1
  77. package/dist/server/routes/auth/controllers/core/registration.d.ts.map +1 -1
  78. package/dist/server/routes/auth/controllers/core/registration.js +37 -9
  79. package/dist/server/routes/auth/controllers/core/updateUserInfo.js +1 -1
  80. package/dist/server/routes/auth/controllers/jwt/authorize.js +5 -5
  81. package/dist/server/routes/auth/controllers/jwt/token.d.ts.map +1 -1
  82. package/dist/server/routes/auth/controllers/jwt/token.js +10 -12
  83. package/dist/server/routes/cron/controllers/cronApi.d.ts +1 -1
  84. package/dist/server/routes/cron/controllers/cronApi.d.ts.map +1 -1
  85. package/dist/server/routes/cron/controllers/cronApi.js +5 -3
  86. package/dist/server/routes/crud/controllers/insert.d.ts +1 -4
  87. package/dist/server/routes/crud/controllers/insert.d.ts.map +1 -1
  88. package/dist/server/routes/crud/controllers/insert.js +24 -16
  89. package/dist/server/routes/crud/controllers/table.d.ts.map +1 -1
  90. package/dist/server/routes/crud/controllers/table.js +13 -6
  91. package/dist/server/routes/crud/controllers/update.d.ts.map +1 -1
  92. package/dist/server/routes/crud/controllers/update.js +23 -15
  93. package/dist/server/routes/file/controllers/delete.d.ts +1 -15
  94. package/dist/server/routes/file/controllers/delete.d.ts.map +1 -1
  95. package/dist/server/routes/file/controllers/delete.js +13 -20
  96. package/dist/server/routes/file/controllers/download.d.ts +2 -2
  97. package/dist/server/routes/file/controllers/download.d.ts.map +1 -1
  98. package/dist/server/routes/file/controllers/download.js +39 -30
  99. package/dist/server/routes/file/controllers/files.d.ts +2 -1
  100. package/dist/server/routes/file/controllers/files.d.ts.map +1 -1
  101. package/dist/server/routes/file/controllers/files.js +15 -11
  102. package/dist/server/routes/file/controllers/resize.d.ts +1 -2
  103. package/dist/server/routes/file/controllers/resize.d.ts.map +1 -1
  104. package/dist/server/routes/file/controllers/resize.js +17 -6
  105. package/dist/server/routes/file/controllers/upload.d.ts.map +1 -1
  106. package/dist/server/routes/file/controllers/upload.js +17 -16
  107. package/dist/server/routes/file/controllers/uploadImage.d.ts +11 -13
  108. package/dist/server/routes/file/controllers/uploadImage.d.ts.map +1 -1
  109. package/dist/server/routes/file/controllers/uploadImage.js +13 -15
  110. package/dist/server/routes/logger/controllers/logger.file.js +1 -1
  111. package/dist/server/routes/menu/controllers/interfaces.d.ts +1 -7
  112. package/dist/server/routes/menu/controllers/interfaces.d.ts.map +1 -1
  113. package/dist/server/routes/table/controllers/card.d.ts +1 -1
  114. package/dist/server/routes/table/controllers/card.d.ts.map +1 -1
  115. package/dist/server/routes/table/controllers/card.js +15 -9
  116. package/dist/server/routes/table/controllers/filter.d.ts +1 -1
  117. package/dist/server/routes/table/controllers/filter.d.ts.map +1 -1
  118. package/dist/server/routes/table/controllers/filter.js +9 -2
  119. package/dist/server/routes/table/controllers/form.d.ts +1 -1
  120. package/dist/server/routes/table/controllers/form.d.ts.map +1 -1
  121. package/dist/server/routes/table/controllers/form.js +8 -5
  122. package/dist/server/routes/table/controllers/search.d.ts +1 -1
  123. package/dist/server/routes/table/controllers/search.d.ts.map +1 -1
  124. package/dist/server/routes/table/controllers/search.js +5 -6
  125. package/dist/server/routes/table/controllers/suggest.d.ts +1 -1
  126. package/dist/server/routes/table/controllers/suggest.d.ts.map +1 -1
  127. package/dist/server/routes/table/controllers/suggest.js +30 -15
  128. package/dist/server/routes/table/functions/getData.d.ts +1 -1
  129. package/dist/server/routes/table/functions/getData.d.ts.map +1 -1
  130. package/dist/server/routes/table/functions/getData.js +60 -45
  131. package/dist/server/routes/upload/index.d.ts +2 -0
  132. package/dist/server/routes/upload/index.d.ts.map +1 -0
  133. package/dist/server/routes/upload/index.js +72 -0
  134. package/dist/server/types/core.d.ts +7 -1
  135. package/dist/server/types/core.d.ts.map +1 -1
  136. package/dist/utils.d.ts +5 -0
  137. package/dist/utils.d.ts.map +1 -1
  138. package/dist/utils.js +5 -0
  139. package/package.json +3 -3
@@ -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"}
@@ -1,14 +1,17 @@
1
- import { getTemplate, getMeta, metaFormat, getAccess, applyHook, } from "../../../../utils.js";
2
- export default async function card(req) {
1
+ import { getTemplate, getMeta, metaFormat, getAccess, applyHook, pgClients, } from "../../../../utils.js";
2
+ export default async function card(req, reply) {
3
3
  const time = Date.now();
4
- const { pg, user, params = {}, query = {} } = req;
4
+ const { pg = pgClients.client, user, params = {}, query = {} } = req;
5
5
  const hookData = (await applyHook("preCard", {
6
6
  table: params?.table,
7
7
  id: params?.id,
8
8
  user,
9
9
  }));
10
10
  if (hookData?.message && hookData?.status) {
11
- return { message: hookData?.message, status: hookData?.status };
11
+ const response = hookData.status >= 400
12
+ ? { error: hookData.message, code: hookData.status }
13
+ : hookData.message;
14
+ return reply.status(hookData.status).send(response);
12
15
  }
13
16
  const { actions = [], scope, my, } = (await getAccess({
14
17
  table: hookData?.table || params.table,
@@ -16,16 +19,17 @@ export default async function card(req) {
16
19
  user,
17
20
  })) || {};
18
21
  if (!actions.includes("view") || (scope === "my" && !my)) {
19
- return { message: "access restricted", status: 403 };
22
+ return reply.status(403).send({ error: "access restricted", code: 403 });
20
23
  }
21
24
  const loadTable = await getTemplate("table", hookData?.table || params.table);
22
25
  if (!loadTable) {
23
- return { message: "template not found", status: 404 };
26
+ return reply.status(404).send({ error: "table not found", code: 404 });
24
27
  }
25
28
  const { table, columns, meta, sql, cardSql } = loadTable;
26
29
  const { pk, columns: dbColumns = [] } = await getMeta(table);
27
- if (!pk)
28
- return { message: `table not found: ${table}`, status: 404 };
30
+ if (!pk) {
31
+ return reply.status(404).send({ error: "table pk not found", code: 404 });
32
+ }
29
33
  const cols = columns.map((el) => el.name || el).join(",");
30
34
  const sqlTable = sql
31
35
  ?.filter?.((el) => !el?.disabled && el?.sql?.replace)
@@ -50,7 +54,9 @@ export default async function card(req) {
50
54
  if (query.sql === "1") {
51
55
  return q;
52
56
  }
53
- const { rows } = await pg.query(q, [hookData?.id || params.id]);
57
+ const rows = await pg
58
+ .query(q, [hookData?.id || params.id])
59
+ .then((el) => el.rows || []);
54
60
  await metaFormat({ rows, table: hookData?.table || params.table });
55
61
  const data = meta?.card?.length
56
62
  ? meta.card
@@ -5,7 +5,7 @@ interface IFilter {
5
5
  inline?: any[] | undefined;
6
6
  state?: any[] | undefined;
7
7
  }
8
- export default function filterAPI(req: any, reply: any, iscalled: any): Promise<IFilter | {
8
+ export default function filterAPI(req: any, reply: any, iscalled: number | boolean | undefined | null): Promise<IFilter | {
9
9
  message: string;
10
10
  status: number;
11
11
  } | string | any>;
@@ -1 +1 @@
1
- {"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/filter.ts"],"names":[],"mappings":"AAWA,UAAU,OAAO;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC;IAC3B,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC;IAC3B,KAAK,CAAC,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC;CAC3B;AAED,wBAA8B,SAAS,CACrC,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,GAAG,EACV,QAAQ,EAAE,GAAG,GACZ,OAAO,CAAC,OAAO,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,GAAG,GAAG,CAAC,CA6RvE"}
1
+ {"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/filter.ts"],"names":[],"mappings":"AAaA,UAAU,OAAO;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC;IAC3B,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC;IAC3B,KAAK,CAAC,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC;CAC3B;AAED,wBAA8B,SAAS,CACrC,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,GAAG,EACV,QAAQ,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,IAAI,GAC5C,OAAO,CAAC,OAAO,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,GAAG,GAAG,CAAC,CAoSvE"}