@ejfdelgado/ejflab-back 1.27.0 → 1.27.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ejfdelgado/ejflab-back",
3
- "version": "1.27.0",
3
+ "version": "1.27.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ejfdelgado/ejflab-back.git"
@@ -10,7 +10,8 @@ import { ModuloDatoSeguroBack } from "@ejfdelgado/ejflab-common/src/ModuloDatoSe
10
10
  import { MyConstants } from "@ejfdelgado/ejflab-common/src/MyConstants.js";
11
11
 
12
12
  export class MainHandler {
13
- static LOCAL_FOLDER = path.resolve() + "/dist/bundle";
13
+ static LOCAL_FOLDER1 = path.resolve() + "/src";// First try
14
+ static LOCAL_FOLDER = path.resolve() + "/dist/bundle";// Finall try
14
15
  static async handle(req, res, next) {
15
16
  const originalUrl = req.getUrl();
16
17
  const theUrl = url.parse(originalUrl);
@@ -97,37 +98,54 @@ export class MainHandler {
97
98
  return null;
98
99
  }
99
100
 
100
- static async resolveLocalFileSingle(filename, encoding, rootFolder = MainHandler.LOCAL_FOLDER) {
101
+ static async resolveLocalFileSingle(filename, encoding, rootFolder) {
101
102
  return new Promise((resolve, reject) => {
102
- const somePath = path.join(rootFolder, filename);
103
103
 
104
- fs.access(somePath, (err) => {
105
- if (err) {
106
- resolve(null);
107
- } else {
108
- if (!fs.lstatSync(somePath).isFile()) {
109
- resolve(null);
104
+ // Try
105
+ const options = [];
106
+ if (rootFolder) {
107
+ options.push(path.join(rootFolder, filename));
108
+ }
109
+ options.push(path.join(MainHandler.LOCAL_FOLDER1, filename));
110
+ options.push(path.join(MainHandler.LOCAL_FOLDER, filename));
111
+
112
+ // Check which exists first, if not resolve null with log
113
+ let selected = null;
114
+ for (let i = 0; i < options.length; i++) {
115
+ const actual = options[i];
116
+ if (fs.existsSync(actual)) {
117
+ selected = actual;
118
+ break;
119
+ }
120
+ }
121
+
122
+ if (!selected) {
123
+ console.log(`Files not found ${options}`);
124
+ resolve(null);
125
+ }
126
+
127
+ const somePath = selected;
128
+ if (!fs.lstatSync(somePath).isFile()) {
129
+ resolve(null);
130
+ return;
131
+ }
132
+ if (typeof encoding == "string") {
133
+ fs.readFile(somePath, encoding, function (err, data) {
134
+ if (err) {
135
+ reject(err);
110
136
  return;
111
137
  }
112
- if (typeof encoding == "string") {
113
- fs.readFile(somePath, encoding, function (err, data) {
114
- if (err) {
115
- reject(err);
116
- return;
117
- }
118
- resolve(data);
119
- });
120
- } else {
121
- fs.readFile(somePath, function (err, data) {
122
- if (err) {
123
- reject(err);
124
- return;
125
- }
126
- resolve(data);
127
- });
138
+ resolve(data);
139
+ });
140
+ } else {
141
+ fs.readFile(somePath, function (err, data) {
142
+ if (err) {
143
+ reject(err);
144
+ return;
128
145
  }
129
- }
130
- });
146
+ resolve(data);
147
+ });
148
+ }
131
149
  });
132
150
  }
133
151
 
package/srv/MyPdf.mjs CHANGED
@@ -49,6 +49,7 @@ export class MyPdf {
49
49
  }
50
50
  }
51
51
  } else {
52
+ console.log(`Doesn't exits ${path}`);
52
53
  model.extra[extraFile.alias] = "";
53
54
  }
54
55
  }