@live-change/image-service 0.8.12 → 0.8.14
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 +7 -4
- package/package.json +7 -7
package/endpoint.js
CHANGED
|
@@ -12,6 +12,9 @@ const config = definition.config
|
|
|
12
12
|
|
|
13
13
|
const imagesPath = config.imagesPath || `./storage/images/`
|
|
14
14
|
|
|
15
|
+
import Debug from 'debug'
|
|
16
|
+
const debug = Debug("image-service:endpoint")
|
|
17
|
+
|
|
15
18
|
function normalizeFormat(f1) {
|
|
16
19
|
f1 = f1.toLowerCase().trim()
|
|
17
20
|
if(f1 == 'jpg') f1 = 'jpeg'
|
|
@@ -36,7 +39,7 @@ function delay(ms) {
|
|
|
36
39
|
async function getImageMetadata(image, version) {
|
|
37
40
|
for(let t = 0; t < 5; t++) {
|
|
38
41
|
const metadata = await Image.get(image)
|
|
39
|
-
|
|
42
|
+
debug("METADATA READ RESULT", metadata)
|
|
40
43
|
if(metadata) return metadata
|
|
41
44
|
await delay(200 * Math.pow(2, t))
|
|
42
45
|
}
|
|
@@ -50,7 +53,7 @@ function sanitizeImageId(id) {
|
|
|
50
53
|
async function handleImageGet(req, res, params) {
|
|
51
54
|
const { image } = params
|
|
52
55
|
const metadata = await getImageMetadata(image)
|
|
53
|
-
|
|
56
|
+
debug("PIC METADATA", image, "=>", metadata)
|
|
54
57
|
if(!metadata) {
|
|
55
58
|
res.status(404)
|
|
56
59
|
res.send("Image " + image + " not found")
|
|
@@ -58,7 +61,7 @@ async function handleImageGet(req, res, params) {
|
|
|
58
61
|
}
|
|
59
62
|
const imagePrefix = imagesPath + sanitizeImageId(image) + '/'
|
|
60
63
|
const sourceFilePath = path.resolve(imagePrefix + 'original.' + metadata.extension)
|
|
61
|
-
|
|
64
|
+
debug("SOURCE IMAGE PATH", sourceFilePath)
|
|
62
65
|
if(!(await fileExists(sourceFilePath))) {
|
|
63
66
|
res.status(404)
|
|
64
67
|
console.error("IMAGE FILE NOT FOUND", sourceFilePath)
|
|
@@ -71,7 +74,7 @@ async function handleImageGet(req, res, params) {
|
|
|
71
74
|
switch(params.type) {
|
|
72
75
|
case "original": {
|
|
73
76
|
if(params.format && !isFormatsIdentical(params.format, metadata.extension)) {
|
|
74
|
-
|
|
77
|
+
debug("CONVERTING IMAGE!", metadata.extension, params.format)
|
|
75
78
|
const normalized = normalizeFormat(params.format)
|
|
76
79
|
const convertedFilePath = path.resolve(imagePrefix + 'converted.' + normalized)
|
|
77
80
|
if(!(await fileExists(convertedFilePath))) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/image-service",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.14",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,25 +8,25 @@
|
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/live-change/live-change-
|
|
11
|
+
"url": "git+https://github.com/live-change/live-change-stack.git"
|
|
12
12
|
},
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"bugs": {
|
|
15
|
-
"url": "https://github.com/live-change/live-change-
|
|
15
|
+
"url": "https://github.com/live-change/live-change-stack/issues"
|
|
16
16
|
},
|
|
17
|
-
"homepage": "https://github.com/live-change/live-change-
|
|
17
|
+
"homepage": "https://github.com/live-change/live-change-stack",
|
|
18
18
|
"author": {
|
|
19
19
|
"email": "michal@laszczewski.pl",
|
|
20
20
|
"name": "Michał Łaszczewski",
|
|
21
21
|
"url": "https://www.viamage.com/"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@live-change/framework": "^0.8.
|
|
25
|
-
"@live-change/relations-plugin": "^0.8.
|
|
24
|
+
"@live-change/framework": "^0.8.14",
|
|
25
|
+
"@live-change/relations-plugin": "^0.8.14",
|
|
26
26
|
"download": "^8.0.0",
|
|
27
27
|
"pluralize": "^8.0.0",
|
|
28
28
|
"sharp": "^0.32.5"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "d81b573fb8891746ae1c67f4f68558123c9f85f7",
|
|
31
31
|
"type": "module"
|
|
32
32
|
}
|