@uxf/resizer 2.2.0 → 2.2.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.
@@ -8,7 +8,7 @@
8
8
  "source": "/Users/vejvis/UXF/projects/resizer/example-upload/:namespace/:p1/:p2/:filename.:extension"
9
9
  },
10
10
  {
11
- "route": "/generated/opentopo/:width(\\d+)_:height(\\d+)/:filename",
12
- "source": "https://opentopo.app/:filename"
11
+ "route": "/generated/static/:width(\\d+)_:height(\\d+)/:filename(*).:extension.:toFormat",
12
+ "source": "https://www.uxf.cz/:filename+.:extension"
13
13
  }
14
14
  ]
package/README.md CHANGED
@@ -29,8 +29,8 @@ You can use configuration file `.resizer-config.json` or environment variable `U
29
29
  "source": "/var/www/UXF/projects/resizer/example-upload/:namespace/:p1/:p2/:filename.:extension"
30
30
  },
31
31
  {
32
- "route": "/generated/opentopo/:width(\\d+)_:height(\\d+)_:fit([a-z]+)/:filename",
33
- "source": "https://opentopo.app/:filename"
32
+ "route": "/generated/static/:width(\\d+)_:height(\\d+)/:filename(*).:extension.:toExtension",
33
+ "source": "https://www.uxf.cz/:filename+"
34
34
  }
35
35
  ]
36
36
  ```
package/index.js CHANGED
@@ -100,6 +100,21 @@ function log(message) {
100
100
  // eslint-disable-next-line no-console
101
101
  console.log(message);
102
102
  }
103
+ /**
104
+ * TODO @vejvis HACK
105
+ *
106
+ * pro odchycení celé cesty i s lomítkama je potřeba udělat hack: /generated/:restPath(*) => restPath bude string
107
+ * pro zpětné složení pomocí pathToRegexp::compile() se používá: /generated/:restPath+ => restPath musí být string[]
108
+ * Tato funkce projde celý objekt a pokud v hodnotě atributu najde "/" tak tento atribut převede na pole
109
+ */
110
+ var repairParams = function (params) {
111
+ var obj = {};
112
+ Object.keys(params).forEach(function (key) {
113
+ var value = params[key];
114
+ obj[key] = value.includes("/") ? value.split("/") : value;
115
+ });
116
+ return obj;
117
+ };
103
118
  var resizerMiddleware = function (config) {
104
119
  var middleware = (0, express_1.Router)();
105
120
  config.forEach(function (c, i) {
@@ -107,20 +122,21 @@ var resizerMiddleware = function (config) {
107
122
  log(" Route: ".concat(c.route));
108
123
  log(" Source: ".concat(c.source));
109
124
  middleware.get(c.route, function (req, res) { return __awaiter(void 0, void 0, void 0, function () {
110
- var url, domain, sourceFilename, generatedFilename, generatedDirectory, params, sourceFile, _a, pipeline, trim;
125
+ var url, domain, repairedParams, sourceFilename, generatedFilename, generatedDirectory, params, sourceFile, _a, pipeline, trim;
111
126
  var _b, _c;
112
127
  return __generator(this, function (_d) {
113
128
  switch (_d.label) {
114
129
  case 0:
115
130
  url = c.source.startsWith("http") ? new URL(c.source) : null;
116
131
  domain = url === null || url === void 0 ? void 0 : url.origin;
117
- sourceFilename = (0, path_to_regexp_1.compile)((_b = url === null || url === void 0 ? void 0 : url.pathname) !== null && _b !== void 0 ? _b : c.source, {})(req.params);
132
+ repairedParams = repairParams(req.params);
133
+ sourceFilename = (0, path_to_regexp_1.compile)((_b = url === null || url === void 0 ? void 0 : url.pathname) !== null && _b !== void 0 ? _b : c.source, {})(repairedParams);
118
134
  generatedFilename = ((_c = process.env.UXF_RESIZER_GENERATE_PATH) !== null && _c !== void 0 ? _c : process.cwd()) + req.path;
119
135
  if ((0, fs_1.existsSync)(generatedFilename)) {
120
136
  return [2 /*return*/, res.sendFile(generatedFilename)];
121
137
  }
122
138
  log("----------------------------------------");
123
- log(req.params);
139
+ log(repairedParams);
124
140
  log("Source filename: ".concat(sourceFilename));
125
141
  log("Generated filename: ".concat(generatedFilename));
126
142
  generatedDirectory = (0, path_1.dirname)(generatedFilename);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/resizer",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "main": "index.js",
5
5
  "description": "UXF Resizer",
6
6
  "author": "UXFans <dev@uxf.cz>",
Binary file