@opengis/fastify-table 2.4.19 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server/migrations/users.sql +11 -1
- package/dist/server/plugins/auth/index.d.ts.map +1 -1
- package/dist/server/plugins/auth/index.js +5 -0
- package/dist/server/plugins/crud/funcs/utils/logChanges.d.ts.map +1 -1
- package/dist/server/plugins/crud/funcs/utils/logChanges.js +5 -2
- package/dist/server/plugins/file/uploadMultiPart.d.ts.map +1 -1
- package/dist/server/plugins/file/uploadMultiPart.js +3 -1
- package/dist/server/plugins/logger/createFileStream.d.ts +1 -1
- package/dist/server/plugins/logger/createFileStream.d.ts.map +1 -1
- package/dist/server/plugins/pg/funcs/getMeta.js +2 -2
- package/dist/server/plugins/policy/funcs/checkPolicy.d.ts.map +1 -1
- package/dist/server/plugins/policy/funcs/checkPolicy.js +4 -1
- package/dist/server/plugins/sqlite/funcs/getSqlite.d.ts.map +1 -1
- package/dist/server/plugins/sqlite/funcs/getSqlite.js +9 -6
- package/dist/server/plugins/sqlite/sqliteClients.d.ts.map +1 -1
- package/dist/server/plugins/sqlite/sqliteClients.js +10 -9
- package/dist/server/plugins/table/funcs/getSelectMeta.d.ts.map +1 -1
- package/dist/server/plugins/table/funcs/getSelectMeta.js +10 -5
- package/dist/server/plugins/table/funcs/getTemplate.js +2 -2
- package/dist/server/plugins/table/funcs/getTemplateSync.js +2 -2
- package/dist/server/plugins/util/funcs/eventStream.d.ts +1 -4
- package/dist/server/plugins/util/funcs/eventStream.d.ts.map +1 -1
- package/dist/server/routes/access/schema.d.ts.map +1 -1
- package/dist/server/routes/auth/controllers/euSign/authByData.d.ts.map +1 -1
- package/dist/server/routes/auth/controllers/euSign/authByData.js +1 -1
- package/dist/server/routes/file/controllers/export.d.ts.map +1 -1
- package/dist/server/routes/file/controllers/export.js +5 -3
- package/dist/server/routes/file/controllers/resizeAll.d.ts.map +1 -1
- package/dist/server/routes/file/controllers/resizeAll.js +4 -3
- package/dist/server/routes/file/index.d.ts.map +1 -1
- package/dist/server/routes/file/index.js +20 -5
- package/dist/server/routes/file/schema.d.ts +27 -4
- package/dist/server/routes/file/schema.d.ts.map +1 -1
- package/dist/server/routes/file/schema.js +23 -9
- package/dist/server/routes/table/controllers/search.d.ts.map +1 -1
- package/dist/server/routes/table/controllers/search.js +19 -11
- package/dist/server/routes/table/controllers/suggest.js +1 -1
- 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 +80 -46
- package/dist/server/routes/table/index.js +2 -1
- package/dist/server/routes/table/schema.d.ts +6 -10
- package/dist/server/routes/table/schema.d.ts.map +1 -1
- package/dist/server/routes/table/schema.js +50 -50
- package/dist/server/routes/templates/index.d.ts.map +1 -1
- package/dist/server/routes/templates/index.js +7 -1
- package/dist/server/routes/templates/schema.d.ts +3 -3
- package/dist/server/routes/templates/schema.d.ts.map +1 -1
- package/dist/server/routes/templates/schema.js +4 -4
- package/dist/server/types/core.d.ts.map +1 -1
- package/dist/server/types/core.js +0 -4
- package/package.json +98 -98
|
@@ -56,7 +56,17 @@ COMMENT ON COLUMN admin.users.salt IS 'Сіль';
|
|
|
56
56
|
COMMENT ON COLUMN admin.users.twofa IS 'Двофакторна авторизація';
|
|
57
57
|
|
|
58
58
|
CREATE EXTENSION if not exists pgcrypto SCHEMA public VERSION "1.3";
|
|
59
|
-
|
|
59
|
+
|
|
60
|
+
CREATE OR REPLACE FUNCTION admin.crypt(pass TEXT,salt TEXT)
|
|
61
|
+
RETURNS text AS
|
|
62
|
+
$BODY$
|
|
63
|
+
DECLARE
|
|
64
|
+
BEGIN
|
|
65
|
+
return public.crypt(pass, salt);
|
|
66
|
+
END;
|
|
67
|
+
$BODY$
|
|
68
|
+
LANGUAGE plpgsql VOLATILE
|
|
69
|
+
COST 100;
|
|
60
70
|
|
|
61
71
|
-- DROP FUNCTION admin.insert_update_user_before();
|
|
62
72
|
CREATE OR REPLACE FUNCTION admin.insert_update_user_before()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/plugins/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAYxD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAOtD,wBAAsB,SAAS,CAAC,GAAG,EAAE,eAAe,EAAE,KAAK,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/plugins/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAYxD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAOtD,wBAAsB,SAAS,CAAC,GAAG,EAAE,eAAe,EAAE,KAAK,EAAE,YAAY,iBAkIxE;AAED,iBAAS,MAAM,CAAC,OAAO,EAAE,eAAe,QAmCvC;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -38,6 +38,11 @@ export async function onRequest(req, reply) {
|
|
|
38
38
|
const isPublic = Array.isArray(policy)
|
|
39
39
|
? policy.includes("public")
|
|
40
40
|
: policy === "L0";
|
|
41
|
+
// local development only, example: upload file via postman
|
|
42
|
+
if (process.platform === "win32" && !req.cookies) {
|
|
43
|
+
req.cookies = {};
|
|
44
|
+
req.cookies["session_auth"] = "test";
|
|
45
|
+
}
|
|
41
46
|
if (req.cookies?.["session_auth"] &&
|
|
42
47
|
!req.session?.passport?.user?.uid &&
|
|
43
48
|
(config.auth?.disable || config.auth?.user)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logChanges.d.ts","sourceRoot":"","sources":["../../../../../../server/plugins/crud/funcs/utils/logChanges.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"logChanges.d.ts","sourceRoot":"","sources":["../../../../../../server/plugins/crud/funcs/utils/logChanges.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAoD5D,wBAA8B,UAAU,CAAC,EACvC,EAAE,EACF,KAAK,EAAE,MAAM,EACb,SAAS,EACT,OAAO,EACP,EAAE,EACF,IAAI,EACJ,GAAO,EACP,IAAI,GACL,EAAE;IACD,EAAE,EAAE,UAAU,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC;CACd;;;;;;;;;;;;;;;;;;;;UA0MA"}
|
|
@@ -4,6 +4,9 @@ import metaFormat from "../../../table/funcs/metaFormat/index.js";
|
|
|
4
4
|
import getMeta from "../../../pg/funcs/getMeta.js";
|
|
5
5
|
import config from "../../../../../config.js";
|
|
6
6
|
const logLength = +(config.logLength || 200);
|
|
7
|
+
const sequence = (arr, fn) => {
|
|
8
|
+
return arr.reduce((promise, item) => promise.then(() => fn(item)), Promise.resolve());
|
|
9
|
+
};
|
|
7
10
|
const defaultTitles = {
|
|
8
11
|
editor_date: "Дата оновлення",
|
|
9
12
|
editor_id: "Редактор",
|
|
@@ -157,7 +160,7 @@ export default async function logChanges({ pg, table: table1, tokenData, referer
|
|
|
157
160
|
if (process.env.NODE_ENV === "test") {
|
|
158
161
|
console.log("changesData", changesData);
|
|
159
162
|
}
|
|
160
|
-
const res = await
|
|
163
|
+
const res = await sequence(changesData, async (el) => {
|
|
161
164
|
const insertQuery = `insert into log.table_changes_data (${Object.entries(el)
|
|
162
165
|
?.map((key) => `"${key[0]}"`)
|
|
163
166
|
.join(",")})
|
|
@@ -174,7 +177,7 @@ export default async function logChanges({ pg, table: table1, tokenData, referer
|
|
|
174
177
|
])
|
|
175
178
|
.then((el) => el.rows?.[0] || {});
|
|
176
179
|
return row1;
|
|
177
|
-
})
|
|
180
|
+
});
|
|
178
181
|
const newData = (Array.isArray(res) ? res : [res]).reduce((acc, curr) => Object.assign(acc, { [curr.entity_key]: curr.value_new }), {});
|
|
179
182
|
// console.log('logChanges OK', type);
|
|
180
183
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uploadMultiPart.d.ts","sourceRoot":"","sources":["../../../../server/plugins/file/uploadMultiPart.ts"],"names":[],"mappings":"AAwBA,MAAM,WAAW,KAAK;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AA2CD,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,mBAkBvE;AAED,wBAAsB,gBAAgB,CACpC,EACE,IAAI,EAAE,QAAQ,EACd,MAA2C,EAC3C,MAAM,GACP,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EACpD,MAAM,MAAW,mBA+BlB;AAED,wBAAsB,eAAe,CACnC,GAAG,EAAE,GAAG,EACR,EACE,UAAU,EACV,GAAG,EACH,MAAM,EACN,gBAAwB,GACzB,GAAE;IACD,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CACvB,GACL,OAAO,CAAC,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"uploadMultiPart.d.ts","sourceRoot":"","sources":["../../../../server/plugins/file/uploadMultiPart.ts"],"names":[],"mappings":"AAwBA,MAAM,WAAW,KAAK;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AA2CD,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,mBAkBvE;AAED,wBAAsB,gBAAgB,CACpC,EACE,IAAI,EAAE,QAAQ,EACd,MAA2C,EAC3C,MAAM,GACP,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EACpD,MAAM,MAAW,mBA+BlB;AAED,wBAAsB,eAAe,CACnC,GAAG,EAAE,GAAG,EACR,EACE,UAAU,EACV,GAAG,EACH,MAAM,EACN,gBAAwB,GACzB,GAAE;IACD,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CACvB,GACL,OAAO,CAAC,KAAK,CAAC,CA2GhB;AAED,eAAe,eAAe,CAAC"}
|
|
@@ -141,9 +141,11 @@ export async function uploadMultiPart(req, { extensions, raw, subdir, originalFi
|
|
|
141
141
|
// move file to s3
|
|
142
142
|
if (config.s3?.endpoint) {
|
|
143
143
|
const s3 = providers();
|
|
144
|
+
if (config.trace)
|
|
145
|
+
console.log("upload to s3 start", file.relativeFilepath, fileBuffer.length);
|
|
144
146
|
await s3.uploadFile(file.relativeFilepath, fileBuffer);
|
|
145
147
|
if (config.trace)
|
|
146
|
-
console.log("upload to s3", file.relativeFilepath);
|
|
148
|
+
console.log("upload to s3 success", file.relativeFilepath);
|
|
147
149
|
}
|
|
148
150
|
return file;
|
|
149
151
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import build from "pino-abstract-transport";
|
|
2
|
-
export default function transportTarget(): import("stream").Transform & build.OnUnknown;
|
|
2
|
+
export default function transportTarget(): import("node:stream").Transform & build.OnUnknown;
|
|
3
3
|
//# sourceMappingURL=createFileStream.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFileStream.d.ts","sourceRoot":"","sources":["../../../../server/plugins/logger/createFileStream.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,yBAAyB,CAAC;AAmC5C,MAAM,CAAC,OAAO,UAAU,eAAe,
|
|
1
|
+
{"version":3,"file":"createFileStream.d.ts","sourceRoot":"","sources":["../../../../server/plugins/logger/createFileStream.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,yBAAyB,CAAC;AAmC5C,MAAM,CAAC,OAAO,UAAU,eAAe,sDAoDtC"}
|
|
@@ -55,8 +55,8 @@ export default async function getMeta(opt, nocache) {
|
|
|
55
55
|
json_build_object(
|
|
56
56
|
'title', pg_catalog.col_description(attrelid,attnum)
|
|
57
57
|
)
|
|
58
|
-
) from pg_catalog.pg_attribute
|
|
59
|
-
where attrelid=$1::regclass and attnum>0`, [tableSafe])
|
|
58
|
+
) from pg_catalog.pg_attribute
|
|
59
|
+
where attrelid=$1::regclass and attnum>0 and NOT attisdropped`, [tableSafe])
|
|
60
60
|
.then((el) => el.rows?.[0]?.json_object_agg || {});
|
|
61
61
|
fields.forEach((el) => Object.assign(el, { ...(dbColumns[el.name] || {}) }));
|
|
62
62
|
const res = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkPolicy.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/policy/funcs/checkPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EAEhB,MAAM,wBAAwB,CAAC;AAMhC,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,CAAC,EAAE,GAAG,
|
|
1
|
+
{"version":3,"file":"checkPolicy.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/policy/funcs/checkPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EAEhB,MAAM,wBAAwB,CAAC;AAMhC,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,CAAC,EAAE,GAAG,QAyKlE"}
|
|
@@ -67,7 +67,10 @@ export default function checkPolicy(req, jwt) {
|
|
|
67
67
|
return null;
|
|
68
68
|
}
|
|
69
69
|
// ! sql injection
|
|
70
|
-
const stopWords = block.filter((el) => path
|
|
70
|
+
const stopWords = block.filter((el) => decodeURIComponent(path).toUpperCase().includes(el.toUpperCase()) ||
|
|
71
|
+
JSON.stringify(req.body || {})
|
|
72
|
+
.toUpperCase()
|
|
73
|
+
.includes(el.toUpperCase()));
|
|
71
74
|
if (stopWords?.length && !allowSql) {
|
|
72
75
|
logger.file("injection/sql", {
|
|
73
76
|
path,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSqlite.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/sqlite/funcs/getSqlite.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getSqlite.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/sqlite/funcs/getSqlite.ts"],"names":[],"mappings":"AAgBA,iBAAS,cAAc,CAAC,EACtB,IAAI,EACJ,QAAgB,EAChB,aAAqB,EACrB,iBAAiB,EAAE,OAAe,GACnC,GAAE,GAAQ,OAuBV;AAED,eAAe,cAAc,CAAC"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
const { name: execName } = path.parse(process.argv0);
|
|
3
|
-
// import Database from 'better-sqlite3'; // error with bun
|
|
4
|
-
const { default: Database } = execName === "bun"
|
|
5
|
-
? { default: (await import("bun:sqlite")).Database }
|
|
6
|
-
: await import("better-sqlite3");
|
|
7
3
|
import config from "../../../../config.js";
|
|
4
|
+
if (config.sqlite && execName !== "bun") {
|
|
5
|
+
throw NotImplementedError("sqlite without bun is not supported");
|
|
6
|
+
}
|
|
7
|
+
const { Database } = config.sqlite ? await import("bun:sqlite") : {};
|
|
8
8
|
import sqliteClients from "../sqliteClients.js";
|
|
9
9
|
import init from "./init.js";
|
|
10
|
+
import { NotImplementedError } from "../../../../errors.js";
|
|
10
11
|
function getSqliteAsync({ name, readonly = false, fileMustExist = false, statement_timeout: timeout = 10000, } = {}) {
|
|
11
|
-
if (!config.sqlite)
|
|
12
|
+
if (!config.sqlite || !Database)
|
|
12
13
|
return null;
|
|
13
14
|
if (sqliteClients.client?.tlist) {
|
|
14
15
|
return sqliteClients.client;
|
|
@@ -19,7 +20,9 @@ function getSqliteAsync({ name, readonly = false, fileMustExist = false, stateme
|
|
|
19
20
|
timeout,
|
|
20
21
|
verbose: config.trace ? console.log : undefined,
|
|
21
22
|
};
|
|
22
|
-
sqliteClients.client =
|
|
23
|
+
sqliteClients.client = Database
|
|
24
|
+
? new Database(name || ":memory:", execName === "bun" ? undefined : dbConfig)
|
|
25
|
+
: null;
|
|
23
26
|
init(sqliteClients.client);
|
|
24
27
|
return sqliteClients.client;
|
|
25
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqliteClients.d.ts","sourceRoot":"","sources":["../../../../server/plugins/sqlite/sqliteClients.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sqliteClients.d.ts","sourceRoot":"","sources":["../../../../server/plugins/sqlite/sqliteClients.ts"],"names":[],"mappings":"AAgBA,QAAA,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,CAAC;AAkB9C,eAAe,aAAa,CAAC"}
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
const { name: execName } = path.parse(process.argv0);
|
|
3
|
-
// import Database from 'better-sqlite3';
|
|
4
|
-
const { default: Database } = execName === "bun"
|
|
5
|
-
? { default: (await import("bun:sqlite")).Database }
|
|
6
|
-
: await import("better-sqlite3");
|
|
7
3
|
import config from "../../../config.js";
|
|
4
|
+
if (config.sqlite && execName !== "bun") {
|
|
5
|
+
throw NotImplementedError("sqlite without bun is not supported");
|
|
6
|
+
}
|
|
7
|
+
const { Database } = config.sqlite ? await import("bun:sqlite") : {};
|
|
8
8
|
import init from "./funcs/init.js";
|
|
9
|
+
import { NotImplementedError } from "../../../errors.js";
|
|
9
10
|
const sqliteClients = {};
|
|
10
|
-
if (config.sqlite) {
|
|
11
|
+
if (config.sqlite && Database) {
|
|
11
12
|
const client = new Database(config.sqlite?.name || ":memory:", execName === "bun"
|
|
12
13
|
? undefined
|
|
13
14
|
: {
|
|
14
|
-
readonly: config.sqlite?.readonly
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
readonly: config.sqlite?.readonly ?? false,
|
|
16
|
+
create: config.sqlite?.create ?? false,
|
|
17
|
+
readwrite: config.sqlite?.readwrite ?? true,
|
|
18
|
+
safeIntegers: config.sqlite?.safeIntegers ?? true,
|
|
18
19
|
});
|
|
19
20
|
client.init = () => init(client);
|
|
20
21
|
client.init();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSelectMeta.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/table/funcs/getSelectMeta.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAWzD,wBAA8B,aAAa,CAAC,EAC1C,IAAI,EACJ,UAAU,EACV,GAAG,EACH,OAAO,EACP,MAAM,EACN,EAAqB,GACtB,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,EAAE,CAAC,EAAE,UAAU,CAAC;CACjB,
|
|
1
|
+
{"version":3,"file":"getSelectMeta.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/table/funcs/getSelectMeta.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAWzD,wBAA8B,aAAa,CAAC,EAC1C,IAAI,EACJ,UAAU,EACV,GAAG,EACH,OAAO,EACP,MAAM,EACN,EAAqB,GACtB,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,EAAE,CAAC,EAAE,UAAU,CAAC;CACjB,gBAsHA"}
|
|
@@ -30,7 +30,12 @@ export default async function getSelectMeta({ name, startsWith, key, nocache, pa
|
|
|
30
30
|
console.log(`sql select null: ${name}`);
|
|
31
31
|
return null;
|
|
32
32
|
}
|
|
33
|
-
const
|
|
33
|
+
const args = [
|
|
34
|
+
limit,
|
|
35
|
+
original.includes("{{parent}}") ? parent : undefined,
|
|
36
|
+
].filter((el) => el !== undefined);
|
|
37
|
+
const original1 = args.length === 2 ? original.replace("'{{parent}}'", "$1") : original;
|
|
38
|
+
const sql = `with c(id,text) as (select * from (${original1})q limit $${args.length > 1 ? 2 : 1}) select * from c`;
|
|
34
39
|
/*= == meta table === */
|
|
35
40
|
const tableNew = original
|
|
36
41
|
.toLowerCase()
|
|
@@ -38,13 +43,13 @@ export default async function getSelectMeta({ name, startsWith, key, nocache, pa
|
|
|
38
43
|
.split(" from ")
|
|
39
44
|
.filter((el) => /^[a-z0-9_]+\.[a-z0-9_]+/.test(el))
|
|
40
45
|
.map((el) => el.split(/[ )]/)[0].replace(/[\r\n]+/g, ""));
|
|
41
|
-
const dataOrigin = await pg1.query(sql
|
|
42
|
-
const dataOrigin1 = await pg1.query(`${
|
|
46
|
+
const dataOrigin = await pg1.query(sql.replace("limit $2", "limit 0").replace("limit $1", "limit 0"), [parent].filter((el) => el !== undefined));
|
|
47
|
+
const dataOrigin1 = await pg1.query(`${original1} limit 0`, [parent].filter((el) => el !== undefined));
|
|
43
48
|
// const table = getTable(original);
|
|
44
49
|
const count = cls?.count ??
|
|
45
50
|
(await pg1
|
|
46
|
-
.query(`select count(*) from (${
|
|
47
|
-
.then((
|
|
51
|
+
.query(`select count(*) from (${original1})q`, [parent].filter((el) => el !== undefined))
|
|
52
|
+
.then((r) => r?.rows?.[0].count));
|
|
48
53
|
// column name
|
|
49
54
|
const cols = dataOrigin.fields.map((el) => el.name);
|
|
50
55
|
const originalCols = dataOrigin1.fields.map((el) => el.name);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import
|
|
2
|
+
import { load } from "js-yaml";
|
|
3
3
|
import { readdir, readFile } from "node:fs/promises";
|
|
4
4
|
import getTemplatePath from "./getTemplatePath.js";
|
|
5
5
|
import loadTemplate from "./loadTemplate.js";
|
|
@@ -8,7 +8,7 @@ async function readFileData(file) {
|
|
|
8
8
|
const data = await readFile(file, "utf-8");
|
|
9
9
|
const ext = file.substring(file.lastIndexOf(".") + 1);
|
|
10
10
|
if (ext === "yml") {
|
|
11
|
-
return
|
|
11
|
+
return load(data);
|
|
12
12
|
}
|
|
13
13
|
if (ext === "json" && data) {
|
|
14
14
|
return JSON.parse(data);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { readdirSync, readFileSync } from "node:fs";
|
|
3
|
-
import
|
|
3
|
+
import { load } from "js-yaml";
|
|
4
4
|
import getTemplatePath from "./getTemplatePath.js";
|
|
5
5
|
import loadTemplate from "./loadTemplate.js";
|
|
6
6
|
import mdToHTML from "../../md/funcs/mdToHTML.js";
|
|
@@ -8,7 +8,7 @@ function readFileData(file) {
|
|
|
8
8
|
const data = readFileSync(file, "utf-8");
|
|
9
9
|
const ext = file.substring(file.lastIndexOf(".") + 1);
|
|
10
10
|
if (ext === "yml") {
|
|
11
|
-
return
|
|
11
|
+
return load(data);
|
|
12
12
|
}
|
|
13
13
|
if (ext === "json") {
|
|
14
14
|
return JSON.parse(data);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventStream.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/util/funcs/eventStream.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,GAAG,EAAE,GAAG
|
|
1
|
+
{"version":3,"file":"eventStream.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/util/funcs/eventStream.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,GAAG,EAAE,GAAG,4BA0B3C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../server/routes/access/schema.ts"],"names":[],"mappings":";AAAA,wBAAoB;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../server/routes/access/schema.ts"],"names":[],"mappings":";AAAA,wBAAoB;AAEpB,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,GACrB,CAAC;AAEF,QAAA,MAAM,iBAAiB;;;;;;;;;;;CAQtB,CAAC;AAEF,QAAA,MAAM,gBAAgB;;;;;;;;;;;CAQrB,CAAC;AAEF,QAAA,MAAM,qBAAqB;;;;;;;;;;;CAQ1B,CAAC;AAEF,QAAA,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4C1B,CAAC;AAEF,QAAA,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4CzB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authByData.d.ts","sourceRoot":"","sources":["../../../../../../server/routes/auth/controllers/euSign/authByData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAcvC,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"authByData.d.ts","sourceRoot":"","sources":["../../../../../../server/routes/auth/controllers/euSign/authByData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAcvC,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AA+B5D,wBAA8B,UAAU,CACtC,GAAG,EAAE,eAAe,EACpB,KAAK,EAAE,YAAY,kBAgIpB"}
|
|
@@ -7,7 +7,7 @@ import checkReferer from "../../../../plugins/auth/funcs/checkReferer.js";
|
|
|
7
7
|
import getQuery from "../../../../plugins/auth/funcs/getQuery.js";
|
|
8
8
|
import logAuth from "../../../../plugins/auth/funcs/logAuth.js";
|
|
9
9
|
import authorizeUser from "../../../../plugins/auth/funcs/authorizeUser.js";
|
|
10
|
-
import { BadRequestError, ForbiddenError, NotImplementedError } from "../../../../../errors.js";
|
|
10
|
+
import { BadRequestError, ForbiddenError, NotImplementedError, } from "../../../../../errors.js";
|
|
11
11
|
function fetchWithoutSSL(url, options) {
|
|
12
12
|
const httpsAgent = new Agent({
|
|
13
13
|
connect: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/export.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAiCzD;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,wBAA8B,WAAW,CACvC,EACE,EAAqB,EACrB,OAAO,EACP,IAAI,EACJ,OAAO,EAAE,QAAQ,EACjB,GAAG,EACH,KAAU,EACV,IAAkB,EAClB,QAAQ,EACR,UAAU,GACX,EAAE;IACD,EAAE,EAAE,UAAU,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,EACD,KAAK,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/export.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAiCzD;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,wBAA8B,WAAW,CACvC,EACE,EAAqB,EACrB,OAAO,EACP,IAAI,EACJ,OAAO,EAAE,QAAQ,EACjB,GAAG,EACH,KAAU,EACV,IAAkB,EAClB,QAAQ,EACR,UAAU,GACX,EAAE;IACD,EAAE,EAAE,UAAU,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,EACD,KAAK,EAAE,YAAY,gBAsbpB"}
|
|
@@ -229,10 +229,12 @@ export default async function exportTable({ pg = pgClients.client, headers, user
|
|
|
229
229
|
while (+filtered - offset > 0 && !res?.error) {
|
|
230
230
|
try {
|
|
231
231
|
send(`Оброблено: ${offset}/${filtered}`);
|
|
232
|
+
const isSingle = loadTable?.key && id;
|
|
233
|
+
const args = loadTable?.key && id
|
|
234
|
+
? [id, options.limit, offset]
|
|
235
|
+
: [options.limit, offset];
|
|
232
236
|
const { rows = [] } = tableSql || viewSql
|
|
233
|
-
? await pg.query(`select * from (${tableSql || viewSql})q where ${loadTable
|
|
234
|
-
? `${loadTable?.key}::text = '${id}'`
|
|
235
|
-
: "true"} limit ${options.limit} offset ${offset}`)
|
|
237
|
+
? await pg.query(`select * from (${tableSql || viewSql})q where ${isSingle ? `${loadTable.key}::text = $1` : "true"} limit $${isSingle ? 2 : 1} offset $${isSingle ? 3 : 2}`, args)
|
|
236
238
|
: await getData({
|
|
237
239
|
...options,
|
|
238
240
|
query: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resizeAll.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/resizeAll.ts"],"names":[],"mappings":"AA0HA,wBAA8B,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,
|
|
1
|
+
{"version":3,"file":"resizeAll.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/resizeAll.ts"],"names":[],"mappings":"AA0HA,wBAA8B,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,gBAuH3D"}
|
|
@@ -81,11 +81,12 @@ export default async function resizeAll(req, reply) {
|
|
|
81
81
|
const resizeQuality = Math.min(quality, 100);
|
|
82
82
|
const q = `select file_id as id, file_path as relpath from crm.files
|
|
83
83
|
where ext=any($1)
|
|
84
|
-
and ${filepath ? "file_path=$
|
|
85
|
-
and resized is null
|
|
84
|
+
and ${filepath ? "file_path=$3" : "1=1"}
|
|
85
|
+
and resized is null
|
|
86
|
+
limit $2`;
|
|
86
87
|
if (sql)
|
|
87
88
|
return q;
|
|
88
|
-
const { rows = [], rowCount = 0 } = await pg.query(q, [images, filepath].filter(Boolean));
|
|
89
|
+
const { rows = [], rowCount = 0 } = await pg.query(q, [images, Math.min(+limit || 16, 16), filepath].filter(Boolean));
|
|
89
90
|
if (rowCount === 0) {
|
|
90
91
|
return reply.status(200).send("nothing to resize");
|
|
91
92
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/routes/file/index.ts"],"names":[],"mappings":"AAoBA,iBAAS,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,GAAE,GAAQ,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/routes/file/index.ts"],"names":[],"mappings":"AAoBA,iBAAS,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,GAAE,GAAQ,QAqCtC;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -7,7 +7,7 @@ import download from "./controllers/download.js";
|
|
|
7
7
|
import exportTable from "./controllers/export.js";
|
|
8
8
|
import uploadImage from "./controllers/uploadImage.js";
|
|
9
9
|
import deleteFileAPI from "./controllers/delete.js";
|
|
10
|
-
import { resizeSchema } from "./schema.js";
|
|
10
|
+
import { resizeSchema, exportSchema } from "./schema.js";
|
|
11
11
|
const tags = ["core", "file"];
|
|
12
12
|
const { uploadPolicy = "L1" } = config;
|
|
13
13
|
const publicParams = { config: { tags, policy: "L0" } };
|
|
@@ -15,7 +15,9 @@ const privateParams = { config: { tags, policy: uploadPolicy } };
|
|
|
15
15
|
function plugin(app, opt = {}) {
|
|
16
16
|
app.get("/files/*", publicParams, files);
|
|
17
17
|
if (!app.hasRoute({ method: "GET", url: "/file/resize" })) {
|
|
18
|
-
app.
|
|
18
|
+
app.route({
|
|
19
|
+
method: "GET",
|
|
20
|
+
url: "/file/resize",
|
|
19
21
|
config: {
|
|
20
22
|
...publicParams,
|
|
21
23
|
rateLimit: config.rateLimit
|
|
@@ -26,13 +28,26 @@ function plugin(app, opt = {}) {
|
|
|
26
28
|
: undefined,
|
|
27
29
|
},
|
|
28
30
|
schema: resizeSchema,
|
|
29
|
-
|
|
31
|
+
handler: resize,
|
|
32
|
+
});
|
|
30
33
|
}
|
|
31
|
-
app.
|
|
34
|
+
app.route({
|
|
35
|
+
method: "GET",
|
|
36
|
+
url: "/api/resize-all",
|
|
37
|
+
config: { tags, role: "admin" },
|
|
38
|
+
schema: resizeSchema,
|
|
39
|
+
handler: resizeAll,
|
|
40
|
+
});
|
|
32
41
|
app.post("/file/upload/*", privateParams, upload);
|
|
33
42
|
app.post("/file/upload-image/*", privateParams, uploadImage);
|
|
34
43
|
app.get("/file/download/*", publicParams, download);
|
|
35
44
|
app.get("/file/delete/*", publicParams, deleteFileAPI);
|
|
36
|
-
app.
|
|
45
|
+
app.route({
|
|
46
|
+
method: "GET",
|
|
47
|
+
url: "/api/export",
|
|
48
|
+
...publicParams,
|
|
49
|
+
schema: exportSchema,
|
|
50
|
+
handler: exportTable,
|
|
51
|
+
});
|
|
37
52
|
}
|
|
38
53
|
export default plugin;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
declare const resizeSchema: {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
querystring: {
|
|
3
|
+
type: string;
|
|
4
|
+
properties: {
|
|
5
5
|
filepath: {
|
|
6
6
|
type: string;
|
|
7
7
|
};
|
|
@@ -27,7 +27,30 @@ declare const resizeSchema: {
|
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
|
+
declare const exportSchema: {
|
|
31
|
+
querystring: {
|
|
32
|
+
type: string;
|
|
33
|
+
properties: {
|
|
34
|
+
limit: {
|
|
35
|
+
type: string;
|
|
36
|
+
minimum: number;
|
|
37
|
+
};
|
|
38
|
+
batchLimit: {
|
|
39
|
+
type: string;
|
|
40
|
+
minimum: number;
|
|
41
|
+
};
|
|
42
|
+
page: {
|
|
43
|
+
type: string;
|
|
44
|
+
minimum: number;
|
|
45
|
+
};
|
|
46
|
+
key: {
|
|
47
|
+
type: string;
|
|
48
|
+
pattern: string;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
};
|
|
30
53
|
declare const _default: null;
|
|
31
54
|
export default _default;
|
|
32
|
-
export { resizeSchema };
|
|
55
|
+
export { resizeSchema, exportSchema };
|
|
33
56
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../server/routes/file/schema.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../server/routes/file/schema.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAcjB,CAAC;AAEF,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;CAUjB,CAAC;;AAEF,wBAAoB;AAEpB,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
const resizeSchema = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
filepath: { type:
|
|
6
|
-
quality: { type:
|
|
7
|
-
size: {
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
querystring: {
|
|
3
|
+
type: "object",
|
|
4
|
+
properties: {
|
|
5
|
+
filepath: { type: "string" },
|
|
6
|
+
quality: { type: "number", exclusiveMinimum: 0, maximum: 100 },
|
|
7
|
+
size: {
|
|
8
|
+
type: "string",
|
|
9
|
+
pattern: "^((\\d{1,4})x(\\d{1,4})|(\\d{1,4})x|x(\\d{1,4}))$",
|
|
10
|
+
},
|
|
11
|
+
w: { type: "number", minimum: 1, maximum: 2048 },
|
|
12
|
+
h: { type: "number", minimum: 1, maximum: 2048 },
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
const exportSchema = {
|
|
17
|
+
querystring: {
|
|
18
|
+
type: "object",
|
|
19
|
+
properties: {
|
|
20
|
+
limit: { type: "number", minimum: 1 },
|
|
21
|
+
batchLimit: { type: "number", minimum: 1 },
|
|
22
|
+
page: { type: "number", minimum: 1 },
|
|
23
|
+
key: { type: "string", pattern: "^([\\d\\w_.-]+)$" },
|
|
10
24
|
},
|
|
11
25
|
},
|
|
12
26
|
};
|
|
13
27
|
export default null;
|
|
14
|
-
export { resizeSchema };
|
|
28
|
+
export { resizeSchema, exportSchema };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/search.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/search.ts"],"names":[],"mappings":"AAkJA,wBAA8B,MAAM,CAAC,EACnC,EAAqB,EACrB,KAAU,GACX,EAAE,GAAG;;;;;;GAmCL"}
|
|
@@ -11,7 +11,7 @@ async function getData({ pg = pgClients.client, tableName, query = {}, maxLimit,
|
|
|
11
11
|
return null;
|
|
12
12
|
}
|
|
13
13
|
const { table, columns, meta } = loadTable;
|
|
14
|
-
const { pk, view } = await getMeta({ pg, table });
|
|
14
|
+
const { pk, view } = (await getMeta({ pg, table }).catch((err) => null)) || {};
|
|
15
15
|
if (!pk && !view) {
|
|
16
16
|
return null;
|
|
17
17
|
}
|
|
@@ -20,14 +20,19 @@ async function getData({ pg = pgClients.client, tableName, query = {}, maxLimit,
|
|
|
20
20
|
const order = cols.includes(orderColumn) && orderColumn?.length
|
|
21
21
|
? `order by ${orderColumn} ${query.desc || orderDir === "desc" ? "desc" : ""}`
|
|
22
22
|
: "";
|
|
23
|
+
const args = [];
|
|
23
24
|
const limit = Math.max(maxLimit - res.rows.length, 0);
|
|
24
|
-
|
|
25
|
-
const offset = query.page && query.page > 0 ?
|
|
25
|
+
args.push(limit);
|
|
26
|
+
const offset = query.page && query.page > 0 ? (query.page - 1) * limit : 0;
|
|
27
|
+
args.push(offset);
|
|
28
|
+
if (meta?.search && query.key) {
|
|
29
|
+
args.push(`%${query.key}%`);
|
|
30
|
+
}
|
|
26
31
|
const search1 = meta?.search && query.key
|
|
27
32
|
? `(${meta?.search
|
|
28
33
|
.concat(meta?.title ? `,${meta?.title}` : "")
|
|
29
34
|
.split(",")
|
|
30
|
-
.map((el) => `${el}::text ilike
|
|
35
|
+
.map((el) => `${el}::text ilike $3`)
|
|
31
36
|
.join(" or ")})`
|
|
32
37
|
: "false";
|
|
33
38
|
const where = [!pk ? "false" : "true", loadTable.query, search1].filter(Boolean);
|
|
@@ -40,23 +45,26 @@ async function getData({ pg = pgClients.client, tableName, query = {}, maxLimit,
|
|
|
40
45
|
meta?.title ? `${meta.title} as title` : "",
|
|
41
46
|
]
|
|
42
47
|
.filter((el) => el)
|
|
43
|
-
.join(",")} from ${table} t ${sqlTable} where ${where.join(" and ") || "true"} ${order} $
|
|
48
|
+
.join(",")} from ${table} t ${sqlTable} where ${where.join(" and ") || "true"} ${order} limit $1 offset $2`;
|
|
44
49
|
if (query.sql) {
|
|
45
50
|
res.sql.push(q);
|
|
46
51
|
return null;
|
|
47
52
|
}
|
|
48
|
-
const rows = await pg.query(q).then((
|
|
53
|
+
const rows = await pg.query(q, args).then((r) => r.rows || []);
|
|
49
54
|
const filtered = pg.queryCache
|
|
50
55
|
? await pg
|
|
51
|
-
.queryCache(`select count(*) from ${table} t ${sqlTable} where ${where.join(" and ") || "true"}
|
|
52
|
-
|
|
56
|
+
.queryCache(`select count(*) from ${table} t ${sqlTable} where ${where.join(" and ").replace(/\$3/g, "$1") || "true"}`, {
|
|
57
|
+
args: [meta?.search && query.key ? query.key : undefined].filter(Boolean),
|
|
58
|
+
table,
|
|
59
|
+
})
|
|
60
|
+
.then((r) => +(r?.rows[0]?.count || 0))
|
|
53
61
|
: 0;
|
|
54
62
|
const total = pg.queryCache
|
|
55
63
|
? await pg
|
|
56
64
|
.queryCache(`select count(*) from ${table}`)
|
|
57
|
-
.then((
|
|
65
|
+
.then((r) => +(r?.rows[0]?.count || 0))
|
|
58
66
|
: 0;
|
|
59
|
-
await metaFormat({ rows, table: tableName });
|
|
67
|
+
await metaFormat({ rows, table: tableName }, pg);
|
|
60
68
|
res.total += +total;
|
|
61
69
|
res.filtered += +filtered;
|
|
62
70
|
rows.forEach((row) => {
|
|
@@ -83,7 +91,7 @@ export default async function search({ pg = pgClients.client, query = {}, }) {
|
|
|
83
91
|
total: 0,
|
|
84
92
|
filtered: 0,
|
|
85
93
|
};
|
|
86
|
-
const maxLimit = Math.min(100, query.limit ||
|
|
94
|
+
const maxLimit = Math.min(100, +query.limit || 16);
|
|
87
95
|
await sequence(tables, {
|
|
88
96
|
pg,
|
|
89
97
|
query,
|
|
@@ -68,7 +68,7 @@ export async function getTableColumnMeta({ table, template, column, selectName,
|
|
|
68
68
|
export default async function suggest(req) {
|
|
69
69
|
const time = Date.now();
|
|
70
70
|
const { params, user, query = {}, pg: pg1 = pgClients.client } = req;
|
|
71
|
-
const { lang = "ua", parent
|
|
71
|
+
const { lang = "ua", parent } = query;
|
|
72
72
|
const debugMode = config.local ||
|
|
73
73
|
user?.user_type?.includes?.("admin") ||
|
|
74
74
|
process.env.NODE_ENV === "test" ||
|
|
@@ -20,5 +20,5 @@ export default function dataAPI({ pg, params, table, id, headers, query, user, c
|
|
|
20
20
|
accessQuery?: string;
|
|
21
21
|
columns?: string[];
|
|
22
22
|
isExport?: boolean;
|
|
23
|
-
},
|
|
23
|
+
}, reply?: FastifyReply, called?: any): Promise<any>;
|
|
24
24
|
//# sourceMappingURL=getData.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getData.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/functions/getData.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAwFzD,wBAA8B,OAAO,CACnC,EACE,EAAqB,EACrB,MAAM,EACN,KAAK,EACL,EAAE,EACF,OAAY,EACZ,KAAU,EACV,IAAS,EACT,YAAY,EACZ,YAAY,EACZ,KAAY,EACZ,UAAU,EACV,OAAO,EAAE,YAAY,EACrB,WAAW,EAAE,gBAAgB,EAC7B,OAAO,EAAE,YAAY,EACrB,QAAgB,GACjB,EAAE;IACD,EAAE,CAAC,EAAE,UAAU,CAAC;IAChB,MAAM,CAAC,EAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACxD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,EACD,
|
|
1
|
+
{"version":3,"file":"getData.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/functions/getData.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAwFzD,wBAA8B,OAAO,CACnC,EACE,EAAqB,EACrB,MAAM,EACN,KAAK,EACL,EAAE,EACF,OAAY,EACZ,KAAU,EACV,IAAS,EACT,YAAY,EACZ,YAAY,EACZ,KAAY,EACZ,UAAU,EACV,OAAO,EAAE,YAAY,EACrB,WAAW,EAAE,gBAAgB,EAC7B,OAAO,EAAE,YAAY,EACrB,QAAgB,GACjB,EAAE;IACD,EAAE,CAAC,EAAE,UAAU,CAAC;IAChB,MAAM,CAAC,EAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACxD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,EACD,KAAK,CAAC,EAAE,YAAY,EACpB,MAAM,CAAC,EAAE,GAAG,gBA64Bb"}
|