@live-change/image-service 0.8.113 → 0.8.115
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/image.js +69 -0
- package/package.json +4 -4
package/image.js
CHANGED
|
@@ -138,6 +138,75 @@ definition.action({
|
|
|
138
138
|
}
|
|
139
139
|
})
|
|
140
140
|
|
|
141
|
+
|
|
142
|
+
definition.trigger({
|
|
143
|
+
name: "setupExistingImage",
|
|
144
|
+
properties: {
|
|
145
|
+
image: {
|
|
146
|
+
type: Image
|
|
147
|
+
},
|
|
148
|
+
name: {
|
|
149
|
+
type: String,
|
|
150
|
+
validation: ['nonEmpty']
|
|
151
|
+
},
|
|
152
|
+
width: {
|
|
153
|
+
type: Number
|
|
154
|
+
},
|
|
155
|
+
height: {
|
|
156
|
+
type: Number
|
|
157
|
+
},
|
|
158
|
+
purpose: {
|
|
159
|
+
type: String,
|
|
160
|
+
validation: ['nonEmpty']
|
|
161
|
+
},
|
|
162
|
+
ownerType: {
|
|
163
|
+
type: String,
|
|
164
|
+
validation: ['nonEmpty']
|
|
165
|
+
},
|
|
166
|
+
owner: {
|
|
167
|
+
type: String,
|
|
168
|
+
validation: ['nonEmpty']
|
|
169
|
+
},
|
|
170
|
+
fileName: {
|
|
171
|
+
type: String,
|
|
172
|
+
validation: ['nonEmpty']
|
|
173
|
+
},
|
|
174
|
+
crop: cropInfo
|
|
175
|
+
},
|
|
176
|
+
waitForEvents: true,
|
|
177
|
+
async execute({ image, name, width, height, fileName, purpose, owner, ownerType, crop }, { client, service }, emit) {
|
|
178
|
+
if(!image) throw new Error("image_not_found")
|
|
179
|
+
const existing = await Image.get(image)
|
|
180
|
+
if (existing) throw 'already_exists'
|
|
181
|
+
|
|
182
|
+
let extension = fileName.match(/\.([A-Z0-9]+)$/i)[1].toLowerCase()
|
|
183
|
+
if(extension === 'jpg') throw new Error('jpg should have jpeg extension')
|
|
184
|
+
|
|
185
|
+
if(!width || !height) {
|
|
186
|
+
const path = `${imagesPath}/${image}/original.${extension}`
|
|
187
|
+
const data = await fs.promises.readFile(path)
|
|
188
|
+
const metadata = await sharp(data).metadata()
|
|
189
|
+
width = metadata.width
|
|
190
|
+
height = metadata.height
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
emit({
|
|
194
|
+
type: "ownerOwnedImageCreated",
|
|
195
|
+
image,
|
|
196
|
+
identifiers: {
|
|
197
|
+
owner, ownerType
|
|
198
|
+
},
|
|
199
|
+
data: {
|
|
200
|
+
name, purpose,
|
|
201
|
+
fileName,
|
|
202
|
+
width, height, extension, crop
|
|
203
|
+
}
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
return image
|
|
207
|
+
}
|
|
208
|
+
})
|
|
209
|
+
|
|
141
210
|
definition.trigger({
|
|
142
211
|
name: "createImageFromUrl",
|
|
143
212
|
properties: {
|
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.115",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,12 +21,12 @@
|
|
|
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.115",
|
|
25
|
+
"@live-change/relations-plugin": "^0.8.115",
|
|
26
26
|
"download": "^8.0.0",
|
|
27
27
|
"pluralize": "^8.0.0",
|
|
28
28
|
"sharp": "^0.32.5"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "fc360f214e2cd529db9e5795849005a563cb6866",
|
|
31
31
|
"type": "module"
|
|
32
32
|
}
|