@opengis/fastify-table 2.6.4 → 2.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../config.ts"],"names":[],"mappings":"AAWA,QAAA,MAAM,MAAM,KAA8D,CAAC;AAiD3E,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../config.ts"],"names":[],"mappings":"AAYA,QAAA,MAAM,MAAM,KAA8D,CAAC;AAsD3E,eAAe,MAAM,CAAC"}
package/dist/config.js CHANGED
@@ -3,6 +3,7 @@ import dotenv from "dotenv";
3
3
  dotenv.config(); // ! load .env (workaround for node)
4
4
  import { existsSync, readFileSync } from "node:fs";
5
5
  import unflattenObject from "./server/plugins/util/funcs/unflattenObject.js";
6
+ import { randomUUID } from "node:crypto";
6
7
  const fileName = ["config.json", "/data/local/config.json"].find((el) => existsSync(el) ? el : null);
7
8
  const config = fileName ? JSON.parse(readFileSync(fileName, "utf-8")) : {};
8
9
  const { skipKeys = ["windir"] } = config;
@@ -38,6 +39,11 @@ function loadEnvConfig() {
38
39
  (key.charAt(0) === key.charAt(0)?.toLowerCase?.() || key.includes(".")))
39
40
  .reduce((acc, curr) => ({ ...acc, [curr]: process.env[curr] }), {});
40
41
  Object.assign(config, unflattenObject(configKeys));
42
+ if (!config.auth?.secret) {
43
+ config.auth = config.auth || {};
44
+ config.auth.secret = randomUUID().replace(/-/g, "");
45
+ console.warn("environment variable auth.secret not set");
46
+ }
41
47
  }
42
48
  loadEnvConfig();
43
49
  export default config;
@@ -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;AAYtD,wBAAsB,SAAS,CAAC,GAAG,EAAE,eAAe,EAAE,KAAK,EAAE,YAAY,iBAiIxE;AAED,iBAAS,MAAM,CAAC,OAAO,EAAE,eAAe,QAmCvC;AAED,eAAe,MAAM,CAAC"}
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;AAQtD,wBAAsB,SAAS,CAAC,GAAG,EAAE,eAAe,EAAE,KAAK,EAAE,YAAY,iBAiIxE;AAED,iBAAS,MAAM,CAAC,OAAO,EAAE,eAAe,QAmCvC;AAED,eAAe,MAAM,CAAC"}
@@ -8,9 +8,6 @@ import getRedis from "../redis/funcs/getRedis.js";
8
8
  import { ForbiddenError } from "../../../errors.js";
9
9
  const { prefix = "/api" } = config;
10
10
  const { auth } = config || {};
11
- if (!auth?.secret && process.platform !== 'win32') {
12
- throw new Error("environment variable auth.secret not set");
13
- }
14
11
  const fastifyPassport = new Authenticator();
15
12
  export async function onRequest(req, reply) {
16
13
  const { hostname, headers, routeOptions } = req;
@@ -127,7 +124,7 @@ function plugin(fastify) {
127
124
  parseOptions: config?.auth?.cookieOptions || { secure: false },
128
125
  });
129
126
  fastify.register(session, {
130
- secret: auth?.secret || 'fastify-session-redis-store-secret',
127
+ secret: auth?.secret || "fastify-session-redis-store-secret",
131
128
  cookieName: "session_auth",
132
129
  cookie: config?.auth?.cookieOptions || { secure: false },
133
130
  store: new RedisStore({
@@ -1,4 +1,4 @@
1
- import type { FastifyReply } from "fastify";
1
+ import { FastifyReply } from "fastify";
2
2
  /**
3
3
  * Апі використовується для отримання різних файлів і можливістю змінювати їх
4
4
  *
@@ -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;AAmB5C;;;;;;;;;;;;;;;;;GAiBG;AAEH,wBAA8B,OAAO,CACnC,EACE,MAAM,EACN,KAAK,EACL,IAAI,GACL,EAAE;IACD,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IACxB,KAAK,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC5B,EACD,KAAK,EAAE,YAAY,gBA8DpB"}
1
+ {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAiBvC;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAA8B,OAAO,CACnC,EACE,MAAM,EACN,KAAK,EACL,IAAI,GACL,EAAE;IACD,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IACxB,KAAK,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC5B,EACD,KAAK,EAAE,YAAY,gBA8DpB"}
@@ -1,6 +1,5 @@
1
1
  import path from "node:path";
2
2
  import mime from "../../../plugins/file/providers/mime/index.js";
3
- // import isFileExists from "../../../plugins/file/isFileExists.js";
4
3
  import downloadFile from "../../../plugins/file/downloadFile.js";
5
4
  import config from "../../../../config.js";
6
5
  import logger from "../../../plugins/logger/getLogger.js";
@@ -40,10 +39,19 @@ export default async function getFile({ params, query, user, }, reply) {
40
39
  if (relpath.includes("../")) {
41
40
  throw ForbiddenError("invalid characters detected");
42
41
  }
43
- const hookData = await applyHook("preFile", { user, relpath, reply });
42
+ const filepath = path.posix.join("files", relpath);
43
+ const hookData = (await applyHook("preFile", { user, relpath }));
44
+ const headers = {
45
+ "Content-Disposition": `inline; filename=${encodeURIComponent(path.basename(filepath))}`,
46
+ "Cache-Control": "max-age=86400",
47
+ "Content-Type": `${mime(filepath)}`, // ; charset=utf-8 --- untested
48
+ };
49
+ if (hookData?.data) {
50
+ logger.file("file/files", { filepath: params["*"], uid: user?.uid });
51
+ return reply.headers(hookData.headers || headers).send(hookData.data);
52
+ }
44
53
  if (hookData)
45
54
  return hookData;
46
- const filepath = path.join("files", relpath);
47
55
  if ((config.local || user?.user_type?.includes?.("admin")) && query.debug) {
48
56
  const fp = providers();
49
57
  const existsS3 = fp.name === "s3"
@@ -60,11 +68,6 @@ export default async function getFile({ params, query, user, }, reply) {
60
68
  if (!fileStream) {
61
69
  return reply.headers({ "Content-Type": "image/gif" }).send(grayGif);
62
70
  }
63
- const headers = {
64
- "Content-Disposition": `inline; filename=${encodeURIComponent(path.basename(filepath))}`,
65
- "Cache-Control": "max-age=86400",
66
- "Content-Type": `${mime(filepath)}`, // ; charset=utf-8 --- untested
67
- };
68
71
  reply.headers(headers);
69
72
  logger.file("file/files", { filepath: params["*"], uid: user?.uid });
70
73
  return fileStream;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "2.6.4",
3
+ "version": "2.6.7",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [