@live-change/image-service 0.3.8 → 0.3.10
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/endpoint.js +14 -7
- package/package.json +4 -4
package/endpoint.js
CHANGED
|
@@ -86,7 +86,7 @@ async function handleImageGet(req, res, params) {
|
|
|
86
86
|
res.send("Bad parameter value")
|
|
87
87
|
return
|
|
88
88
|
}
|
|
89
|
-
|
|
89
|
+
if(width >= metadata.original.width) return res.sendFile(sourceFilePath)
|
|
90
90
|
const normalized = normalizeFormat(params.format || metadata.extension)
|
|
91
91
|
const convertedFilePath = path.resolve(imagePrefix + `width-${width}.${normalized}`)
|
|
92
92
|
if(!(await fileExists(convertedFilePath))) {
|
|
@@ -106,7 +106,7 @@ async function handleImageGet(req, res, params) {
|
|
|
106
106
|
res.send("Bad parameter value")
|
|
107
107
|
return
|
|
108
108
|
}
|
|
109
|
-
|
|
109
|
+
if(height >= metadata.original.height) return res.sendFile(sourceFilePath)
|
|
110
110
|
const normalized = normalizeFormat(params.format || metadata.extension)
|
|
111
111
|
const convertedFilePath = path.resolve(imagePrefix + `height-${height}.${normalized}`)
|
|
112
112
|
if(!(await fileExists(convertedFilePath))) {
|
|
@@ -120,15 +120,22 @@ async function handleImageGet(req, res, params) {
|
|
|
120
120
|
res.sendFile(convertedFilePath)
|
|
121
121
|
} break;
|
|
122
122
|
case "rect": {
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
let width = +params.width
|
|
124
|
+
let height = +params.height
|
|
125
125
|
if(!(height > 0 && width>0)) {
|
|
126
126
|
res.status(400)
|
|
127
127
|
res.send("Bad parameter value")
|
|
128
128
|
return
|
|
129
129
|
}
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
if(height > metadata.original.height) {
|
|
131
|
+
width = Math.round(width * metadata.original.height / height)
|
|
132
|
+
height = metadata.original.height
|
|
133
|
+
}
|
|
134
|
+
if(width > metadata.original.width) {
|
|
135
|
+
height = Math.round(height * metadata.original.width / width)
|
|
136
|
+
width = metadata.original.width
|
|
137
|
+
}
|
|
138
|
+
if(width == metadata.original.width && height == metadata.original.height) return res.sendFile(sourceFilePath)
|
|
132
139
|
const normalized = normalizeFormat(params.format || metadata.extension)
|
|
133
140
|
const convertedFilePath = path.resolve(imagePrefix + `rect-${width}-${height}.${normalized}`)
|
|
134
141
|
if(!(await fileExists(convertedFilePath))) {
|
|
@@ -185,4 +192,4 @@ definition.endpoint({
|
|
|
185
192
|
}
|
|
186
193
|
})
|
|
187
194
|
|
|
188
|
-
module.exports = {}
|
|
195
|
+
module.exports = {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/image-service",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
"url": "https://www.viamage.com/"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@live-change/framework": "0.7.
|
|
25
|
-
"@live-change/relations-plugin": "0.7.
|
|
24
|
+
"@live-change/framework": "0.7.8",
|
|
25
|
+
"@live-change/relations-plugin": "0.7.8",
|
|
26
26
|
"download": "^8.0.0",
|
|
27
27
|
"pluralize": "8.0.0",
|
|
28
28
|
"sharp": "^0.30.6"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "2517a729c452633bc3ce9725c05005a66b8f78ee"
|
|
31
31
|
}
|