@ejfdelgado/ejflab-back 1.34.5 → 1.35.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ejfdelgado/ejflab-back",
3
- "version": "1.34.5",
3
+ "version": "1.35.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ejfdelgado/ejflab-back.git"
@@ -113,7 +113,14 @@ export class PostgresSrv {
113
113
  }
114
114
 
115
115
  static async executeText(sql, model = {}, client = null) {
116
- const sqlRendered = PostgresSrv.renderer.render(sql, model);
116
+ let sqlRendered = "";
117
+ if (typeof sql == "string") {
118
+ sqlRendered = PostgresSrv.renderer.render(sql, model);
119
+ } else if (sql instanceof Array) {
120
+ sqlRendered = sql.map((sqlText, index) => {
121
+ return PostgresSrv.renderer.render(sqlText, model[index]);
122
+ }).join("\n");
123
+ }
117
124
  consoleSrv.log(sqlRendered);
118
125
  let localClient = false;
119
126
  if (!client) {
@@ -129,13 +136,27 @@ export class PostgresSrv {
129
136
  }
130
137
 
131
138
  static async executeFile(path, model = {}, client = null) {
132
- const sql = fs.readFileSync(path, "utf-8");
133
- return await PostgresSrv.executeText(sql, model, client);
139
+ if (typeof path == "string") {
140
+ const sql = fs.readFileSync(path, "utf-8");
141
+ return await PostgresSrv.executeText(sql, model, client);
142
+ } else if (path instanceof Array) {
143
+ const plainSqlArray = path.map((singlePath) => {
144
+ return fs.readFileSync(singlePath, "utf-8");
145
+ });
146
+ return await PostgresSrv.executeText(plainSqlArray, model, client);
147
+ }
134
148
  }
135
149
 
136
150
  static async executeFileInTransaction(path, model = {}) {
137
- const sql = fs.readFileSync(path, "utf-8");
138
- return await PostgresSrv.executeTextInTransaction(sql, model);
151
+ if (typeof path == "string") {
152
+ const sql = fs.readFileSync(path, "utf-8");
153
+ return await PostgresSrv.executeTextInTransaction(sql, model);
154
+ } else if (path instanceof Array) {
155
+ const plainSqlArray = path.map((singlePath) => {
156
+ return fs.readFileSync(singlePath, "utf-8");
157
+ });
158
+ return await PostgresSrv.executeTextInTransaction(plainSqlArray, model);
159
+ }
139
160
  }
140
161
 
141
162
  static createPool() {
@@ -36,6 +36,7 @@ import { CloseVideoChatProcessor } from "./callprocessors/CloseVideoChatProcesso
36
36
  import { IncludeOtherPeersProcessor } from "./callprocessors/IncludeOtherPeersProcessor.mjs";
37
37
  import { RegisterSessionProcessor } from "./callprocessors/RegisterSessionProcessor.mjs";
38
38
  import { UnregisterSessionProcessor } from "./callprocessors/UnregisterSessionProcessor.mjs";
39
+ import { General } from "./common/General.mjs";
39
40
 
40
41
  import stream from "stream";
41
42
 
@@ -53,6 +54,7 @@ export class SocketIOCall {
53
54
  static hookProcessors = {};
54
55
  static internalBus = new EventEmitter();
55
56
  static sessionsByProvider = {};
57
+ static attachedFiles = {};
56
58
 
57
59
  static {
58
60
  // check dead sockets
@@ -89,6 +91,14 @@ export class SocketIOCall {
89
91
  }, 4000);
90
92
  }
91
93
 
94
+ static storeAttachedFile(id, byteArray, fileName, mimeType) {
95
+ SocketIOCall.attachedFiles[id] = {
96
+ byteArray,
97
+ fileName,
98
+ mimeType,
99
+ };
100
+ }
101
+
92
102
  static echoLog(message) {
93
103
  if (process.env.ENV != "pro") {
94
104
  console.log(message);
@@ -641,4 +651,23 @@ export class SocketIOCall {
641
651
  static getSocketImage(socketId) {
642
652
  return SocketIOCall.socketToImage[socketId];
643
653
  }
654
+
655
+ static async getAttachedFile(req, res, next) {
656
+ const attachedId = General.readParam(req, "id", null, true);
657
+ const attachedData = SocketIOCall.attachedFiles[attachedId];
658
+ if (!attachedData) {
659
+ res.status(204).end();
660
+ return;
661
+ }
662
+ const { byteArray, fileName, mimeType } = attachedData;
663
+ const buffer = Buffer.from(byteArray);
664
+ const safeName = encodeURIComponent(fileName);
665
+ res.setHeader("Content-Disposition", `inline; filename=${safeName}`);
666
+ res.setHeader("Content-Type", mimeType);
667
+ res.setHeader("X-Frame-Options", "ALLOWALL");
668
+ res.setHeader("Content-Security-Policy", "frame-ancestors 'self' http://localhost:4200;");
669
+ res.setHeader("Permissions-Policy", "fullscreen=*");
670
+
671
+ res.send(buffer); // send raw bytes
672
+ }
644
673
  }
@@ -1,6 +1,6 @@
1
1
  import { SimpleObj } from "@ejfdelgado/ejflab-common/src/SimpleObj.js";
2
2
  import { GenericProcessor } from "./GenericProcessor.mjs";
3
-
3
+ import { v4 as uuidv4 } from 'uuid';
4
4
 
5
5
  export class SendChatProcessor extends GenericProcessor {
6
6
  MAX_COUNT_TIMESTAMS = 6;
@@ -8,8 +8,14 @@ export class SendChatProcessor extends GenericProcessor {
8
8
  super(context, io, socket);
9
9
  }
10
10
  execute(args) {
11
- const { text, author, open } = args;
11
+ const { text, author, open, bytes, fileName, mimeType } = args;
12
12
  const room = this.context.getRoomFromSocket(this.socket);
13
+ let attachedFileId = null;
14
+ if (bytes) {
15
+ attachedFileId = room + "_" + uuidv4().replace(/-/g, '_');
16
+ // Store the bytes using this idKey
17
+ this.context.storeAttachedFile(attachedFileId, bytes, fileName, mimeType);
18
+ }
13
19
  const roomData = this.context.getRoomLiveTupleModel(room);
14
20
  if (!roomData.model.data) {
15
21
  roomData.model.data = {};
@@ -18,13 +24,17 @@ export class SendChatProcessor extends GenericProcessor {
18
24
  roomData.model.data.chat = [];
19
25
  }
20
26
  const now = new Date().getTime();
21
- roomData.model.data.chat.push({
27
+ const chatEntry = {
22
28
  text,
23
29
  date: now,
24
30
  author: {
25
31
  uid: author,
26
32
  },
27
- });
33
+ };
34
+ if (attachedFileId) {
35
+ chatEntry.attachedId = attachedFileId;
36
+ }
37
+ roomData.model.data.chat.push(chatEntry);
28
38
  let changes = roomData.builder.trackDifferences(roomData.model, [], null, ["data", "data.chat"]);
29
39
  roomData.model = roomData.builder.affect(changes);
30
40
  // Also notify last message time