@aphexcms/cms-core 9.10.0 → 10.0.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/dist/api/assets.d.ts +62 -7
- package/dist/api/assets.d.ts.map +1 -1
- package/dist/api/assets.js +116 -9
- package/dist/api/client.d.ts +1 -1
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +39 -9
- package/dist/api/limits.d.ts +55 -0
- package/dist/api/limits.d.ts.map +1 -0
- package/dist/api/limits.js +58 -0
- package/dist/api/schemas/assets.d.ts +94 -4
- package/dist/api/schemas/assets.d.ts.map +1 -1
- package/dist/api/schemas/assets.js +82 -5
- package/dist/api/types.d.ts +25 -0
- package/dist/api/types.d.ts.map +1 -1
- package/dist/api/upload-timeout.d.ts +17 -0
- package/dist/api/upload-timeout.d.ts.map +1 -0
- package/dist/api/upload-timeout.js +35 -0
- package/dist/api/upload.d.ts +42 -0
- package/dist/api/upload.d.ts.map +1 -0
- package/dist/api/upload.js +144 -0
- package/dist/components/AdminApp.svelte +130 -26
- package/dist/components/AdminApp.svelte.d.ts.map +1 -1
- package/dist/components/admin/AssetBrowserModal.svelte +4 -3
- package/dist/components/admin/AssetBrowserModal.svelte.d.ts +2 -1
- package/dist/components/admin/AssetBrowserModal.svelte.d.ts.map +1 -1
- package/dist/components/admin/MediaBrowser.svelte +1859 -281
- package/dist/components/admin/MediaBrowser.svelte.d.ts +21 -1
- package/dist/components/admin/MediaBrowser.svelte.d.ts.map +1 -1
- package/dist/components/admin/fields/ArrayField.svelte +21 -10
- package/dist/components/admin/fields/ArrayField.svelte.d.ts.map +1 -1
- package/dist/components/admin/fields/FileField.svelte +9 -2
- package/dist/components/admin/fields/FileField.svelte.d.ts.map +1 -1
- package/dist/components/admin/fields/ImageField.svelte +47 -12
- package/dist/components/admin/fields/ImageField.svelte.d.ts.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +14 -0
- package/dist/db/interfaces/asset.d.ts +114 -5
- package/dist/db/interfaces/asset.d.ts.map +1 -1
- package/dist/db/interfaces/document.d.ts +98 -3
- package/dist/db/interfaces/document.d.ts.map +1 -1
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js +2 -1
- package/dist/image/Image.svelte +72 -0
- package/dist/image/Image.svelte.d.ts +40 -0
- package/dist/image/Image.svelte.d.ts.map +1 -0
- package/dist/image/index.d.ts +3 -0
- package/dist/image/index.d.ts.map +1 -0
- package/dist/image/index.js +11 -0
- package/dist/image/types.d.ts +28 -0
- package/dist/image/types.d.ts.map +1 -0
- package/dist/image/types.js +1 -0
- package/dist/images/generate.d.ts +55 -0
- package/dist/images/generate.d.ts.map +1 -0
- package/dist/images/generate.js +243 -0
- package/dist/images/index.d.ts +2 -0
- package/dist/images/index.d.ts.map +1 -0
- package/dist/images/index.js +7 -0
- package/dist/images/variants.d.ts +82 -0
- package/dist/images/variants.d.ts.map +1 -0
- package/dist/images/variants.js +124 -0
- package/dist/jobs/asset-reference-jobs.d.ts +49 -0
- package/dist/jobs/asset-reference-jobs.d.ts.map +1 -0
- package/dist/jobs/asset-reference-jobs.js +74 -0
- package/dist/jobs/run-batch.d.ts.map +1 -1
- package/dist/jobs/run-batch.js +5 -0
- package/dist/lib/api/assets.d.ts +62 -7
- package/dist/lib/api/assets.d.ts.map +1 -1
- package/dist/lib/api/assets.js +116 -9
- package/dist/lib/api/assets.js.map +1 -1
- package/dist/lib/api/client.d.ts +1 -1
- package/dist/lib/api/client.d.ts.map +1 -1
- package/dist/lib/api/client.js +39 -9
- package/dist/lib/api/client.js.map +1 -1
- package/dist/lib/api/limits.d.ts +55 -0
- package/dist/lib/api/limits.d.ts.map +1 -0
- package/dist/lib/api/limits.js +59 -0
- package/dist/lib/api/limits.js.map +1 -0
- package/dist/lib/api/schemas/assets.d.ts +94 -4
- package/dist/lib/api/schemas/assets.d.ts.map +1 -1
- package/dist/lib/api/schemas/assets.js +82 -5
- package/dist/lib/api/schemas/assets.js.map +1 -1
- package/dist/lib/api/types.d.ts +25 -0
- package/dist/lib/api/types.d.ts.map +1 -1
- package/dist/lib/api/upload-timeout.d.ts +17 -0
- package/dist/lib/api/upload-timeout.d.ts.map +1 -0
- package/dist/lib/api/upload-timeout.js +36 -0
- package/dist/lib/api/upload-timeout.js.map +1 -0
- package/dist/lib/api/upload.d.ts +42 -0
- package/dist/lib/api/upload.d.ts.map +1 -0
- package/dist/lib/api/upload.js +145 -0
- package/dist/lib/api/upload.js.map +1 -0
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +14 -0
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/db/interfaces/asset.d.ts +114 -5
- package/dist/lib/db/interfaces/asset.d.ts.map +1 -1
- package/dist/lib/db/interfaces/document.d.ts +98 -3
- package/dist/lib/db/interfaces/document.d.ts.map +1 -1
- package/dist/lib/hooks.d.ts.map +1 -1
- package/dist/lib/hooks.js +2 -1
- package/dist/lib/hooks.js.map +1 -1
- package/dist/lib/image/index.d.ts +3 -0
- package/dist/lib/image/index.d.ts.map +1 -0
- package/dist/lib/image/index.js +12 -0
- package/dist/lib/image/index.js.map +1 -0
- package/dist/lib/image/types.d.ts +28 -0
- package/dist/lib/image/types.d.ts.map +1 -0
- package/dist/lib/image/types.js +2 -0
- package/dist/lib/image/types.js.map +1 -0
- package/dist/lib/images/generate.d.ts +55 -0
- package/dist/lib/images/generate.d.ts.map +1 -0
- package/dist/lib/images/generate.js +244 -0
- package/dist/lib/images/generate.js.map +1 -0
- package/dist/lib/images/index.d.ts +2 -0
- package/dist/lib/images/index.d.ts.map +1 -0
- package/dist/lib/images/index.js +8 -0
- package/dist/lib/images/index.js.map +1 -0
- package/dist/lib/images/variants.d.ts +82 -0
- package/dist/lib/images/variants.d.ts.map +1 -0
- package/dist/lib/images/variants.js +125 -0
- package/dist/lib/images/variants.js.map +1 -0
- package/dist/lib/jobs/asset-reference-jobs.d.ts +49 -0
- package/dist/lib/jobs/asset-reference-jobs.d.ts.map +1 -0
- package/dist/lib/jobs/asset-reference-jobs.js +75 -0
- package/dist/lib/jobs/asset-reference-jobs.js.map +1 -0
- package/dist/lib/jobs/run-batch.d.ts.map +1 -1
- package/dist/lib/jobs/run-batch.js +5 -0
- package/dist/lib/jobs/run-batch.js.map +1 -1
- package/dist/lib/local-api/collection-api.d.ts +19 -2
- package/dist/lib/local-api/collection-api.d.ts.map +1 -1
- package/dist/lib/local-api/collection-api.js +65 -17
- package/dist/lib/local-api/collection-api.js.map +1 -1
- package/dist/lib/preview/assets.d.ts +19 -0
- package/dist/lib/preview/assets.d.ts.map +1 -1
- package/dist/lib/preview/assets.js +6 -0
- package/dist/lib/preview/assets.js.map +1 -1
- package/dist/lib/routes/assets-cdn.d.ts +19 -0
- package/dist/lib/routes/assets-cdn.d.ts.map +1 -1
- package/dist/lib/routes/assets-cdn.js +295 -17
- package/dist/lib/routes/assets-cdn.js.map +1 -1
- package/dist/lib/server/api/index.d.ts.map +1 -1
- package/dist/lib/server/api/index.js +87 -8
- package/dist/lib/server/api/index.js.map +1 -1
- package/dist/lib/server/api/routes/assets-bulk.d.ts.map +1 -1
- package/dist/lib/server/api/routes/assets-bulk.js +36 -7
- package/dist/lib/server/api/routes/assets-bulk.js.map +1 -1
- package/dist/lib/server/api/routes/assets-by-id.d.ts.map +1 -1
- package/dist/lib/server/api/routes/assets-by-id.js +32 -15
- package/dist/lib/server/api/routes/assets-by-id.js.map +1 -1
- package/dist/lib/server/api/routes/assets-direct-upload.d.ts +4 -0
- package/dist/lib/server/api/routes/assets-direct-upload.d.ts.map +1 -0
- package/dist/lib/server/api/routes/assets-direct-upload.js +164 -0
- package/dist/lib/server/api/routes/assets-direct-upload.js.map +1 -0
- package/dist/lib/server/api/routes/assets-poster.d.ts +4 -0
- package/dist/lib/server/api/routes/assets-poster.d.ts.map +1 -0
- package/dist/lib/server/api/routes/assets-poster.js +120 -0
- package/dist/lib/server/api/routes/assets-poster.js.map +1 -0
- package/dist/lib/server/api/routes/assets-references.d.ts.map +1 -1
- package/dist/lib/server/api/routes/assets-references.js +64 -5
- package/dist/lib/server/api/routes/assets-references.js.map +1 -1
- package/dist/lib/server/api/routes/assets.d.ts.map +1 -1
- package/dist/lib/server/api/routes/assets.js +116 -12
- package/dist/lib/server/api/routes/assets.js.map +1 -1
- package/dist/lib/server/api/routes/clear-asset-references.d.ts +18 -0
- package/dist/lib/server/api/routes/clear-asset-references.d.ts.map +1 -0
- package/dist/lib/server/api/routes/clear-asset-references.js +32 -0
- package/dist/lib/server/api/routes/clear-asset-references.js.map +1 -0
- package/dist/lib/server/api/routes/documents.d.ts.map +1 -1
- package/dist/lib/server/api/routes/documents.js +27 -1
- package/dist/lib/server/api/routes/documents.js.map +1 -1
- package/dist/lib/server/index.d.ts +2 -0
- package/dist/lib/server/index.d.ts.map +1 -1
- package/dist/lib/server/index.js +4 -0
- package/dist/lib/server/index.js.map +1 -1
- package/dist/lib/services/asset-references-service.d.ts +93 -0
- package/dist/lib/services/asset-references-service.d.ts.map +1 -0
- package/dist/lib/services/asset-references-service.js +198 -0
- package/dist/lib/services/asset-references-service.js.map +1 -0
- package/dist/lib/services/asset-service.d.ts +115 -14
- package/dist/lib/services/asset-service.d.ts.map +1 -1
- package/dist/lib/services/asset-service.js +312 -31
- package/dist/lib/services/asset-service.js.map +1 -1
- package/dist/lib/services/references-service.d.ts +19 -15
- package/dist/lib/services/references-service.d.ts.map +1 -1
- package/dist/lib/services/references-service.js +59 -31
- package/dist/lib/services/references-service.js.map +1 -1
- package/dist/lib/services/version-service.d.ts +10 -1
- package/dist/lib/services/version-service.d.ts.map +1 -1
- package/dist/lib/services/version-service.js +26 -4
- package/dist/lib/services/version-service.js.map +1 -1
- package/dist/lib/storage/adapters/local-storage-adapter.d.ts +38 -0
- package/dist/lib/storage/adapters/local-storage-adapter.d.ts.map +1 -1
- package/dist/lib/storage/adapters/local-storage-adapter.js +86 -19
- package/dist/lib/storage/adapters/local-storage-adapter.js.map +1 -1
- package/dist/lib/storage/index.d.ts +1 -0
- package/dist/lib/storage/index.d.ts.map +1 -1
- package/dist/lib/storage/index.js +2 -0
- package/dist/lib/storage/index.js.map +1 -1
- package/dist/lib/storage/interfaces/storage.d.ts +135 -5
- package/dist/lib/storage/interfaces/storage.d.ts.map +1 -1
- package/dist/lib/storage/keys.d.ts +96 -0
- package/dist/lib/storage/keys.d.ts.map +1 -0
- package/dist/lib/storage/keys.js +160 -0
- package/dist/lib/storage/keys.js.map +1 -0
- package/dist/lib/types/asset.d.ts +92 -12
- package/dist/lib/types/asset.d.ts.map +1 -1
- package/dist/lib/types/capabilities.d.ts +11 -0
- package/dist/lib/types/capabilities.d.ts.map +1 -1
- package/dist/lib/types/capabilities.js +20 -6
- package/dist/lib/types/capabilities.js.map +1 -1
- package/dist/lib/types/config.d.ts +127 -0
- package/dist/lib/types/config.d.ts.map +1 -1
- package/dist/lib/utils/asset-reference-walk.d.ts +44 -0
- package/dist/lib/utils/asset-reference-walk.d.ts.map +1 -0
- package/dist/lib/utils/asset-reference-walk.js +144 -0
- package/dist/lib/utils/asset-reference-walk.js.map +1 -0
- package/dist/lib/utils/image-url.d.ts +61 -26
- package/dist/lib/utils/image-url.d.ts.map +1 -1
- package/dist/lib/utils/image-url.js +143 -26
- package/dist/lib/utils/image-url.js.map +1 -1
- package/dist/lib/utils/video-metadata.d.ts +39 -0
- package/dist/lib/utils/video-metadata.d.ts.map +1 -0
- package/dist/lib/utils/video-metadata.js +161 -0
- package/dist/lib/utils/video-metadata.js.map +1 -0
- package/dist/local-api/collection-api.d.ts +19 -2
- package/dist/local-api/collection-api.d.ts.map +1 -1
- package/dist/local-api/collection-api.js +65 -17
- package/dist/preview/assets.d.ts +19 -0
- package/dist/preview/assets.d.ts.map +1 -1
- package/dist/preview/assets.js +6 -0
- package/dist/routes/assets-cdn.d.ts +19 -0
- package/dist/routes/assets-cdn.d.ts.map +1 -1
- package/dist/routes/assets-cdn.js +295 -17
- package/dist/server/api/index.d.ts.map +1 -1
- package/dist/server/api/index.js +87 -8
- package/dist/server/api/routes/assets-bulk.d.ts.map +1 -1
- package/dist/server/api/routes/assets-bulk.js +36 -7
- package/dist/server/api/routes/assets-by-id.d.ts.map +1 -1
- package/dist/server/api/routes/assets-by-id.js +32 -15
- package/dist/server/api/routes/assets-direct-upload.d.ts +4 -0
- package/dist/server/api/routes/assets-direct-upload.d.ts.map +1 -0
- package/dist/server/api/routes/assets-direct-upload.js +163 -0
- package/dist/server/api/routes/assets-poster.d.ts +4 -0
- package/dist/server/api/routes/assets-poster.d.ts.map +1 -0
- package/dist/server/api/routes/assets-poster.js +119 -0
- package/dist/server/api/routes/assets-references.d.ts.map +1 -1
- package/dist/server/api/routes/assets-references.js +64 -5
- package/dist/server/api/routes/assets.d.ts.map +1 -1
- package/dist/server/api/routes/assets.js +116 -12
- package/dist/server/api/routes/clear-asset-references.d.ts +18 -0
- package/dist/server/api/routes/clear-asset-references.d.ts.map +1 -0
- package/dist/server/api/routes/clear-asset-references.js +31 -0
- package/dist/server/api/routes/documents.d.ts.map +1 -1
- package/dist/server/api/routes/documents.js +27 -1
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +4 -0
- package/dist/services/asset-references-service.d.ts +93 -0
- package/dist/services/asset-references-service.d.ts.map +1 -0
- package/dist/services/asset-references-service.js +197 -0
- package/dist/services/asset-service.d.ts +115 -14
- package/dist/services/asset-service.d.ts.map +1 -1
- package/dist/services/asset-service.js +312 -31
- package/dist/services/references-service.d.ts +19 -15
- package/dist/services/references-service.d.ts.map +1 -1
- package/dist/services/references-service.js +59 -31
- package/dist/services/version-service.d.ts +10 -1
- package/dist/services/version-service.d.ts.map +1 -1
- package/dist/services/version-service.js +26 -4
- package/dist/storage/adapters/local-storage-adapter.d.ts +38 -0
- package/dist/storage/adapters/local-storage-adapter.d.ts.map +1 -1
- package/dist/storage/adapters/local-storage-adapter.js +86 -19
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +2 -0
- package/dist/storage/interfaces/storage.d.ts +135 -5
- package/dist/storage/interfaces/storage.d.ts.map +1 -1
- package/dist/storage/keys.d.ts +96 -0
- package/dist/storage/keys.d.ts.map +1 -0
- package/dist/storage/keys.js +159 -0
- package/dist/types/asset.d.ts +92 -12
- package/dist/types/asset.d.ts.map +1 -1
- package/dist/types/capabilities.d.ts +11 -0
- package/dist/types/capabilities.d.ts.map +1 -1
- package/dist/types/capabilities.js +20 -6
- package/dist/types/config.d.ts +127 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/utils/asset-reference-walk.d.ts +44 -0
- package/dist/utils/asset-reference-walk.d.ts.map +1 -0
- package/dist/utils/asset-reference-walk.js +143 -0
- package/dist/utils/image-url.d.ts +61 -26
- package/dist/utils/image-url.d.ts.map +1 -1
- package/dist/utils/image-url.js +143 -26
- package/dist/utils/video-metadata.d.ts +39 -0
- package/dist/utils/video-metadata.d.ts.map +1 -0
- package/dist/utils/video-metadata.js +160 -0
- package/package.json +6 -1
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage key layout.
|
|
3
|
+
*
|
|
4
|
+
* Every asset owns a directory named by its id, and the file it was uploaded
|
|
5
|
+
* with is `original.{ext}` inside it:
|
|
6
|
+
*
|
|
7
|
+
* {assetId}/original.png
|
|
8
|
+
* {assetId}/w800-a1b2c3.webp ← later, generated variants
|
|
9
|
+
*
|
|
10
|
+
* Two properties matter, and both come from the same decision:
|
|
11
|
+
*
|
|
12
|
+
* - **Derivable.** The key follows from the asset id alone, so a sibling — a
|
|
13
|
+
* resized variant — can be addressed without reading the row back or knowing
|
|
14
|
+
* how the adapter stores things. The previous flat layout invented a name per
|
|
15
|
+
* adapter (` (1)` suffixes locally, timestamp + random on S3), which made
|
|
16
|
+
* `asset.path` unpredictable and left nowhere to put a variant.
|
|
17
|
+
* - **Opaque.** No organization segment and no user-supplied filename. The org
|
|
18
|
+
* lives on the row, so putting it in the key would leak org ids into storage
|
|
19
|
+
* paths and force a copy if an asset ever moved between orgs; user filenames
|
|
20
|
+
* in keys invite collisions and traversal for no benefit, since the display
|
|
21
|
+
* name is `asset.originalFilename` and is free to change independently.
|
|
22
|
+
*
|
|
23
|
+
* Assets stored under the old flat layout keep their existing `path` and keep
|
|
24
|
+
* working — this applies to new uploads only.
|
|
25
|
+
*/
|
|
26
|
+
/** Extensions we'll accept straight from a user-supplied filename. */
|
|
27
|
+
const EXTENSION_PATTERN = /^[a-z0-9]{1,12}$/;
|
|
28
|
+
/** Fallbacks for filenames that arrive without a usable extension. */
|
|
29
|
+
const MIME_EXTENSIONS = {
|
|
30
|
+
'image/jpeg': 'jpg',
|
|
31
|
+
'image/png': 'png',
|
|
32
|
+
'image/gif': 'gif',
|
|
33
|
+
'image/webp': 'webp',
|
|
34
|
+
'image/avif': 'avif',
|
|
35
|
+
'image/svg+xml': 'svg',
|
|
36
|
+
'application/pdf': 'pdf'
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Pick a safe extension for a stored file.
|
|
40
|
+
*
|
|
41
|
+
* Prefers the uploaded filename's own extension, falls back to the MIME type,
|
|
42
|
+
* and finally to `bin`. The result is always lowercase alphanumerics, so it
|
|
43
|
+
* can't introduce a path separator or a leading dot of its own.
|
|
44
|
+
*/
|
|
45
|
+
export function extensionFor(originalFilename, mimeType) {
|
|
46
|
+
const lastDot = originalFilename.lastIndexOf('.');
|
|
47
|
+
if (lastDot > -1) {
|
|
48
|
+
const candidate = originalFilename.slice(lastDot + 1).toLowerCase();
|
|
49
|
+
if (EXTENSION_PATTERN.test(candidate))
|
|
50
|
+
return candidate;
|
|
51
|
+
}
|
|
52
|
+
if (mimeType && MIME_EXTENSIONS[mimeType])
|
|
53
|
+
return MIME_EXTENSIONS[mimeType];
|
|
54
|
+
return 'bin';
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Adapter-relative key for an asset's original file: `{assetId}/original.{ext}`.
|
|
58
|
+
*/
|
|
59
|
+
export function buildOriginalKey(assetId, originalFilename, mimeType) {
|
|
60
|
+
return `${assetId}/original.${extensionFor(originalFilename, mimeType)}`;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Public URL for an asset: the `/media/:id/:filename` route.
|
|
64
|
+
*
|
|
65
|
+
* The route resolves the asset by id alone — the filename segment is cosmetic,
|
|
66
|
+
* there so a saved file lands with a sensible name and so the URL is readable.
|
|
67
|
+
* That's what lets an asset be renamed without touching storage: only this URL
|
|
68
|
+
* changes, and the bytes stay where they are.
|
|
69
|
+
*/
|
|
70
|
+
export function buildAssetUrl(assetId, originalFilename) {
|
|
71
|
+
return `/media/${assetId}/${encodeURIComponent(originalFilename)}`;
|
|
72
|
+
}
|
|
73
|
+
// --- Variants -------------------------------------------------------------
|
|
74
|
+
//
|
|
75
|
+
// A derivative is addressed by the same `/media/{id}/{filename}` route as the
|
|
76
|
+
// original, with the variant encoded in the filename segment: `w800-a1b2c3.webp`.
|
|
77
|
+
//
|
|
78
|
+
// Reusing the route rather than adding one is the security-relevant decision.
|
|
79
|
+
// The route already resolves the asset, checks whether its field is private,
|
|
80
|
+
// and verifies the caller's organization. A separate `/image` endpoint would
|
|
81
|
+
// have to reimplement all of that, and the failure mode if it drifted is ugly:
|
|
82
|
+
// a *public* derivative of a *private* original, sitting in the bucket forever
|
|
83
|
+
// under a guessable key. That is exactly the hole Payload users hit when they
|
|
84
|
+
// hand resizing to Next.js's image optimizer, which bypasses access control.
|
|
85
|
+
//
|
|
86
|
+
// The `configHash` in the name is what makes a variant immutable: change the
|
|
87
|
+
// quality or the ladder and every URL changes, so a cached copy is never
|
|
88
|
+
// stale and old derivatives are simply orphaned rather than overwritten. That
|
|
89
|
+
// in turn is what lets a variant be served `immutable` for a year.
|
|
90
|
+
/** Format every derivative is encoded in. Not configurable at V1. */
|
|
91
|
+
/**
|
|
92
|
+
* Filename segment that addresses a video's poster frame rather than the asset
|
|
93
|
+
* itself: `/media/{id}/poster.webp`.
|
|
94
|
+
*
|
|
95
|
+
* A poster is deliberately not an image *variant*. Variants are a responsive
|
|
96
|
+
* ladder keyed by width and config hash, regenerated when the image config
|
|
97
|
+
* changes; a poster is one derived frame whose only input is the video, so it
|
|
98
|
+
* has no ladder, no hash, and nothing to regenerate against.
|
|
99
|
+
*/
|
|
100
|
+
export const POSTER_FILENAME = 'poster.webp';
|
|
101
|
+
/** Storage key for a video's poster frame, alongside its original. */
|
|
102
|
+
export function buildPosterKey(assetId) {
|
|
103
|
+
return `${assetId}/${POSTER_FILENAME}`;
|
|
104
|
+
}
|
|
105
|
+
/** Public URL for a video's poster frame. */
|
|
106
|
+
export function buildPosterUrl(assetId) {
|
|
107
|
+
return `/media/${assetId}/${POSTER_FILENAME}`;
|
|
108
|
+
}
|
|
109
|
+
export const VARIANT_FORMAT = 'webp';
|
|
110
|
+
/** `w800-a1b2c3.webp` — width, config hash, format. */
|
|
111
|
+
const VARIANT_FILENAME_PATTERN = /^w(\d{1,5})-([a-z0-9]{1,12})\.([a-z0-9]{1,8})$/;
|
|
112
|
+
/**
|
|
113
|
+
* Recognise a variant request in the route's filename segment.
|
|
114
|
+
*
|
|
115
|
+
* Returns null for anything else — an original's real filename, a stale link,
|
|
116
|
+
* or junk — which the route serves as the original. The width is bounded by the
|
|
117
|
+
* pattern itself so an absurd value can't reach a resizer.
|
|
118
|
+
*/
|
|
119
|
+
export function parseVariantFilename(filename) {
|
|
120
|
+
const match = VARIANT_FILENAME_PATTERN.exec(filename);
|
|
121
|
+
if (!match)
|
|
122
|
+
return null;
|
|
123
|
+
const width = Number(match[1]);
|
|
124
|
+
if (!Number.isInteger(width) || width <= 0)
|
|
125
|
+
return null;
|
|
126
|
+
return { width, configHash: match[2], format: match[3] };
|
|
127
|
+
}
|
|
128
|
+
/** `w800-a1b2c3.webp` */
|
|
129
|
+
export function variantFilename(width, configHash) {
|
|
130
|
+
return `w${width}-${configHash}.${VARIANT_FORMAT}`;
|
|
131
|
+
}
|
|
132
|
+
/** Adapter-relative key for a derivative, a sibling of the original. */
|
|
133
|
+
export function buildVariantKey(assetId, width, configHash) {
|
|
134
|
+
return `${assetId}/${variantFilename(width, configHash)}`;
|
|
135
|
+
}
|
|
136
|
+
/** Public URL for a derivative, on the same route as the original. */
|
|
137
|
+
export function buildVariantUrl(assetId, width, configHash) {
|
|
138
|
+
return `/media/${assetId}/${variantFilename(width, configHash)}`;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Stable short hash of the image config.
|
|
142
|
+
*
|
|
143
|
+
* FNV-1a rather than a crypto digest because this has to run in the browser:
|
|
144
|
+
* `<Image>` builds variant URLs for derivatives that may not exist yet, so it
|
|
145
|
+
* needs the same hash the server will use, and Node's `crypto` isn't available
|
|
146
|
+
* to it. It is a cache key, not a security boundary — a collision would serve
|
|
147
|
+
* a correctly-sized image at a slightly different quality, which is why a
|
|
148
|
+
* 32-bit hash is enough.
|
|
149
|
+
*/
|
|
150
|
+
export function imageConfigHash(config) {
|
|
151
|
+
const canonical = `${[...config.widths].sort((a, b) => a - b).join(',')}|q${config.quality ?? ''}|f${VARIANT_FORMAT}`;
|
|
152
|
+
let hash = 0x811c9dc5;
|
|
153
|
+
for (let i = 0; i < canonical.length; i++) {
|
|
154
|
+
hash ^= canonical.charCodeAt(i);
|
|
155
|
+
// FNV prime, via shifts so this stays in 32-bit integer math.
|
|
156
|
+
hash = (hash + ((hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24))) >>> 0;
|
|
157
|
+
}
|
|
158
|
+
return hash.toString(36);
|
|
159
|
+
}
|
package/dist/types/asset.d.ts
CHANGED
|
@@ -1,3 +1,64 @@
|
|
|
1
|
+
import type { InjectedAsset } from '../image/types.js';
|
|
2
|
+
/** One generated derivative of an image. */
|
|
3
|
+
export interface AssetVariant {
|
|
4
|
+
/** Rendered width in pixels — always one of the configured ladder widths. */
|
|
5
|
+
w: number;
|
|
6
|
+
/** Rendered height, derived from the original's aspect ratio. */
|
|
7
|
+
h: number;
|
|
8
|
+
/** Adapter-relative storage key. */
|
|
9
|
+
key: string;
|
|
10
|
+
/**
|
|
11
|
+
* Adapter-specific path, as `StorageAdapter.store()` reported it.
|
|
12
|
+
*
|
|
13
|
+
* Recorded rather than derived from the original's path, because how an
|
|
14
|
+
* adapter roots storage is its own business — local joins a base directory,
|
|
15
|
+
* S3 prefixes a bucket. Rebuilding it by string surgery on `asset.path`
|
|
16
|
+
* happens to work for both today and breaks on the first adapter that does
|
|
17
|
+
* something else.
|
|
18
|
+
*/
|
|
19
|
+
path: string;
|
|
20
|
+
/**
|
|
21
|
+
* Public URL on the `/media` route.
|
|
22
|
+
*
|
|
23
|
+
* Contains no part of the user's filename — it is `{assetId}/w{width}-{hash}`
|
|
24
|
+
* — so renaming an asset leaves every variant URL and key untouched.
|
|
25
|
+
*/
|
|
26
|
+
url: string;
|
|
27
|
+
bytes: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The derivative record for one asset.
|
|
31
|
+
*
|
|
32
|
+
* Lives on `asset.metadata`, which is already `jsonb` (Postgres) / JSON text
|
|
33
|
+
* (SQLite), so recording variants needs no schema change on either adapter.
|
|
34
|
+
*/
|
|
35
|
+
export interface AssetVariantRecord {
|
|
36
|
+
/**
|
|
37
|
+
* Hash of the image config the variants were generated under. Variants whose
|
|
38
|
+
* hash no longer matches the current config are ignored rather than deleted —
|
|
39
|
+
* they're simply never addressed again, since every URL embeds the hash.
|
|
40
|
+
*/
|
|
41
|
+
config: string;
|
|
42
|
+
generatedAt: string;
|
|
43
|
+
widths: AssetVariant[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Known shape of `asset.metadata`.
|
|
47
|
+
*
|
|
48
|
+
* Deliberately open (`[key: string]: any`): metadata also carries whatever the
|
|
49
|
+
* upload path extracted from the image and whatever a caller attached, and
|
|
50
|
+
* narrowing those would break callers for no gain. The point is that the keys
|
|
51
|
+
* the CMS itself depends on are typed, so `variants` isn't reached through a
|
|
52
|
+
* cast at every call site.
|
|
53
|
+
*/
|
|
54
|
+
export interface AssetMetadata {
|
|
55
|
+
variants?: AssetVariantRecord;
|
|
56
|
+
/** Schema type the asset was uploaded into — used for privacy resolution. */
|
|
57
|
+
schemaType?: string;
|
|
58
|
+
/** Field path within that schema type. */
|
|
59
|
+
fieldPath?: string;
|
|
60
|
+
[key: string]: any;
|
|
61
|
+
}
|
|
1
62
|
/**
|
|
2
63
|
* Asset type - represents uploaded files
|
|
3
64
|
*/
|
|
@@ -14,7 +75,12 @@ export interface Asset {
|
|
|
14
75
|
storageAdapter: string;
|
|
15
76
|
width: number | null;
|
|
16
77
|
height: number | null;
|
|
17
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Nullable because the column is: rows predating a given feature, or created
|
|
80
|
+
* without extracted image metadata, genuinely have no value here. Typing it
|
|
81
|
+
* non-null would be a lie the adapters have to cast their way out of.
|
|
82
|
+
*/
|
|
83
|
+
metadata: AssetMetadata | null;
|
|
18
84
|
title: string | null;
|
|
19
85
|
description: string | null;
|
|
20
86
|
alt: string | null;
|
|
@@ -47,18 +113,23 @@ export interface NewAsset {
|
|
|
47
113
|
createdAt?: Date | null;
|
|
48
114
|
updatedAt?: Date | null;
|
|
49
115
|
}
|
|
50
|
-
|
|
116
|
+
/**
|
|
117
|
+
* Sanity-style image reference, plus whatever asset injection has filled in.
|
|
118
|
+
*
|
|
119
|
+
* The injected half is inherited from `InjectedAsset` rather than restated here.
|
|
120
|
+
* They are the same fields at runtime — `injectAssetUrls` writes `url`, `alt`,
|
|
121
|
+
* `width`, `height` and `srcset` — and when this interface listed only `url` and
|
|
122
|
+
* `alt`, a document's own generated type denied the existence of the three the
|
|
123
|
+
* responsive pipeline exists to produce. Reading `image.asset.srcset` off a typed
|
|
124
|
+
* document was a type error even though the value was right there.
|
|
125
|
+
*
|
|
126
|
+
* NOT part of stored data: injection happens at render time (`injectAssetUrls`
|
|
127
|
+
* server-side, the editor's live preview client-side), so all of it is absent
|
|
128
|
+
* until then.
|
|
129
|
+
*/
|
|
130
|
+
export interface ImageAsset extends InjectedAsset {
|
|
51
131
|
_type: 'reference';
|
|
52
132
|
_ref: string;
|
|
53
|
-
/**
|
|
54
|
-
* Resolved public URL. NOT part of stored data — it's injected at render time
|
|
55
|
-
* (by `AssetService.injectAssetUrls` server-side, and by the editor's live preview
|
|
56
|
-
* client-side) so the frontend can read `image.asset.url` directly. Absent until then.
|
|
57
|
-
*/
|
|
58
|
-
url?: string;
|
|
59
|
-
/** The asset's default alt text, injected alongside `url`. Per-placement overrides live
|
|
60
|
-
* on `ImageValue.alt`; render precedence is `value.alt || asset.alt`. */
|
|
61
|
-
alt?: string;
|
|
62
133
|
}
|
|
63
134
|
export interface ImageCrop {
|
|
64
135
|
top: number;
|
|
@@ -85,7 +156,16 @@ export interface ImageValue {
|
|
|
85
156
|
alt?: string;
|
|
86
157
|
[key: string]: any;
|
|
87
158
|
}
|
|
88
|
-
|
|
159
|
+
/**
|
|
160
|
+
* A file reference, with the fields injection adds at render time.
|
|
161
|
+
*
|
|
162
|
+
* Extends `InjectedAsset` for the same reason `ImageAsset` does: `collectAssetRefs`
|
|
163
|
+
* walks `{ asset: { _ref } }` generically, so a file field's `url` is populated
|
|
164
|
+
* exactly like an image's — but the type said otherwise, making
|
|
165
|
+
* `video.asset.url` a type error on a value that was right there. Only `url` is
|
|
166
|
+
* meaningful for a non-image; the dimension fields stay undefined.
|
|
167
|
+
*/
|
|
168
|
+
export interface FileAsset extends InjectedAsset {
|
|
89
169
|
_type: 'reference';
|
|
90
170
|
_ref: string;
|
|
91
171
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asset.d.ts","sourceRoot":"","sources":["../../src/lib/types/asset.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"asset.d.ts","sourceRoot":"","sources":["../../src/lib/types/asset.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEpD,4CAA4C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AM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,YAAY;IAC5B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,UAAU;IAC1B,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,UAAU,CAAC;IAClB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACnB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,SAAU,SAAQ,aAAa;IAC/C,KAAK,EAAE,WAAW,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,SAAS;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,SAAS,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACnB"}
|
|
@@ -134,6 +134,17 @@ export declare function coarseApiKeyCapabilities(permissions: readonly string[])
|
|
|
134
134
|
* 3. API keys → derived from `read`/`write` scopes.
|
|
135
135
|
* 4. Session fallback → built-in seed for the org role.
|
|
136
136
|
* 5. Partial session → empty set.
|
|
137
|
+
*
|
|
138
|
+
* Every branch is passed through {@link normalizeCapabilities}, so the
|
|
139
|
+
* write-implies-read invariant holds at *resolve* time and not merely at write
|
|
140
|
+
* time. `normalizeCapabilities` is otherwise only applied by the role and
|
|
141
|
+
* API-key request schemas, which covers the admin UI but not seeds, migrations,
|
|
142
|
+
* plugins, or rows written directly — and the read routes now depend on
|
|
143
|
+
* `asset.read`/`document.read` actually being present. Without this, a role
|
|
144
|
+
* persisted with `asset.upload` alone would be able to upload an asset and then
|
|
145
|
+
* get a 403 listing it. It can only ever add a read cap alongside a write cap
|
|
146
|
+
* that already survived whatever clamp produced the set, so it never widens
|
|
147
|
+
* access beyond what the principal was already granted.
|
|
137
148
|
*/
|
|
138
149
|
export declare function resolveCapabilities(auth: Auth): ReadonlySet<string>;
|
|
139
150
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../src/lib/types/capabilities.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAEnB,eAAe,GACf,iBAAiB,GACjB,iBAAiB,GACjB,iBAAiB,GACjB,kBAAkB,GAClB,oBAAoB,GAEpB,YAAY,GACZ,cAAc,GACd,cAAc,GAEd,eAAe,GACf,eAAe,GACf,mBAAmB,GACnB,eAAe,GACf,aAAa,GACb,cAAc,GAEd,wBAAwB,CAAC;AAM5B;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAAE,SAAS,UAAU,EAiBxC,CAAC;AAEX;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACpC,2EAA2E;IAC3E,EAAE,EAAE,MAAM,CAAC;IACX,yCAAyC;IACzC,KAAK,EAAE,MAAM,CAAC;IACd,kDAAkD;IAClD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yDAAyD;IACzD,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC/B,EAAE,EAAE,MAAM,EACV,IAAI,GAAE,OAAO,CAAC,IAAI,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAM,GAClD,oBAAoB,CAOtB;AAED,gGAAgG;AAChG,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAIvD;AAED,4EAA4E;AAC5E,eAAO,M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AM,GAAG,EAAE,CAAC,GAAG,OAAO,CAEzF;AAgBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAIjF;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,IAAI,GAAG,WAAW,CAAC,MAAM,CAAC,CAEnE;AA8BD;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAInE;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC3B,4EAA4E;IAC5E,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,0EAA0E;IAC1E,YAAY,EAAE,UAAU,EAAE,CAAC;CAC3B"}
|
|
@@ -338,16 +338,31 @@ export function coarseApiKeyCapabilities(permissions) {
|
|
|
338
338
|
* 3. API keys → derived from `read`/`write` scopes.
|
|
339
339
|
* 4. Session fallback → built-in seed for the org role.
|
|
340
340
|
* 5. Partial session → empty set.
|
|
341
|
+
*
|
|
342
|
+
* Every branch is passed through {@link normalizeCapabilities}, so the
|
|
343
|
+
* write-implies-read invariant holds at *resolve* time and not merely at write
|
|
344
|
+
* time. `normalizeCapabilities` is otherwise only applied by the role and
|
|
345
|
+
* API-key request schemas, which covers the admin UI but not seeds, migrations,
|
|
346
|
+
* plugins, or rows written directly — and the read routes now depend on
|
|
347
|
+
* `asset.read`/`document.read` actually being present. Without this, a role
|
|
348
|
+
* persisted with `asset.upload` alone would be able to upload an asset and then
|
|
349
|
+
* get a 403 listing it. It can only ever add a read cap alongside a write cap
|
|
350
|
+
* that already survived whatever clamp produced the set, so it never widens
|
|
351
|
+
* access beyond what the principal was already granted.
|
|
341
352
|
*/
|
|
342
353
|
export function resolveCapabilities(auth) {
|
|
354
|
+
return new Set(normalizeCapabilities(rawCapabilities(auth)));
|
|
355
|
+
}
|
|
356
|
+
const EMPTY_CAPS = [];
|
|
357
|
+
function rawCapabilities(auth) {
|
|
343
358
|
if (auth.type === 'partial_session')
|
|
344
|
-
return
|
|
359
|
+
return EMPTY_CAPS;
|
|
345
360
|
// Authoritative source once hydrated by the auth hook.
|
|
346
361
|
if ('capabilities' in auth && Array.isArray(auth.capabilities)) {
|
|
347
|
-
return
|
|
362
|
+
return auth.capabilities;
|
|
348
363
|
}
|
|
349
364
|
if (auth.type === 'session' && INSTANCE_ROLE_OVERRIDES.has(auth.user.role)) {
|
|
350
|
-
return
|
|
365
|
+
return ALL_CAPABILITIES;
|
|
351
366
|
}
|
|
352
367
|
// Reached only when the key carries no capability list at all — an explicit
|
|
353
368
|
// one, including an empty one, is authoritative and was returned above.
|
|
@@ -355,11 +370,11 @@ export function resolveCapabilities(auth) {
|
|
|
355
370
|
// allowlist that a clamp stripped to nothing would otherwise resolve to more
|
|
356
371
|
// than it asked for.
|
|
357
372
|
if (auth.type === 'api_key') {
|
|
358
|
-
return
|
|
373
|
+
return coarseApiKeyCapabilities(auth.permissions);
|
|
359
374
|
}
|
|
360
375
|
// Session without pre-resolved capabilities → seed fallback.
|
|
361
376
|
const builtin = BUILTIN_ROLE_SEED[auth.organizationRole];
|
|
362
|
-
return builtin ?
|
|
377
|
+
return builtin ? builtin.capabilities : EMPTY_CAPS;
|
|
363
378
|
}
|
|
364
379
|
/**
|
|
365
380
|
* Resolve the effective organization role name for an Auth, honoring
|
|
@@ -377,4 +392,3 @@ export function effectiveOrganizationRole(auth) {
|
|
|
377
392
|
return 'owner';
|
|
378
393
|
return auth.organizationRole ?? null;
|
|
379
394
|
}
|
|
380
|
-
const EMPTY = new Set();
|
package/dist/types/config.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type { EmailAdapter } from '../email/index.js';
|
|
|
7
7
|
import type { AIProviderAdapter } from '../ai/index.js';
|
|
8
8
|
import type { GraphQLConfig } from '../graphql/index.js';
|
|
9
9
|
import type { AphexEnv } from '../server/api/index.js';
|
|
10
|
+
import type { Asset } from './asset.js';
|
|
10
11
|
import type { SchemaType } from './schemas.js';
|
|
11
12
|
import type { Logger } from '../utils/logger.js';
|
|
12
13
|
import type { CMSPlugin } from '../plugins/types.js';
|
|
@@ -25,6 +26,132 @@ export interface CMSConfig {
|
|
|
25
26
|
*/
|
|
26
27
|
plugins?: CMSPlugin[];
|
|
27
28
|
storage?: StorageAdapter | null;
|
|
29
|
+
/**
|
|
30
|
+
* Include object storage in the `/aphex-health` response. Off by default.
|
|
31
|
+
*
|
|
32
|
+
* Opt-in because it costs money on metered storage: `isHealthy()` is a real
|
|
33
|
+
* network round-trip to the bucket, `/aphex-health` is unauthenticated, and
|
|
34
|
+
* the probe happens per process. The result is cached for 30s, which caps a
|
|
35
|
+
* single process at ~88k requests/month — inside R2's free tier and around
|
|
36
|
+
* $0.03/month past it — but that multiplies by instance count, so it is your
|
|
37
|
+
* decision to make rather than a default you inherit.
|
|
38
|
+
*
|
|
39
|
+
* Enabling it never changes the HTTP status code: unhealthy storage reports
|
|
40
|
+
* `status: 'degraded'` with a 200, so a bucket outage cannot pull healthy
|
|
41
|
+
* nodes out of a load balancer.
|
|
42
|
+
*/
|
|
43
|
+
storageHealthCheck?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Serve selected assets as a short-lived signed-URL redirect instead of
|
|
46
|
+
* proxying their bytes.
|
|
47
|
+
*
|
|
48
|
+
* `/media/:id/:filename` proxies by default, so its access checks actually
|
|
49
|
+
* decide whether the caller gets the file. That costs a round-trip through
|
|
50
|
+
* the app for every byte, which is the wrong trade for large files — a 200MB
|
|
51
|
+
* video download shouldn't occupy a server process. Return `true` for those
|
|
52
|
+
* and the route redirects to a signed URL from the storage adapter instead.
|
|
53
|
+
*
|
|
54
|
+
* The access checks run *before* the predicate either way: a signed URL is
|
|
55
|
+
* only ever minted for a request that was already allowed to read the file.
|
|
56
|
+
*
|
|
57
|
+
* Requires `getSignedUrl` on the storage adapter; without it the route
|
|
58
|
+
* proxies anyway rather than failing, since serving the file correctly beats
|
|
59
|
+
* refusing to serve it at all.
|
|
60
|
+
*
|
|
61
|
+
* Deliberately one predicate and one duration rather than a matrix of
|
|
62
|
+
* per-collection toggles — the whole surface is "which files skip the proxy,
|
|
63
|
+
* and for how long".
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* signedDownloads: {
|
|
67
|
+
* shouldUseSignedURL: (asset) => asset.size > 25 * 1024 * 1024
|
|
68
|
+
* }
|
|
69
|
+
*/
|
|
70
|
+
signedDownloads?: {
|
|
71
|
+
shouldUseSignedURL: (asset: Asset) => boolean | Promise<boolean>;
|
|
72
|
+
/** Signed-URL lifetime in seconds. Default 900 (15 minutes). */
|
|
73
|
+
expiresIn?: number;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Responsive image derivatives.
|
|
77
|
+
*
|
|
78
|
+
* One width ladder and a quality, and that is deliberately the entire
|
|
79
|
+
* surface. Derivatives are generated **on first request**, not at upload:
|
|
80
|
+
* a width that nobody asks for is never produced, changing the ladder needs
|
|
81
|
+
* no migration or regeneration script, and assets uploaded before the
|
|
82
|
+
* pipeline existed are backfilled simply by being viewed.
|
|
83
|
+
*
|
|
84
|
+
* Enabled by default. Sharp is already a hard dependency, originals are kept
|
|
85
|
+
* byte-for-byte, and the admin's own thumbnails are the smallest rung — so an
|
|
86
|
+
* opt-in default would mean the admin grid keeps serving full-size originals
|
|
87
|
+
* to everyone who never found the flag.
|
|
88
|
+
*
|
|
89
|
+
* Set to `null` to disable: `/media` then always serves the original.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* images: { widths: [320, 640, 960, 1280, 1920], quality: 80 }
|
|
93
|
+
*/
|
|
94
|
+
images?: {
|
|
95
|
+
/**
|
|
96
|
+
* The widths that may be generated, in pixels. A closed set on purpose —
|
|
97
|
+
* it is the allowlist that stops a request for arbitrary dimensions
|
|
98
|
+
* turning into unbounded CPU and storage. A request for a width outside
|
|
99
|
+
* it serves the original rather than generating anything.
|
|
100
|
+
*/
|
|
101
|
+
widths: number[];
|
|
102
|
+
/** WebP quality, 1–100. Default 80. */
|
|
103
|
+
quality?: number;
|
|
104
|
+
} | null;
|
|
105
|
+
/**
|
|
106
|
+
* Upload constraints.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* upload: { maxFileSize: 100 * 1024 * 1024 } // 100MB
|
|
110
|
+
*/
|
|
111
|
+
upload?: {
|
|
112
|
+
/**
|
|
113
|
+
* Largest accepted request body, in bytes. Defaults to
|
|
114
|
+
* {@link MAX_UPLOAD_BYTES} (10MB).
|
|
115
|
+
*
|
|
116
|
+
* This is one number rather than several because it's the *only* ceiling
|
|
117
|
+
* that matters: it's enforced by the `bodyLimit` middleware on `/api/*`,
|
|
118
|
+
* which rejects with 413 before the body is buffered, so nothing larger
|
|
119
|
+
* ever reaches a route or a storage adapter. The admin UI reads the
|
|
120
|
+
* effective value back from the assets endpoint and refuses oversized
|
|
121
|
+
* files before sending them.
|
|
122
|
+
*
|
|
123
|
+
* This is the *only* place to set it. `createCMSConfig` pushes the resolved
|
|
124
|
+
* value into the storage adapter, overriding whatever `maxFileSize` the
|
|
125
|
+
* adapter was constructed with — so the request check, the direct-upload
|
|
126
|
+
* grant, the limit the admin reads back, and the adapter's own backstop are
|
|
127
|
+
* all the same number and cannot disagree.
|
|
128
|
+
*
|
|
129
|
+
* The one thing it can't raise is a serverless host's own request cap.
|
|
130
|
+
* Vercel Functions reject a body over 4.5MB before the app is invoked, and
|
|
131
|
+
* unlike responses there's no streaming escape — large uploads there need
|
|
132
|
+
* direct-to-storage ({@link direct}).
|
|
133
|
+
*/
|
|
134
|
+
maxFileSize?: number;
|
|
135
|
+
/**
|
|
136
|
+
* Let the browser upload straight to object storage, bypassing this app.
|
|
137
|
+
*
|
|
138
|
+
* Off by default, and deliberately not inferred from "the adapter can
|
|
139
|
+
* sign": it additionally requires **CORS `PUT` on the bucket from your
|
|
140
|
+
* site's origin**, which nothing here can detect. Turning it on without
|
|
141
|
+
* that configured makes every upload fail in the browser, so it has to be
|
|
142
|
+
* a decision someone takes rather than a default they discover.
|
|
143
|
+
*
|
|
144
|
+
* Worth turning on when deploying somewhere that caps request bodies —
|
|
145
|
+
* Vercel Functions reject anything over 4.5MB before the app is invoked,
|
|
146
|
+
* and unlike responses there is no streaming escape, so this is the only
|
|
147
|
+
* way a larger file can be uploaded at all.
|
|
148
|
+
*
|
|
149
|
+
* Ignored when the storage adapter can't sign uploads or no
|
|
150
|
+
* `security.secretEncryptionKey` is set; the admin falls back to
|
|
151
|
+
* uploading through the app, which works everywhere.
|
|
152
|
+
*/
|
|
153
|
+
direct?: boolean;
|
|
154
|
+
};
|
|
28
155
|
email?: EmailAdapter | null;
|
|
29
156
|
/** Model backend for the in-admin agent. Omit to leave the agent panel disabled. */
|
|
30
157
|
aiProvider?: AIProviderAdapter | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/lib/types/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,M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;;;;;;;;;OAwBG;IACH,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC;CACpC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** One asset reference found in a document's data. */
|
|
2
|
+
export interface FoundAssetReference {
|
|
3
|
+
/** The referenced asset's id. */
|
|
4
|
+
assetId: string;
|
|
5
|
+
/**
|
|
6
|
+
* Dotted/bracketed path to the field holding the reference, e.g.
|
|
7
|
+
* `coverImage`, `seo.ogImage`, `content[3]`, `gallery.images[2]`.
|
|
8
|
+
*
|
|
9
|
+
* Array indices are positions at the time of the write. They are a label for
|
|
10
|
+
* a human, not a stable address: reordering an array changes them, and the
|
|
11
|
+
* index is rebuilt on every write anyway, so nothing depends on them lasting.
|
|
12
|
+
*/
|
|
13
|
+
fieldPath: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Collect every asset reference in a document's data.
|
|
17
|
+
*
|
|
18
|
+
* Deduplicated by `assetId` + `fieldPath`, so the same asset used twice in
|
|
19
|
+
* different fields yields two rows, while the same asset at the same path (which
|
|
20
|
+
* shouldn't happen, but costs nothing to guard) yields one.
|
|
21
|
+
*/
|
|
22
|
+
export declare function collectAssetReferences(data: unknown): FoundAssetReference[];
|
|
23
|
+
/**
|
|
24
|
+
* Every asset id reachable anywhere in the data, ignoring structure entirely.
|
|
25
|
+
*
|
|
26
|
+
* The unstructured twin of {@link collectAssetReferences}, and deliberately dumb:
|
|
27
|
+
* it descends through everything and collects any `asset: { _ref }` it meets, at
|
|
28
|
+
* any depth, under any wrapper, with no notion of which shapes are legitimate.
|
|
29
|
+
* It therefore cannot tell you *where* a reference lives, which is why it is not
|
|
30
|
+
* the indexer.
|
|
31
|
+
*
|
|
32
|
+
* It exists to check the indexer. The walker is a structural allowlist — it finds
|
|
33
|
+
* references in the shapes it knows — while the delete guard is a substring scan
|
|
34
|
+
* that finds them in shapes nobody anticipated. That asymmetry is permanent, and
|
|
35
|
+
* every gap it has produced looked identical from the outside: an asset that
|
|
36
|
+
* reads as unused and then refuses to delete. Comparing these two sets turns the
|
|
37
|
+
* next such gap into a log line at rebuild time instead of a support question
|
|
38
|
+
* months later.
|
|
39
|
+
*
|
|
40
|
+
* Not a substitute for the guard's scan: that one matches raw text, so it also
|
|
41
|
+
* catches an id sitting somewhere this doesn't model at all.
|
|
42
|
+
*/
|
|
43
|
+
export declare function collectAssetIdsUnstructured(data: unknown): Set<string>;
|
|
44
|
+
//# sourceMappingURL=asset-reference-walk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset-reference-walk.d.ts","sourceRoot":"","sources":["../../src/lib/utils/asset-reference-walk.ts"],"names":[],"mappings":"AAYA,sDAAsD;AACtD,MAAM,WAAW,mBAAmB;IACnC,iCAAiC;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;;;OAOG;IACH,SAAS,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,OAAO,GAAG,mBAAmB,EAAE,CAI3E;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,CAyBtE"}
|