@ossy/resources 3.7.0 → 3.7.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.
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/resources",
|
|
3
3
|
"description": "Resource domain — aggregate and events for the Ossy resource model",
|
|
4
|
-
"version": "3.7.
|
|
4
|
+
"version": "3.7.1",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./src/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@ossy/event-store": "^3.7.0",
|
|
27
27
|
"@ossy/fold": "^3.4.0",
|
|
28
|
-
"@ossy/platform": "^3.7.
|
|
28
|
+
"@ossy/platform": "^3.7.1",
|
|
29
29
|
"@ossy/schema": "^3.6.1"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"/src",
|
|
50
50
|
"README.md"
|
|
51
51
|
],
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "1ee220424da6b065034a7f52f52aa4a6ce7c88d5"
|
|
53
53
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { attachResourceMediaUrls } from './resources.attach-media-urls.js'
|
|
2
|
+
import { createLogger } from '@ossy/observability'
|
|
3
|
+
|
|
4
|
+
const log = createLogger('resources')
|
|
2
5
|
|
|
3
6
|
export function mediaContextFromRun({ payload, req }) {
|
|
4
7
|
return {
|
|
@@ -7,12 +10,24 @@ export function mediaContextFromRun({ payload, req }) {
|
|
|
7
10
|
}
|
|
8
11
|
}
|
|
9
12
|
|
|
13
|
+
async function attachOrKeep (resource, context) {
|
|
14
|
+
try {
|
|
15
|
+
return await attachResourceMediaUrls(resource, context)
|
|
16
|
+
} catch (error) {
|
|
17
|
+
log.warn('[withResourceMedia] skipping media urls', {
|
|
18
|
+
resourceId: resource?.id,
|
|
19
|
+
error: error?.message,
|
|
20
|
+
})
|
|
21
|
+
return resource
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
10
25
|
export async function withResourceMedia(result, context) {
|
|
11
26
|
if (Array.isArray(result)) {
|
|
12
|
-
return Promise.all(result.map(r =>
|
|
27
|
+
return Promise.all(result.map(r => attachOrKeep(r, context)))
|
|
13
28
|
}
|
|
14
29
|
if (result && typeof result === 'object' && result.id) {
|
|
15
|
-
return
|
|
30
|
+
return attachOrKeep(result, context)
|
|
16
31
|
}
|
|
17
32
|
return result
|
|
18
33
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { StorageClient } from '@ossy/platform'
|
|
2
2
|
import { Aggregate } from '@ossy/event-store'
|
|
3
|
+
import { coerceStorageKey } from '@ossy/platform/storage-keys'
|
|
3
4
|
import { Workspace } from '@ossy/workspaces/server'
|
|
5
|
+
import { createLogger } from '@ossy/observability'
|
|
6
|
+
|
|
7
|
+
const log = createLogger('resources')
|
|
4
8
|
|
|
5
9
|
/**
|
|
6
10
|
* Adds `content.src` (and `content.sizes[*]` URLs) for file resources, respecting
|
|
@@ -39,11 +43,19 @@ export async function attachResourceMediaUrls(resource, { userId, workspaceId }
|
|
|
39
43
|
return { ...resource, content: nextContent }
|
|
40
44
|
}
|
|
41
45
|
|
|
42
|
-
|
|
46
|
+
const originalKey = coerceStorageKey(Key, resource.id)
|
|
47
|
+
if (Key && !originalKey) {
|
|
48
|
+
log.warn('[attachResourceMediaUrls] skipping invalid storage key', {
|
|
49
|
+
resourceId: resource.id,
|
|
50
|
+
key: Key,
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (originalKey) {
|
|
43
55
|
nextContent.src =
|
|
44
56
|
access === 'public'
|
|
45
|
-
? StorageClient.createDownloadUrl(
|
|
46
|
-
: await StorageClient.createPresignedDownloadUrl(
|
|
57
|
+
? StorageClient.createDownloadUrl(originalKey)
|
|
58
|
+
: await StorageClient.createPresignedDownloadUrl(originalKey)
|
|
47
59
|
}
|
|
48
60
|
|
|
49
61
|
if (hasSizes) {
|
|
@@ -54,10 +66,15 @@ export async function attachResourceMediaUrls(resource, { userId, workspaceId }
|
|
|
54
66
|
nextSizes[name] = value
|
|
55
67
|
continue
|
|
56
68
|
}
|
|
69
|
+
const sizeFallback = resource.id && /^[A-Za-z0-9_-]+$/.test(name)
|
|
70
|
+
? `${resource.id}:${name}`
|
|
71
|
+
: resource.id
|
|
72
|
+
const logical = coerceStorageKey(value, sizeFallback)
|
|
73
|
+
if (!logical) continue
|
|
57
74
|
nextSizes[name] =
|
|
58
75
|
access === 'public'
|
|
59
|
-
? StorageClient.createDownloadUrl(
|
|
60
|
-
: await StorageClient.createPresignedDownloadUrl(
|
|
76
|
+
? StorageClient.createDownloadUrl(logical)
|
|
77
|
+
: await StorageClient.createPresignedDownloadUrl(logical)
|
|
61
78
|
}
|
|
62
79
|
nextContent.sizes = nextSizes
|
|
63
80
|
}
|