@opengis/fastify-table 2.0.105 → 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.
- package/dist/config.d.ts.map +1 -1
- package/dist/script/adduser +15 -0
- package/dist/script/dump.js +176 -0
- package/dist/script/migrate.js +25 -0
- package/dist/server/migrations/users.sql +1 -1
- package/dist/server/plugins/auth/funcs/verifyPassword.d.ts.map +1 -1
- package/dist/server/plugins/auth/funcs/verifyPassword.js +3 -1
- package/dist/server/plugins/crud/funcs/dataInsert.js +1 -1
- package/dist/server/plugins/crud/funcs/dataUpdate.d.ts.map +1 -1
- package/dist/server/plugins/crud/funcs/dataUpdate.js +7 -4
- package/dist/server/plugins/file/providers/s3/client.d.ts +12 -4
- package/dist/server/plugins/file/providers/s3/client.d.ts.map +1 -1
- package/dist/server/plugins/file/providers/s3/client.js +21 -15
- package/dist/server/plugins/file/providers/s3/funcs/downloadFile.d.ts +1 -1
- package/dist/server/plugins/file/providers/s3/funcs/downloadFile.d.ts.map +1 -1
- package/dist/server/plugins/file/providers/s3/funcs/downloadFile.js +9 -4
- package/dist/server/plugins/file/providers/s3/funcs/fileExists.d.ts +1 -1
- package/dist/server/plugins/file/providers/s3/funcs/fileExists.d.ts.map +1 -1
- package/dist/server/plugins/file/providers/s3/funcs/fileExists.js +13 -10
- package/dist/server/plugins/file/providers/s3/funcs/uploadFile.d.ts +1 -1
- package/dist/server/plugins/file/providers/s3/funcs/uploadFile.d.ts.map +1 -1
- package/dist/server/plugins/file/providers/s3/funcs/uploadFile.js +4 -4
- package/dist/server/plugins/file/providers/s3/funcs/utils/getS3FilePath.d.ts +1 -1
- package/dist/server/plugins/file/providers/s3/funcs/utils/getS3FilePath.d.ts.map +1 -1
- package/dist/server/plugins/file/providers/s3/funcs/utils/getS3FilePath.js +1 -1
- package/dist/server/plugins/file/providers/s3/index.d.ts +1 -1
- package/dist/server/plugins/logger/getLogger.d.ts.map +1 -1
- package/dist/server/plugins/logger/getLogger.js +13 -10
- package/dist/server/plugins/logger/index.d.ts.map +1 -1
- package/dist/server/plugins/logger/index.js +7 -3
- package/dist/server/plugins/pg/funcs/getPG.d.ts.map +1 -1
- package/dist/server/plugins/pg/funcs/getPG.js +1 -0
- package/dist/server/plugins/pg/funcs/getPGAsync.js +1 -1
- package/dist/server/plugins/pg/funcs/init.d.ts +1 -1
- package/dist/server/plugins/pg/funcs/init.d.ts.map +1 -1
- package/dist/server/plugins/pg/funcs/init.js +20 -5
- package/dist/server/plugins/pg/funcs/pool.d.ts.map +1 -1
- package/dist/server/plugins/pg/funcs/pool.js +10 -16
- package/dist/server/plugins/pg/index.d.ts.map +1 -1
- package/dist/server/plugins/pg/index.js +3 -2
- package/dist/server/plugins/redis/funcs/getRedis.d.ts.map +1 -1
- package/dist/server/plugins/redis/funcs/getRedis.js +6 -4
- package/dist/server/plugins/redis/index.d.ts.map +1 -1
- package/dist/server/plugins/redis/index.js +4 -1
- package/dist/server/plugins/sqlite/index.d.ts.map +1 -1
- package/dist/server/plugins/sqlite/index.js +7 -3
- package/dist/server/plugins/table/funcs/getFilter.d.ts +1 -1
- package/dist/server/plugins/table/funcs/getFilter.d.ts.map +1 -1
- package/dist/server/plugins/table/funcs/getFilter.js +14 -1
- package/dist/server/plugins/table/funcs/getSelectMeta.d.ts +4 -2
- package/dist/server/plugins/table/funcs/getSelectMeta.d.ts.map +1 -1
- package/dist/server/plugins/table/funcs/getSelectMeta.js +21 -7
- package/dist/server/plugins/table/funcs/gisIRColumn.d.ts +2 -2
- package/dist/server/plugins/table/funcs/gisIRColumn.js +1 -1
- package/dist/server/plugins/util/funcs/unflattenObject.d.ts.map +1 -1
- package/dist/server/plugins/util/funcs/unflattenObject.js +3 -1
- package/dist/server/routes/access/controllers/access.group.d.ts +2 -2
- package/dist/server/routes/access/controllers/access.group.d.ts.map +1 -1
- package/dist/server/routes/access/controllers/access.group.js +0 -1
- package/dist/server/routes/access/controllers/access.group.post.d.ts +2 -2
- package/dist/server/routes/access/controllers/access.group.post.d.ts.map +1 -1
- package/dist/server/routes/access/controllers/access.group.post.js +0 -1
- package/dist/server/routes/auth/controllers/core/registration.d.ts +1 -4
- package/dist/server/routes/auth/controllers/core/registration.d.ts.map +1 -1
- package/dist/server/routes/auth/controllers/core/registration.js +28 -9
- package/dist/server/routes/auth/controllers/core/updateUserInfo.js +1 -1
- package/dist/server/routes/auth/controllers/jwt/authorize.js +5 -5
- package/dist/server/routes/auth/controllers/jwt/token.d.ts.map +1 -1
- package/dist/server/routes/auth/controllers/jwt/token.js +10 -12
- package/dist/server/routes/cron/controllers/cronApi.d.ts +1 -1
- package/dist/server/routes/cron/controllers/cronApi.d.ts.map +1 -1
- package/dist/server/routes/cron/controllers/cronApi.js +5 -3
- package/dist/server/routes/crud/controllers/insert.d.ts +1 -4
- package/dist/server/routes/crud/controllers/insert.d.ts.map +1 -1
- package/dist/server/routes/crud/controllers/insert.js +24 -16
- package/dist/server/routes/crud/controllers/table.d.ts.map +1 -1
- package/dist/server/routes/crud/controllers/table.js +13 -6
- package/dist/server/routes/crud/controllers/update.d.ts.map +1 -1
- package/dist/server/routes/crud/controllers/update.js +23 -15
- package/dist/server/routes/file/controllers/delete.d.ts +1 -15
- package/dist/server/routes/file/controllers/delete.d.ts.map +1 -1
- package/dist/server/routes/file/controllers/delete.js +13 -20
- package/dist/server/routes/file/controllers/download.d.ts +2 -2
- package/dist/server/routes/file/controllers/download.d.ts.map +1 -1
- package/dist/server/routes/file/controllers/download.js +39 -30
- package/dist/server/routes/file/controllers/files.d.ts +2 -1
- package/dist/server/routes/file/controllers/files.d.ts.map +1 -1
- package/dist/server/routes/file/controllers/files.js +15 -11
- package/dist/server/routes/file/controllers/resize.d.ts +1 -2
- package/dist/server/routes/file/controllers/resize.d.ts.map +1 -1
- package/dist/server/routes/file/controllers/resize.js +17 -6
- package/dist/server/routes/file/controllers/upload.d.ts.map +1 -1
- package/dist/server/routes/file/controllers/upload.js +17 -16
- package/dist/server/routes/file/controllers/uploadImage.d.ts +11 -13
- package/dist/server/routes/file/controllers/uploadImage.d.ts.map +1 -1
- package/dist/server/routes/file/controllers/uploadImage.js +13 -15
- package/dist/server/routes/logger/controllers/logger.file.js +1 -1
- package/dist/server/routes/menu/controllers/interfaces.d.ts +1 -7
- package/dist/server/routes/menu/controllers/interfaces.d.ts.map +1 -1
- package/dist/server/routes/table/controllers/card.d.ts +1 -1
- package/dist/server/routes/table/controllers/card.d.ts.map +1 -1
- package/dist/server/routes/table/controllers/card.js +15 -9
- package/dist/server/routes/table/controllers/filter.d.ts +1 -1
- package/dist/server/routes/table/controllers/filter.d.ts.map +1 -1
- package/dist/server/routes/table/controllers/filter.js +2 -2
- package/dist/server/routes/table/controllers/form.d.ts +1 -1
- package/dist/server/routes/table/controllers/form.d.ts.map +1 -1
- package/dist/server/routes/table/controllers/form.js +8 -5
- package/dist/server/routes/table/controllers/search.d.ts +1 -1
- package/dist/server/routes/table/controllers/search.d.ts.map +1 -1
- package/dist/server/routes/table/controllers/search.js +5 -6
- package/dist/server/routes/table/controllers/suggest.d.ts +1 -1
- package/dist/server/routes/table/controllers/suggest.d.ts.map +1 -1
- package/dist/server/routes/table/controllers/suggest.js +53 -24
- package/dist/server/routes/table/functions/getData.d.ts +1 -1
- package/dist/server/routes/table/functions/getData.d.ts.map +1 -1
- package/dist/server/routes/table/functions/getData.js +60 -34
- package/dist/server/routes/util/controllers/config.d.ts +2 -0
- package/dist/server/routes/util/controllers/config.d.ts.map +1 -0
- package/dist/server/routes/util/controllers/config.js +33 -0
- package/dist/server/routes/util/index.js +2 -2
- package/dist/server/types/core.d.ts +7 -0
- package/dist/server/types/core.d.ts.map +1 -1
- package/dist/utils.d.ts +1 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -0
- package/package.json +3 -3
|
@@ -14,19 +14,17 @@ export default async function oauthToken(req, reply) {
|
|
|
14
14
|
const payload = req.method === "POST" ? body : query;
|
|
15
15
|
const { grant_type, client_id, code, redirect_uri, code_verifier } = payload;
|
|
16
16
|
if (grant_type !== "authorization_code") {
|
|
17
|
-
return reply
|
|
18
|
-
.code(400)
|
|
19
|
-
.send({ message: "unsupported grant_type", code: 400 });
|
|
17
|
+
return reply.code(400).send({ error: "unsupported grant_type", code: 400 });
|
|
20
18
|
}
|
|
21
19
|
if (!client_id) {
|
|
22
20
|
return reply
|
|
23
21
|
.code(400)
|
|
24
|
-
.send({
|
|
22
|
+
.send({ error: "not enough params: client_id", code: 400 });
|
|
25
23
|
}
|
|
26
24
|
if (!code) {
|
|
27
25
|
return reply
|
|
28
26
|
.code(400)
|
|
29
|
-
.send({
|
|
27
|
+
.send({ error: "not enough params: code", code: 400 });
|
|
30
28
|
}
|
|
31
29
|
const q = `select owner_user_id, client_secret_hash, redirect_uris from oauth.clients where client_id=$1 and token_endpoint_auth_method=$2`;
|
|
32
30
|
const { owner_user_id: userId, client_secret_hash: secret, redirect_uris = [], } = pg.pk?.["oauth.clients"]
|
|
@@ -41,31 +39,31 @@ export default async function oauthToken(req, reply) {
|
|
|
41
39
|
if (storedIp !== ip) {
|
|
42
40
|
return reply
|
|
43
41
|
.code(403)
|
|
44
|
-
.send({
|
|
42
|
+
.send({ error: "access restricted: wrong IP address", code: 403 });
|
|
45
43
|
}
|
|
46
44
|
if (!stored) {
|
|
47
45
|
return reply
|
|
48
46
|
.code(403)
|
|
49
|
-
.send({
|
|
47
|
+
.send({ error: "access restricted: code expired", code: 403 });
|
|
50
48
|
}
|
|
51
49
|
const isValid = await scryptVerify(stored, code);
|
|
52
50
|
if (!isValid) {
|
|
53
51
|
return reply
|
|
54
52
|
.code(403)
|
|
55
|
-
.send({
|
|
53
|
+
.send({ error: "access restricted: stored code mismatch", code: 403 });
|
|
56
54
|
}
|
|
57
55
|
if (!isCodeValid) {
|
|
58
56
|
return reply
|
|
59
57
|
.code(403)
|
|
60
|
-
.send({
|
|
58
|
+
.send({ error: "access restricted: invalid code", code: 403 });
|
|
61
59
|
}
|
|
62
60
|
if (!userId) {
|
|
63
|
-
return reply.code(400).send({
|
|
61
|
+
return reply.code(400).send({ error: "invalid client id", code: 400 });
|
|
64
62
|
}
|
|
65
63
|
if (redirect_uri &&
|
|
66
64
|
Array.isArray(redirect_uris) &&
|
|
67
65
|
!redirect_uris.includes(redirect_uri)) {
|
|
68
|
-
return reply.code(400).send({
|
|
66
|
+
return reply.code(400).send({ error: "invalid redirect_uri", code: 400 });
|
|
69
67
|
}
|
|
70
68
|
const user = pg.pk?.["admin.users"]
|
|
71
69
|
? await pg
|
|
@@ -75,7 +73,7 @@ export default async function oauthToken(req, reply) {
|
|
|
75
73
|
.then((el) => el.rows[0])
|
|
76
74
|
: null;
|
|
77
75
|
if (!user) {
|
|
78
|
-
return reply.code(404).send({
|
|
76
|
+
return reply.code(404).send({ error: "user not found", code: 404 });
|
|
79
77
|
}
|
|
80
78
|
const expire = expires_at ? expires_at - Date.now() : expireMsec;
|
|
81
79
|
const href1 = await authorizeUser(user, req, "jwt", expire);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export default function cronApi(req: any): Promise<any>;
|
|
1
|
+
export default function cronApi(req: any, reply: any): Promise<any>;
|
|
2
2
|
//# sourceMappingURL=cronApi.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cronApi.d.ts","sourceRoot":"","sources":["../../../../../server/routes/cron/controllers/cronApi.ts"],"names":[],"mappings":"AAEA,wBAA8B,OAAO,CAAC,GAAG,EAAE,GAAG,
|
|
1
|
+
{"version":3,"file":"cronApi.d.ts","sourceRoot":"","sources":["../../../../../server/routes/cron/controllers/cronApi.ts"],"names":[],"mappings":"AAEA,wBAA8B,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,gBAsBzD"}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import cronList from "../../../plugins/cron/cronList.js";
|
|
2
|
-
export default async function cronApi(req) {
|
|
2
|
+
export default async function cronApi(req, reply) {
|
|
3
3
|
const { params = {}, user = {}, hostname } = req;
|
|
4
4
|
if ((!user.uid || !user.user_type?.includes("admin")) &&
|
|
5
5
|
!hostname?.includes("local")) {
|
|
6
|
-
return {
|
|
6
|
+
return reply.status(403).send({ error: "access restricted", code: 403 });
|
|
7
7
|
}
|
|
8
8
|
if (params.name === "list") {
|
|
9
9
|
return { data: Object.keys(cronList || {}) };
|
|
10
10
|
}
|
|
11
11
|
if (!cronList[params.name]) {
|
|
12
|
-
return
|
|
12
|
+
return reply
|
|
13
|
+
.status(404)
|
|
14
|
+
.send({ error: `cron not found: ${params.name}`, code: 404 });
|
|
13
15
|
}
|
|
14
16
|
const result = await cronList[params.name]?.(req);
|
|
15
17
|
return result;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
import { type FastifyReply } from "fastify";
|
|
2
|
-
export default function insert(req: any, reply: FastifyReply): Promise<
|
|
3
|
-
message: string;
|
|
4
|
-
status: number;
|
|
5
|
-
}>;
|
|
2
|
+
export default function insert(req: any, reply: FastifyReply): Promise<never>;
|
|
6
3
|
//# sourceMappingURL=insert.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insert.d.ts","sourceRoot":"","sources":["../../../../../server/routes/crud/controllers/insert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,SAAS,CAAC;AAgB5C,wBAA8B,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,YAAY
|
|
1
|
+
{"version":3,"file":"insert.d.ts","sourceRoot":"","sources":["../../../../../server/routes/crud/controllers/insert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,SAAS,CAAC;AAgB5C,wBAA8B,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,YAAY,kBA4KjE"}
|
|
@@ -2,7 +2,7 @@ import { applyHook, getAccess, getTemplate, checkXSS, checkSQL, dataInsert, getT
|
|
|
2
2
|
export default async function insert(req, reply) {
|
|
3
3
|
const { pg = pgClients.client, user = {}, params = {}, body = {}, headers = {}, } = req || {};
|
|
4
4
|
if (!user) {
|
|
5
|
-
return reply.status(403).send("access restricted");
|
|
5
|
+
return reply.status(403).send({ error: "access restricted", code: 403 });
|
|
6
6
|
}
|
|
7
7
|
const hookData = (await applyHook("preInsert", {
|
|
8
8
|
pg,
|
|
@@ -11,7 +11,10 @@ export default async function insert(req, reply) {
|
|
|
11
11
|
body,
|
|
12
12
|
}));
|
|
13
13
|
if (hookData?.message && hookData?.status) {
|
|
14
|
-
|
|
14
|
+
const response = hookData.status >= 400
|
|
15
|
+
? { error: hookData.message, code: hookData.status }
|
|
16
|
+
: hookData.message;
|
|
17
|
+
return reply.status(hookData.status).send(response);
|
|
15
18
|
}
|
|
16
19
|
const { referer } = headers;
|
|
17
20
|
const tokenData = await getToken({
|
|
@@ -30,18 +33,20 @@ export default async function insert(req, reply) {
|
|
|
30
33
|
!config.local &&
|
|
31
34
|
!config.security?.disableToken &&
|
|
32
35
|
!config.auth?.disable) {
|
|
33
|
-
return reply.status(400).send("invalid token");
|
|
36
|
+
return reply.status(400).send({ error: "invalid token", code: 400 });
|
|
34
37
|
}
|
|
35
38
|
if (!actions.includes("add") && !config.local && !tokenData) {
|
|
36
|
-
return reply
|
|
39
|
+
return reply
|
|
40
|
+
.status(403)
|
|
41
|
+
.send({ error: "access restricted: actions", code: 403 });
|
|
37
42
|
}
|
|
38
43
|
if (!add) {
|
|
39
|
-
return reply.status(400).send("table is required");
|
|
44
|
+
return reply.status(400).send({ error: "table is required", code: 400 });
|
|
40
45
|
}
|
|
41
46
|
const loadTemplate = await getTemplate("table", add);
|
|
42
47
|
const { table } = loadTemplate || hookData || tokenData || req.params || {};
|
|
43
48
|
if (!table) {
|
|
44
|
-
return reply.status(404).send("table not found");
|
|
49
|
+
return reply.status(404).send({ error: "table not found", code: 404 });
|
|
45
50
|
}
|
|
46
51
|
const formData = form || loadTemplate?.form
|
|
47
52
|
? (await getTemplate("form", form || loadTemplate?.form)) || {}
|
|
@@ -56,9 +61,10 @@ export default async function insert(req, reply) {
|
|
|
56
61
|
uid: user?.uid,
|
|
57
62
|
msg: xssCheck.error,
|
|
58
63
|
});
|
|
59
|
-
return reply
|
|
60
|
-
|
|
61
|
-
|
|
64
|
+
return reply.status(409).send({
|
|
65
|
+
error: "Дані містять заборонені символи. Приберіть їх та спробуйте ще раз",
|
|
66
|
+
code: 409,
|
|
67
|
+
});
|
|
62
68
|
}
|
|
63
69
|
const fieldCheck = validateData({ body, schema });
|
|
64
70
|
if (fieldCheck.error) {
|
|
@@ -68,9 +74,10 @@ export default async function insert(req, reply) {
|
|
|
68
74
|
uid: user?.uid,
|
|
69
75
|
...fieldCheck,
|
|
70
76
|
});
|
|
71
|
-
return reply
|
|
72
|
-
|
|
73
|
-
|
|
77
|
+
return reply.status(409).send({
|
|
78
|
+
error: "Дані не пройшли валідацію. Приберіть некоректні дані та спробуйте ще раз",
|
|
79
|
+
code: 409,
|
|
80
|
+
});
|
|
74
81
|
}
|
|
75
82
|
const sqlCheck = checkSQL({ body, schema });
|
|
76
83
|
if (sqlCheck.error) {
|
|
@@ -80,9 +87,10 @@ export default async function insert(req, reply) {
|
|
|
80
87
|
uid: user?.uid,
|
|
81
88
|
...sqlCheck,
|
|
82
89
|
});
|
|
83
|
-
return reply
|
|
84
|
-
|
|
85
|
-
|
|
90
|
+
return reply.status(409).send({
|
|
91
|
+
error: "Дані містять заборонені sql символи. Приберіть їх та спробуйте ще раз",
|
|
92
|
+
code: 409,
|
|
93
|
+
});
|
|
86
94
|
}
|
|
87
95
|
if (![add, table].includes("admin.users")) {
|
|
88
96
|
Object.assign(body, { uid: user?.uid, editor_id: user?.uid });
|
|
@@ -104,7 +112,7 @@ export default async function insert(req, reply) {
|
|
|
104
112
|
referer,
|
|
105
113
|
});
|
|
106
114
|
if (!res) {
|
|
107
|
-
return reply.status(400).send("nothing added");
|
|
115
|
+
return reply.status(400).send({ error: "nothing added", code: 400 });
|
|
108
116
|
}
|
|
109
117
|
// admin.custom_column
|
|
110
118
|
await applyHook("afterInsert", {
|
|
@@ -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,
|
|
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,gBAkOZ"}
|
|
@@ -22,14 +22,15 @@ export default async function tableAPI(req, reply, called) {
|
|
|
22
22
|
if (!loadTable &&
|
|
23
23
|
!pg.pk?.[tokenData?.table] &&
|
|
24
24
|
!(pg.pk?.[templateName] && called)) {
|
|
25
|
-
return reply.status(404).send("not found");
|
|
25
|
+
return reply.status(404).send({ error: "not found", code: 404 });
|
|
26
26
|
}
|
|
27
27
|
const { table: table1 = params.table, form: form1, obj, } = hookData || loadTable || tokenData || {};
|
|
28
28
|
const table = loadTable?.table || table1;
|
|
29
29
|
const form = loadTable?.form || form1;
|
|
30
30
|
const id = hookData?.id || tokenData?.id || params.id;
|
|
31
|
-
if (tokenData && !id)
|
|
32
|
-
return {
|
|
31
|
+
if (tokenData && !id) {
|
|
32
|
+
return reply.status(403).send({ error: "invalid token", code: 403 });
|
|
33
|
+
}
|
|
33
34
|
if (!table && !id) {
|
|
34
35
|
return reply.status(400).send("not enough params");
|
|
35
36
|
}
|
|
@@ -46,14 +47,18 @@ export default async function tableAPI(req, reply, called) {
|
|
|
46
47
|
return reply.status(400).send("invalid token");
|
|
47
48
|
}
|
|
48
49
|
if (!actions.includes("edit") && !config?.local && !tokenData && !called) {
|
|
49
|
-
return reply
|
|
50
|
+
return reply
|
|
51
|
+
.status(403)
|
|
52
|
+
.send({ error: "access restricted: actions", code: 403 });
|
|
50
53
|
}
|
|
51
54
|
const { pk, columns: dbColumns = [] } = await getMeta({
|
|
52
55
|
pg,
|
|
53
56
|
table,
|
|
54
57
|
});
|
|
55
58
|
if (!pk) {
|
|
56
|
-
return reply
|
|
59
|
+
return reply
|
|
60
|
+
.status(404)
|
|
61
|
+
.send({ error: `table not found: ${table}`, code: 404 });
|
|
57
62
|
}
|
|
58
63
|
// const cols = columns.map((el) => el.name || el).join(',');
|
|
59
64
|
const formData = (await getTemplate("form", form)) || {};
|
|
@@ -107,7 +112,9 @@ export default async function tableAPI(req, reply, called) {
|
|
|
107
112
|
.query(q.replace(/{{uid}}/, user?.uid), [id])
|
|
108
113
|
.then((el) => el.rows[0]);
|
|
109
114
|
if (!data) {
|
|
110
|
-
return reply
|
|
115
|
+
return reply
|
|
116
|
+
.status(404)
|
|
117
|
+
.send({ error: `object not found: ${id}`, code: 404 });
|
|
111
118
|
}
|
|
112
119
|
Object.keys(schema)
|
|
113
120
|
.filter((key) => schema[key]?.type === "DataTable")
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../../server/routes/crud/controllers/update.ts"],"names":[],"mappings":"AAeA,wBAA8B,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,
|
|
1
|
+
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../../server/routes/crud/controllers/update.ts"],"names":[],"mappings":"AAeA,wBAA8B,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,gBA4LxD"}
|
|
@@ -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
|
-
|
|
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
|
|
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
|
-
|
|
74
|
-
|
|
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
|
-
|
|
86
|
-
|
|
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
|
-
|
|
98
|
-
|
|
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":"
|
|
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
|
|
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
|
|
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
|
|
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:
|
|
66
|
+
message: "file not found",
|
|
68
67
|
file: params["*"],
|
|
69
68
|
uid,
|
|
70
69
|
rnokpp,
|
|
71
70
|
});
|
|
72
|
-
return
|
|
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
|
|
80
|
+
return message;
|
|
84
81
|
}
|
|
85
82
|
catch (err) {
|
|
86
|
-
logger.file("file", {
|
|
87
|
-
|
|
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
|
-
|
|
95
|
-
|
|
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
|
-
|
|
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":"
|
|
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
|
|
2
|
-
import providers from
|
|
3
|
-
import getMimeType from
|
|
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 {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
51
|
-
|
|
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;
|
|
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"}
|