@ossy/media-tasks 1.32.3 → 1.34.0
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": "@ossy/media-tasks",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.34.0",
|
|
4
4
|
"description": "Changestream-triggered media processing tasks (image resize, AI descriptors)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
"scripts": {
|
|
15
15
|
"typecheck": "echo \"No TypeScript in media-tasks package\" && exit 0"
|
|
16
16
|
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@ossy/observability": "^1.2.0"
|
|
19
|
+
},
|
|
17
20
|
"peerDependencies": {
|
|
18
21
|
"openai": ">=4",
|
|
19
22
|
"sharp": ">=0.34"
|
|
@@ -28,5 +31,5 @@
|
|
|
28
31
|
],
|
|
29
32
|
"author": "Ossy <yourfriends@ossy.se> (https://ossy.se)",
|
|
30
33
|
"license": "MIT",
|
|
31
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "46cdd391ec01ea9210543ee7b14661f77079a7e7"
|
|
32
35
|
}
|
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
import OpenAiSDK from 'openai'
|
|
2
2
|
|
|
3
|
+
export const id = 'openai'
|
|
4
|
+
|
|
5
|
+
export const credentials = ['OPENAI_API_KEY']
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Returns an OpenAI client configured from env vars.
|
|
9
|
+
* Tasks receive this via `integrations.get('openai')`.
|
|
10
|
+
*
|
|
11
|
+
* @param {{ env: NodeJS.ProcessEnv }} opts
|
|
12
|
+
* @returns {import('openai').OpenAI}
|
|
13
|
+
*/
|
|
14
|
+
export async function connect({ env }) {
|
|
15
|
+
return new OpenAiSDK({
|
|
16
|
+
apiKey: env.OPENAI_API_KEY,
|
|
17
|
+
organization: env.OPENAI_ORGANIZATION,
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
|
|
3
21
|
let _openai = null
|
|
4
22
|
function getOpenAi() {
|
|
5
23
|
if (!_openai) _openai = new OpenAiSDK({
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { createLogger } from '@ossy/observability'
|
|
2
|
+
|
|
3
|
+
const log = createLogger('media-tasks')
|
|
4
|
+
|
|
1
5
|
const Sizes = [
|
|
2
6
|
{ width: 24, height: 24, name: 'thumbnailSmall' },
|
|
3
7
|
{ width: 48, height: 48, name: 'thumbnailLarge' },
|
|
@@ -22,21 +26,21 @@ export async function run ({ event, sdk }) {
|
|
|
22
26
|
const { default: sharp } = await import('sharp')
|
|
23
27
|
const resourceId = event.aggregateId
|
|
24
28
|
|
|
25
|
-
|
|
29
|
+
log.info(`[resize-common-web] starting for resource ${resourceId}`)
|
|
26
30
|
|
|
27
31
|
const resource = await sdk.resources.get({ id: resourceId })
|
|
28
32
|
const image = await fetch(resource.content.src).then((response) => response.arrayBuffer())
|
|
29
33
|
|
|
30
|
-
|
|
34
|
+
log.info(`[resize-common-web] Resizing ${resourceId}`)
|
|
31
35
|
|
|
32
36
|
for (const { width, height, name } of Sizes) {
|
|
33
37
|
const imageBuffer = await sharp(image).resize(width, height).toBuffer()
|
|
34
38
|
|
|
35
|
-
|
|
39
|
+
log.info(`[resize-common-web] Created image buffer for ${name}`)
|
|
36
40
|
|
|
37
41
|
const file = new File([new Uint8Array(imageBuffer)], name, { type: resource.type })
|
|
38
42
|
|
|
39
|
-
|
|
43
|
+
log.info(`[resize-common-web] Uploading ${name} for ${resourceId}`)
|
|
40
44
|
try {
|
|
41
45
|
await sdk.resources.uploadNamedVersion({
|
|
42
46
|
id: resourceId,
|
|
@@ -44,11 +48,10 @@ export async function run ({ event, sdk }) {
|
|
|
44
48
|
file: file,
|
|
45
49
|
})
|
|
46
50
|
} catch (error) {
|
|
47
|
-
|
|
48
|
-
console.error(error)
|
|
51
|
+
log.error(`[resize-common-web] Error uploading ${name} for ${resourceId}`, undefined, error)
|
|
49
52
|
throw error
|
|
50
53
|
}
|
|
51
54
|
|
|
52
|
-
|
|
55
|
+
log.info(`[resize-common-web] Uploaded ${name} for ${resourceId}`)
|
|
53
56
|
}
|
|
54
57
|
}
|