canopycms 0.0.56 → 0.0.58
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/ai/json-to-markdown.js +74 -3
- package/dist/ai/json-to-markdown.js.map +1 -1
- package/dist/api/__test__/mock-client.d.ts +9 -5
- package/dist/api/__test__/mock-client.d.ts.map +1 -1
- package/dist/api/__test__/mock-client.js +15 -7
- package/dist/api/__test__/mock-client.js.map +1 -1
- package/dist/api/assets.d.ts +100 -36
- package/dist/api/assets.d.ts.map +1 -1
- package/dist/api/assets.js +338 -51
- package/dist/api/assets.js.map +1 -1
- package/dist/api/branch.d.ts +6 -0
- package/dist/api/branch.d.ts.map +1 -1
- package/dist/api/branch.js +63 -19
- package/dist/api/branch.js.map +1 -1
- package/dist/api/client.d.ts +16 -5
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +24 -6
- package/dist/api/client.js.map +1 -1
- package/dist/api/content.d.ts +2 -2
- package/dist/api/entries.d.ts +4 -4
- package/dist/api/entries.d.ts.map +1 -1
- package/dist/api/entries.js +10 -2
- package/dist/api/entries.js.map +1 -1
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js.map +1 -1
- package/dist/api/route-builder.d.ts +9 -0
- package/dist/api/route-builder.d.ts.map +1 -1
- package/dist/api/route-builder.js +1 -0
- package/dist/api/route-builder.js.map +1 -1
- package/dist/api/schema.d.ts +4 -4
- package/dist/api/types.d.ts +11 -1
- package/dist/api/types.d.ts.map +1 -1
- package/dist/assets/asset-prefixes.d.ts +31 -0
- package/dist/assets/asset-prefixes.d.ts.map +1 -0
- package/dist/assets/asset-prefixes.js +20 -0
- package/dist/assets/asset-prefixes.js.map +1 -0
- package/dist/assets/asset-src.d.ts +23 -0
- package/dist/assets/asset-src.d.ts.map +1 -0
- package/dist/assets/asset-src.js +28 -0
- package/dist/assets/asset-src.js.map +1 -0
- package/dist/assets/asset-url.d.ts +35 -0
- package/dist/assets/asset-url.d.ts.map +1 -0
- package/dist/assets/asset-url.js +77 -0
- package/dist/assets/asset-url.js.map +1 -0
- package/dist/assets/factory.d.ts +18 -0
- package/dist/assets/factory.d.ts.map +1 -0
- package/dist/assets/factory.js +42 -0
- package/dist/assets/factory.js.map +1 -0
- package/dist/assets/finalize.d.ts +36 -0
- package/dist/assets/finalize.d.ts.map +1 -0
- package/dist/assets/finalize.js +72 -0
- package/dist/assets/finalize.js.map +1 -0
- package/dist/assets/index.d.ts +20 -0
- package/dist/assets/index.d.ts.map +1 -0
- package/dist/assets/index.js +19 -0
- package/dist/assets/index.js.map +1 -0
- package/dist/assets/keys.d.ts +56 -0
- package/dist/assets/keys.d.ts.map +1 -0
- package/dist/assets/keys.js +88 -0
- package/dist/assets/keys.js.map +1 -0
- package/dist/assets/pipeline.d.ts +50 -0
- package/dist/assets/pipeline.d.ts.map +1 -0
- package/dist/assets/pipeline.js +202 -0
- package/dist/assets/pipeline.js.map +1 -0
- package/dist/assets/store-local.d.ts +84 -0
- package/dist/assets/store-local.d.ts.map +1 -0
- package/dist/assets/store-local.js +254 -0
- package/dist/assets/store-local.js.map +1 -0
- package/dist/assets/store-s3.d.ts +71 -0
- package/dist/assets/store-s3.d.ts.map +1 -0
- package/dist/assets/store-s3.js +183 -0
- package/dist/assets/store-s3.js.map +1 -0
- package/dist/assets/svg-sanitizer.d.ts +37 -0
- package/dist/assets/svg-sanitizer.d.ts.map +1 -0
- package/dist/assets/svg-sanitizer.js +222 -0
- package/dist/assets/svg-sanitizer.js.map +1 -0
- package/dist/assets/transform-directives.d.ts +97 -0
- package/dist/assets/transform-directives.d.ts.map +1 -0
- package/dist/assets/transform-directives.js +267 -0
- package/dist/assets/transform-directives.js.map +1 -0
- package/dist/assets/transform.d.ts +51 -0
- package/dist/assets/transform.d.ts.map +1 -0
- package/dist/assets/transform.js +190 -0
- package/dist/assets/transform.js.map +1 -0
- package/dist/assets/types.d.ts +82 -0
- package/dist/assets/types.d.ts.map +1 -0
- package/dist/assets/types.js +10 -0
- package/dist/assets/types.js.map +1 -0
- package/dist/authorization/groups/schema.d.ts +2 -2
- package/dist/authorization/permissions/schema.d.ts +2 -2
- package/dist/branch-metadata.d.ts +71 -6
- package/dist/branch-metadata.d.ts.map +1 -1
- package/dist/branch-metadata.js +132 -116
- package/dist/branch-metadata.js.map +1 -1
- package/dist/branch-registry.d.ts +78 -9
- package/dist/branch-registry.d.ts.map +1 -1
- package/dist/branch-registry.js +155 -29
- package/dist/branch-registry.js.map +1 -1
- package/dist/branch-schema-cache.d.ts +126 -11
- package/dist/branch-schema-cache.d.ts.map +1 -1
- package/dist/branch-schema-cache.js +208 -58
- package/dist/branch-schema-cache.js.map +1 -1
- package/dist/cli/generate-ai-content.js +1993 -1506
- package/dist/cli/init.js +16 -4
- package/dist/cli/migrate.d.ts.map +1 -1
- package/dist/cli/migrate.js +25 -0
- package/dist/cli/migrate.js.map +1 -1
- package/dist/cli/sync.js +5 -5
- package/dist/cli/sync.js.map +1 -1
- package/dist/comment-store.d.ts +45 -15
- package/dist/comment-store.d.ts.map +1 -1
- package/dist/comment-store.js +80 -101
- package/dist/comment-store.js.map +1 -1
- package/dist/config/helpers.d.ts.map +1 -1
- package/dist/config/helpers.js +2 -1
- package/dist/config/helpers.js.map +1 -1
- package/dist/config/index.d.ts +2 -2
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +1 -1
- package/dist/config/index.js.map +1 -1
- package/dist/config/schemas/config.d.ts +10 -0
- package/dist/config/schemas/config.d.ts.map +1 -1
- package/dist/config/schemas/field.d.ts +38 -3
- package/dist/config/schemas/field.d.ts.map +1 -1
- package/dist/config/schemas/field.js +18 -0
- package/dist/config/schemas/field.js.map +1 -1
- package/dist/config/schemas/media.d.ts +8 -0
- package/dist/config/schemas/media.d.ts.map +1 -1
- package/dist/config/schemas/media.js +9 -0
- package/dist/config/schemas/media.js.map +1 -1
- package/dist/config/types.d.ts +43 -3
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js +4 -1
- package/dist/config/types.js.map +1 -1
- package/dist/content-index-generation.d.ts +40 -4
- package/dist/content-index-generation.d.ts.map +1 -1
- package/dist/content-index-generation.js +70 -73
- package/dist/content-index-generation.js.map +1 -1
- package/dist/content-store.d.ts +63 -0
- package/dist/content-store.d.ts.map +1 -1
- package/dist/content-store.js +421 -194
- package/dist/content-store.js.map +1 -1
- package/dist/editor/CanopyEditor.d.ts.map +1 -1
- package/dist/editor/CanopyEditor.js +1 -1
- package/dist/editor/CanopyEditor.js.map +1 -1
- package/dist/editor/Editor.d.ts +2 -0
- package/dist/editor/Editor.d.ts.map +1 -1
- package/dist/editor/Editor.js +82 -80
- package/dist/editor/Editor.js.map +1 -1
- package/dist/editor/FormRenderer.d.ts.map +1 -1
- package/dist/editor/FormRenderer.js +9 -0
- package/dist/editor/FormRenderer.js.map +1 -1
- package/dist/editor/components/EditorSidebar.d.ts +6 -1
- package/dist/editor/components/EditorSidebar.d.ts.map +1 -1
- package/dist/editor/components/EditorSidebar.js +4 -3
- package/dist/editor/components/EditorSidebar.js.map +1 -1
- package/dist/editor/context/AssetContext.d.ts +25 -0
- package/dist/editor/context/AssetContext.d.ts.map +1 -0
- package/dist/editor/context/AssetContext.js +26 -0
- package/dist/editor/context/AssetContext.js.map +1 -0
- package/dist/editor/context/index.d.ts +1 -0
- package/dist/editor/context/index.d.ts.map +1 -1
- package/dist/editor/context/index.js +1 -0
- package/dist/editor/context/index.js.map +1 -1
- package/dist/editor/fields/ImageField.d.ts +22 -0
- package/dist/editor/fields/ImageField.d.ts.map +1 -0
- package/dist/editor/fields/ImageField.js +100 -0
- package/dist/editor/fields/ImageField.js.map +1 -0
- package/dist/editor/fields/MarkdownField.d.ts.map +1 -1
- package/dist/editor/fields/MarkdownField.js +30 -4
- package/dist/editor/fields/MarkdownField.js.map +1 -1
- package/dist/editor/fields/MdxImageDialog.d.ts +16 -0
- package/dist/editor/fields/MdxImageDialog.d.ts.map +1 -0
- package/dist/editor/fields/MdxImageDialog.js +73 -0
- package/dist/editor/fields/MdxImageDialog.js.map +1 -0
- package/dist/editor/media/AssetCard.d.ts +21 -0
- package/dist/editor/media/AssetCard.d.ts.map +1 -0
- package/dist/editor/media/AssetCard.js +41 -0
- package/dist/editor/media/AssetCard.js.map +1 -0
- package/dist/editor/media/CropStep.d.ts +26 -0
- package/dist/editor/media/CropStep.d.ts.map +1 -0
- package/dist/editor/media/CropStep.js +38 -0
- package/dist/editor/media/CropStep.js.map +1 -0
- package/dist/editor/media/MediaLibrary.d.ts +22 -0
- package/dist/editor/media/MediaLibrary.d.ts.map +1 -0
- package/dist/editor/media/MediaLibrary.js +17 -0
- package/dist/editor/media/MediaLibrary.js.map +1 -0
- package/dist/editor/media/MediaLibraryBody.d.ts +17 -0
- package/dist/editor/media/MediaLibraryBody.d.ts.map +1 -0
- package/dist/editor/media/MediaLibraryBody.js +133 -0
- package/dist/editor/media/MediaLibraryBody.js.map +1 -0
- package/dist/editor/media/crop-math.d.ts +37 -0
- package/dist/editor/media/crop-math.d.ts.map +1 -0
- package/dist/editor/media/crop-math.js +62 -0
- package/dist/editor/media/crop-math.js.map +1 -0
- package/dist/editor/media/upload-asset.d.ts +31 -0
- package/dist/editor/media/upload-asset.d.ts.map +1 -0
- package/dist/editor/media/upload-asset.js +56 -0
- package/dist/editor/media/upload-asset.js.map +1 -0
- package/dist/editor/media/upload-constants.d.ts +27 -0
- package/dist/editor/media/upload-constants.d.ts.map +1 -0
- package/dist/editor/media/upload-constants.js +40 -0
- package/dist/editor/media/upload-constants.js.map +1 -0
- package/dist/editor/media/useAssetUpload.d.ts +19 -0
- package/dist/editor/media/useAssetUpload.d.ts.map +1 -0
- package/dist/editor/media/useAssetUpload.js +53 -0
- package/dist/editor/media/useAssetUpload.js.map +1 -0
- package/dist/editor/media/xhr-upload.d.ts +20 -0
- package/dist/editor/media/xhr-upload.d.ts.map +1 -0
- package/dist/editor/media/xhr-upload.js +42 -0
- package/dist/editor/media/xhr-upload.js.map +1 -0
- package/dist/editor/theme.d.ts +2 -1
- package/dist/editor/theme.d.ts.map +1 -1
- package/dist/editor/theme.js +1 -0
- package/dist/editor/theme.js.map +1 -1
- package/dist/entry-schema.d.ts +19 -0
- package/dist/entry-schema.d.ts.map +1 -1
- package/dist/entry-schema.js.map +1 -1
- package/dist/git-manager.d.ts +15 -10
- package/dist/git-manager.d.ts.map +1 -1
- package/dist/git-manager.js +16 -11
- package/dist/git-manager.js.map +1 -1
- package/dist/http/handler.d.ts +5 -2
- package/dist/http/handler.d.ts.map +1 -1
- package/dist/http/handler.js +13 -4
- package/dist/http/handler.js.map +1 -1
- package/dist/http/index.d.ts +2 -2
- package/dist/http/index.d.ts.map +1 -1
- package/dist/http/index.js +1 -1
- package/dist/http/index.js.map +1 -1
- package/dist/http/router.d.ts +14 -1
- package/dist/http/router.d.ts.map +1 -1
- package/dist/http/router.js +4 -1
- package/dist/http/router.js.map +1 -1
- package/dist/http/types.d.ts +40 -0
- package/dist/http/types.d.ts.map +1 -1
- package/dist/http/types.js +9 -0
- package/dist/http/types.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/resource-generation.d.ts +54 -0
- package/dist/resource-generation.d.ts.map +1 -0
- package/dist/resource-generation.js +156 -0
- package/dist/resource-generation.js.map +1 -0
- package/dist/schema/schema-store.d.ts +31 -4
- package/dist/schema/schema-store.d.ts.map +1 -1
- package/dist/schema/schema-store.js +47 -8
- package/dist/schema/schema-store.js.map +1 -1
- package/dist/server.d.ts +45 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +41 -0
- package/dist/server.js.map +1 -1
- package/dist/sync-core.js +2 -2
- package/dist/sync-core.js.map +1 -1
- package/dist/utils/occ-json-write.d.ts +100 -0
- package/dist/utils/occ-json-write.d.ts.map +1 -0
- package/dist/utils/occ-json-write.js +234 -0
- package/dist/utils/occ-json-write.js.map +1 -0
- package/dist/validation/entry-validator.d.ts.map +1 -1
- package/dist/validation/entry-validator.js +56 -1
- package/dist/validation/entry-validator.js.map +1 -1
- package/dist/worker/cms-worker.d.ts.map +1 -1
- package/dist/worker/cms-worker.js +21 -3
- package/dist/worker/cms-worker.js.map +1 -1
- package/package.json +13 -1
- package/dist/asset-store.d.ts +0 -32
- package/dist/asset-store.d.ts.map +0 -1
- package/dist/asset-store.js +0 -85
- package/dist/asset-store.js.map +0 -1
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure parser/formatter for `/assets/t/{directives}/{hash32}/{slug}.{ext}`
|
|
3
|
+
* transform URLs. Isomorphic and dependency-free by design: this module has
|
|
4
|
+
* NO imports (not even other files in this directory) so it can be imported
|
|
5
|
+
* from client bundles (via `assetUrl`/`assetSrcSet` in asset-url.ts, exported
|
|
6
|
+
* off the package's main entry) as well as from the server-only transform
|
|
7
|
+
* engine (transform.ts) and the future prod transform Lambda (PR 7), without
|
|
8
|
+
* ever pulling in node:crypto, sharp, or any other server-only dependency.
|
|
9
|
+
*
|
|
10
|
+
* `{directives}` is either the literal identity token (`orig`) or a
|
|
11
|
+
* comma-separated list of `key=value` pairs drawn from:
|
|
12
|
+
* w={int} output width - allowlisted to multiples of 160 in [160, 4096]
|
|
13
|
+
* (bounds cache-stuffing; upscaling is rejected at transform
|
|
14
|
+
* time via `withoutEnlargement`, not here)
|
|
15
|
+
* f={fmt} output format: webp | jpeg | png - when present, the URL's
|
|
16
|
+
* `{ext}` must equal it exactly
|
|
17
|
+
* q={int} quality 1..100 (encoder-dependent)
|
|
18
|
+
* c={rect} normalized crop rect `x:y:w:h`, four floats in [0,1] with
|
|
19
|
+
* x+w<=1 and y+h<=1, w>0 and h>0 (colon-separated - commas are
|
|
20
|
+
* the directive separator)
|
|
21
|
+
*
|
|
22
|
+
* Duplicate keys, unknown keys, and empty directive strings are rejected.
|
|
23
|
+
* `orig` must appear alone.
|
|
24
|
+
*/
|
|
25
|
+
/** The identity transform directive name - EXIF-strip only, no other change. */
|
|
26
|
+
export const IDENTITY_TRANSFORM_DIRECTIVE = 'orig';
|
|
27
|
+
const MIN_WIDTH = 160;
|
|
28
|
+
const MAX_WIDTH = 4096;
|
|
29
|
+
const WIDTH_STEP = 160;
|
|
30
|
+
/**
|
|
31
|
+
* Decompression-bomb cap: the max `width * height` (post-decode pixel count)
|
|
32
|
+
* any raster the pipeline handles may have - checked both at upload finalize
|
|
33
|
+
* time (pipeline.ts, against the raw source dims) and at transform decode
|
|
34
|
+
* time (transform.ts, via sharp's `limitInputPixels`). Shared here (rather
|
|
35
|
+
* than duplicated in each server-only module) so it stays a single number,
|
|
36
|
+
* and because this file is dependency-free/isomorphic it can be imported by
|
|
37
|
+
* both without pulling sharp or file-type into anything. 4096x4096 (16.7 MP)
|
|
38
|
+
* comfortably covers the largest output this system ever serves (MAX_WIDTH)
|
|
39
|
+
* while still bounding decode-time memory for a small/compressible-but-huge
|
|
40
|
+
* source (e.g. a 30000x30000 solid-color PNG).
|
|
41
|
+
*/
|
|
42
|
+
export const MAX_INPUT_PIXELS = 4096 * 4096;
|
|
43
|
+
// Quality is allowlisted (multiples of 5 in [30, 95] - 14 values) for the
|
|
44
|
+
// same cache-stuffing reason as width: every accepted directive combination
|
|
45
|
+
// becomes a stored cache object in prod, so unbounded q would multiply the
|
|
46
|
+
// per-asset variant space by 100. Crop remains the one effectively unbounded
|
|
47
|
+
// dimension (editor rects need float precision) - prod mitigation (rate
|
|
48
|
+
// limiting / signed crops) is tracked in the design record for the CDK PR.
|
|
49
|
+
const MIN_QUALITY = 30;
|
|
50
|
+
const MAX_QUALITY = 95;
|
|
51
|
+
const QUALITY_STEP = 5;
|
|
52
|
+
const CROP_PRECISION = 4;
|
|
53
|
+
const HASH32_RE = /^[a-f0-9]{32}$/;
|
|
54
|
+
const SLUG_RE = /^[a-z0-9-]+$/;
|
|
55
|
+
const EXT_RE = /^[a-z0-9]{1,10}$/;
|
|
56
|
+
const POSITIVE_INT_RE = /^[1-9][0-9]*$/;
|
|
57
|
+
// The two alternatives are mutually exclusive on their very first character
|
|
58
|
+
// ('0' vs '1'), and neither branch nests a quantifier inside another - each
|
|
59
|
+
// character class match advances the position by exactly one, so there is
|
|
60
|
+
// exactly one way to parse any matching string (no backtracking ambiguity).
|
|
61
|
+
// The security plugin's heuristic flags any alternation-plus-quantifier
|
|
62
|
+
// shape regardless; input here is also a single bounded URL path segment,
|
|
63
|
+
// not attacker-scalable text.
|
|
64
|
+
// eslint-disable-next-line security/detect-unsafe-regex
|
|
65
|
+
const UNIT_FLOAT_RE = /^(?:0(?:\.[0-9]+)?|1(?:\.0+)?)$/;
|
|
66
|
+
const KNOWN_DIRECTIVE_KEYS = new Set(['w', 'f', 'q', 'c']);
|
|
67
|
+
function isOutputFormat(value) {
|
|
68
|
+
return value === 'webp' || value === 'jpeg' || value === 'png';
|
|
69
|
+
}
|
|
70
|
+
/** True if `width` is on the allowlist: a multiple of 160 in [160, 4096]. */
|
|
71
|
+
export function isAllowedTransformWidth(width) {
|
|
72
|
+
return (Number.isInteger(width) && width >= MIN_WIDTH && width <= MAX_WIDTH && width % WIDTH_STEP === 0);
|
|
73
|
+
}
|
|
74
|
+
function parseWidth(value) {
|
|
75
|
+
if (!POSITIVE_INT_RE.test(value))
|
|
76
|
+
return null;
|
|
77
|
+
const n = Number(value);
|
|
78
|
+
return isAllowedTransformWidth(n) ? n : null;
|
|
79
|
+
}
|
|
80
|
+
/** True if `quality` is on the allowlist: a multiple of 5 in [30, 95]. */
|
|
81
|
+
export function isAllowedTransformQuality(quality) {
|
|
82
|
+
return (Number.isInteger(quality) &&
|
|
83
|
+
quality >= MIN_QUALITY &&
|
|
84
|
+
quality <= MAX_QUALITY &&
|
|
85
|
+
quality % QUALITY_STEP === 0);
|
|
86
|
+
}
|
|
87
|
+
function parseQuality(value) {
|
|
88
|
+
if (!POSITIVE_INT_RE.test(value))
|
|
89
|
+
return null;
|
|
90
|
+
const n = Number(value);
|
|
91
|
+
return isAllowedTransformQuality(n) ? n : null;
|
|
92
|
+
}
|
|
93
|
+
function parseUnitFloat(value) {
|
|
94
|
+
if (!UNIT_FLOAT_RE.test(value))
|
|
95
|
+
return null;
|
|
96
|
+
const n = Number(value);
|
|
97
|
+
return n >= 0 && n <= 1 ? n : null;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* True when x, y, w, h describe a valid normalized crop rect: all four values
|
|
101
|
+
* finite and in [0,1], w and h strictly positive, and the rect fits within
|
|
102
|
+
* bounds (x+w<=1, y+h<=1). Shared by the URL-directive parser (`parseCrop`,
|
|
103
|
+
* below, from a `x:y:w:h` string) and image field value validation (from a
|
|
104
|
+
* `{x,y,w,h}` object, in validation/entry-validator.ts) so both enforce
|
|
105
|
+
* identical constraints.
|
|
106
|
+
*/
|
|
107
|
+
export function isValidCropRect(x, y, w, h) {
|
|
108
|
+
for (const n of [x, y, w, h]) {
|
|
109
|
+
if (!Number.isFinite(n) || n < 0 || n > 1)
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
if (w <= 0 || h <= 0)
|
|
113
|
+
return false;
|
|
114
|
+
if (x + w > 1 || y + h > 1)
|
|
115
|
+
return false;
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
function parseCrop(value) {
|
|
119
|
+
const parts = value.split(':');
|
|
120
|
+
if (parts.length !== 4)
|
|
121
|
+
return null;
|
|
122
|
+
const nums = parts.map(parseUnitFloat);
|
|
123
|
+
if (nums.some((n) => n === null))
|
|
124
|
+
return null;
|
|
125
|
+
const [x, y, w, h] = nums;
|
|
126
|
+
if (!isValidCropRect(x, y, w, h))
|
|
127
|
+
return null;
|
|
128
|
+
return { x, y, w, h };
|
|
129
|
+
}
|
|
130
|
+
function formatUnitFloat(n) {
|
|
131
|
+
return n.toFixed(CROP_PRECISION);
|
|
132
|
+
}
|
|
133
|
+
function err(error) {
|
|
134
|
+
return { ok: false, error };
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Parse a `key=value,key=value` directive string (everything between
|
|
138
|
+
* `assets/t/` and the hash32 segment) into a `TransformDirectives`, or
|
|
139
|
+
* `orig` into the identity directive.
|
|
140
|
+
*/
|
|
141
|
+
function parseDirectivesString(raw) {
|
|
142
|
+
if (raw === IDENTITY_TRANSFORM_DIRECTIVE) {
|
|
143
|
+
return { ok: true, directives: { identity: true } };
|
|
144
|
+
}
|
|
145
|
+
if (raw.length === 0) {
|
|
146
|
+
return err('Empty directives');
|
|
147
|
+
}
|
|
148
|
+
const seen = new Set();
|
|
149
|
+
let width;
|
|
150
|
+
let format;
|
|
151
|
+
let quality;
|
|
152
|
+
let crop;
|
|
153
|
+
for (const pair of raw.split(',')) {
|
|
154
|
+
const eqIdx = pair.indexOf('=');
|
|
155
|
+
// Also catches `orig` combined with other directives (e.g. `orig,w=320`):
|
|
156
|
+
// `orig` has no `=`, so it falls into this same malformed-pair branch -
|
|
157
|
+
// `orig` is only ever valid when it is the entire directives string.
|
|
158
|
+
if (eqIdx <= 0 || eqIdx === pair.length - 1) {
|
|
159
|
+
return err(`Malformed directive: '${pair}'`);
|
|
160
|
+
}
|
|
161
|
+
const key = pair.slice(0, eqIdx);
|
|
162
|
+
const value = pair.slice(eqIdx + 1);
|
|
163
|
+
if (!KNOWN_DIRECTIVE_KEYS.has(key)) {
|
|
164
|
+
return err(`Unknown directive key: '${key}'`);
|
|
165
|
+
}
|
|
166
|
+
if (seen.has(key)) {
|
|
167
|
+
return err(`Duplicate directive key: '${key}'`);
|
|
168
|
+
}
|
|
169
|
+
seen.add(key);
|
|
170
|
+
switch (key) {
|
|
171
|
+
case 'w': {
|
|
172
|
+
const w = parseWidth(value);
|
|
173
|
+
if (w === null)
|
|
174
|
+
return err(`Invalid width: '${value}'`);
|
|
175
|
+
width = w;
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
case 'f': {
|
|
179
|
+
if (!isOutputFormat(value))
|
|
180
|
+
return err(`Invalid format: '${value}'`);
|
|
181
|
+
format = value;
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
case 'q': {
|
|
185
|
+
const q = parseQuality(value);
|
|
186
|
+
if (q === null)
|
|
187
|
+
return err(`Invalid quality: '${value}'`);
|
|
188
|
+
quality = q;
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
case 'c': {
|
|
192
|
+
const c = parseCrop(value);
|
|
193
|
+
if (!c)
|
|
194
|
+
return err(`Invalid crop: '${value}'`);
|
|
195
|
+
crop = c;
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return { ok: true, directives: { identity: false, width, format, quality, crop } };
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Parse the three path segments after the `assets/t/` prefix:
|
|
204
|
+
* `[directivesRaw, hash32, "{slug}.{ext}"]`. The raw route strips the
|
|
205
|
+
* `assets/t/` prefix and splits the remaining key by `/` before calling this.
|
|
206
|
+
*/
|
|
207
|
+
export function parseTransformPath(segments) {
|
|
208
|
+
if (segments.length !== 3) {
|
|
209
|
+
return err(`Expected 3 path segments (directives/hash32/slug.ext), got ${segments.length}`);
|
|
210
|
+
}
|
|
211
|
+
const [directivesRaw, hash32, slugExt] = segments;
|
|
212
|
+
if (!HASH32_RE.test(hash32)) {
|
|
213
|
+
return err(`Invalid hash32: '${hash32}'`);
|
|
214
|
+
}
|
|
215
|
+
const lastDot = slugExt.lastIndexOf('.');
|
|
216
|
+
if (lastDot <= 0 || lastDot === slugExt.length - 1) {
|
|
217
|
+
return err(`Invalid slug.ext segment: '${slugExt}'`);
|
|
218
|
+
}
|
|
219
|
+
const slug = slugExt.slice(0, lastDot);
|
|
220
|
+
const ext = slugExt.slice(lastDot + 1);
|
|
221
|
+
if (!SLUG_RE.test(slug)) {
|
|
222
|
+
return err(`Invalid slug: '${slug}'`);
|
|
223
|
+
}
|
|
224
|
+
if (!EXT_RE.test(ext)) {
|
|
225
|
+
return err(`Invalid ext: '${ext}'`);
|
|
226
|
+
}
|
|
227
|
+
const parsedDirectives = parseDirectivesString(directivesRaw);
|
|
228
|
+
if (!parsedDirectives.ok) {
|
|
229
|
+
return parsedDirectives;
|
|
230
|
+
}
|
|
231
|
+
const { directives } = parsedDirectives;
|
|
232
|
+
if (!directives.identity && directives.format !== undefined && directives.format !== ext) {
|
|
233
|
+
return err(`Extension '${ext}' does not match format '${directives.format}'`);
|
|
234
|
+
}
|
|
235
|
+
return { ok: true, directives, hash32, slug, ext };
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Canonical string form of a directive set, so equivalent directive sets
|
|
239
|
+
* (different key order, different float formatting) always map to the same
|
|
240
|
+
* cache key. Order is fixed alphabetically by key: c, f, q, w.
|
|
241
|
+
*/
|
|
242
|
+
export function formatDirectives(directives) {
|
|
243
|
+
if (directives.identity) {
|
|
244
|
+
return IDENTITY_TRANSFORM_DIRECTIVE;
|
|
245
|
+
}
|
|
246
|
+
const parts = [];
|
|
247
|
+
if (directives.crop) {
|
|
248
|
+
const { x, y, w, h } = directives.crop;
|
|
249
|
+
parts.push(`c=${formatUnitFloat(x)}:${formatUnitFloat(y)}:${formatUnitFloat(w)}:${formatUnitFloat(h)}`);
|
|
250
|
+
}
|
|
251
|
+
if (directives.format !== undefined) {
|
|
252
|
+
parts.push(`f=${directives.format}`);
|
|
253
|
+
}
|
|
254
|
+
if (directives.quality !== undefined) {
|
|
255
|
+
parts.push(`q=${directives.quality}`);
|
|
256
|
+
}
|
|
257
|
+
if (directives.width !== undefined) {
|
|
258
|
+
parts.push(`w=${directives.width}`);
|
|
259
|
+
}
|
|
260
|
+
// A validly-parsed ResizeDirectives always has at least one field set
|
|
261
|
+
// (parseDirectivesString rejects an empty directive string), but a
|
|
262
|
+
// programmatically-constructed one (e.g. from asset-url.ts's merge logic)
|
|
263
|
+
// could end up all-undefined - fall back to identity rather than emit an
|
|
264
|
+
// empty directives segment.
|
|
265
|
+
return parts.length > 0 ? parts.join(',') : IDENTITY_TRANSFORM_DIRECTIVE;
|
|
266
|
+
}
|
|
267
|
+
//# sourceMappingURL=transform-directives.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform-directives.js","sourceRoot":"","sources":["../../src/assets/transform-directives.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,gFAAgF;AAChF,MAAM,CAAC,MAAM,4BAA4B,GAAG,MAAM,CAAA;AAsClD,MAAM,SAAS,GAAG,GAAG,CAAA;AACrB,MAAM,SAAS,GAAG,IAAI,CAAA;AACtB,MAAM,UAAU,GAAG,GAAG,CAAA;AAEtB;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,GAAG,IAAI,CAAA;AAC3C,0EAA0E;AAC1E,4EAA4E;AAC5E,2EAA2E;AAC3E,6EAA6E;AAC7E,wEAAwE;AACxE,2EAA2E;AAC3E,MAAM,WAAW,GAAG,EAAE,CAAA;AACtB,MAAM,WAAW,GAAG,EAAE,CAAA;AACtB,MAAM,YAAY,GAAG,CAAC,CAAA;AACtB,MAAM,cAAc,GAAG,CAAC,CAAA;AAExB,MAAM,SAAS,GAAG,gBAAgB,CAAA;AAClC,MAAM,OAAO,GAAG,cAAc,CAAA;AAC9B,MAAM,MAAM,GAAG,kBAAkB,CAAA;AACjC,MAAM,eAAe,GAAG,eAAe,CAAA;AACvC,4EAA4E;AAC5E,4EAA4E;AAC5E,0EAA0E;AAC1E,4EAA4E;AAC5E,wEAAwE;AACxE,0EAA0E;AAC1E,8BAA8B;AAC9B,wDAAwD;AACxD,MAAM,aAAa,GAAG,iCAAiC,CAAA;AAEvD,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;AAE1D,SAAS,cAAc,CAAC,KAAa;IACnC,OAAO,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,MAAM,IAAI,K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EAAE,CAAC;QACnC,KAAK,CAAC,IAAI,CAAC,KAAK,UAAU,CAAC,KAAK,EAAE,CAAC,CAAA;IACrC,CAAC;IAED,sEAAsE;IACtE,mEAAmE;IACnE,0EAA0E;IAC1E,yEAAyE;IACzE,4BAA4B;IAC5B,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,4BAA4B,CAAA;AAC1E,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared transform engine: applies a parsed `TransformDirectives` to
|
|
3
|
+
* source image bytes with sharp. Server-only - never import this from
|
|
4
|
+
* client/editor code (this is why it lives in its own file, separate from
|
|
5
|
+
* the dependency-free transform-directives.ts). Used by the dev-mode lazy
|
|
6
|
+
* `/assets/t/*` emulation in api/assets.ts today, and will be reused
|
|
7
|
+
* unchanged by the prod transform Lambda (PR 7).
|
|
8
|
+
*
|
|
9
|
+
* Pipeline: a cheap metadata-only probe (`limitInputPixels: MAX_INPUT_PIXELS`,
|
|
10
|
+
* decompression-bomb defense #1) learns the real page count, so animated
|
|
11
|
+
* GIF/WebP frames can be capped at `MAX_ANIMATED_FRAMES` (decompression-bomb
|
|
12
|
+
* defense #2) without exceeding it and making sharp throw -> load for real
|
|
13
|
+
* with `{ pages: min(totalPages, MAX_ANIMATED_FRAMES), limitInputPixels }` ->
|
|
14
|
+
* `.rotate()` with no args (bakes EXIF orientation into pixels,
|
|
15
|
+
* dropping the orientation tag) -> optional crop via `.extract()` -> optional
|
|
16
|
+
* `.resize({ width, withoutEnlargement: true })` (never upscales) -> encode.
|
|
17
|
+
*
|
|
18
|
+
* Identity (`orig`) and any request that omits an explicit `f=` format
|
|
19
|
+
* re-encode through the SOURCE format rather than a fixed one: this is what
|
|
20
|
+
* guarantees EXIF/GPS gets stripped even when no other change is requested
|
|
21
|
+
* (sharp strips metadata by default on re-encode - `withMetadata()` is never
|
|
22
|
+
* called here, which would undo that).
|
|
23
|
+
*
|
|
24
|
+
* GIF has no EXIF segment (EXIF is a JPEG/TIFF APP1 marker; GIF has no such
|
|
25
|
+
* extension block), so an identity GIF has nothing to strip - it is still
|
|
26
|
+
* re-encoded through sharp's `.gif()` (verified: current sharp bundles cgif
|
|
27
|
+
* and re-encodes multi-frame GIFs through the `{ animated: true }` input
|
|
28
|
+
* path with no extra native dependency) purely for pipeline uniformity, not
|
|
29
|
+
* because GIF needs stripping.
|
|
30
|
+
*/
|
|
31
|
+
import { type TransformDirectives } from './transform-directives';
|
|
32
|
+
export interface ApplyTransformInput {
|
|
33
|
+
data: Uint8Array;
|
|
34
|
+
/** Source extension (lowercased file-type ext, e.g. 'png' | 'jpg' | 'webp' | 'gif'). */
|
|
35
|
+
ext: string;
|
|
36
|
+
}
|
|
37
|
+
export interface TransformSuccess {
|
|
38
|
+
ok: true;
|
|
39
|
+
data: Uint8Array;
|
|
40
|
+
contentType: string;
|
|
41
|
+
ext: string;
|
|
42
|
+
}
|
|
43
|
+
export interface TransformRejection {
|
|
44
|
+
ok: false;
|
|
45
|
+
/** 400: unsupported input; 413: output too large; 422: sharp failed to process the input. */
|
|
46
|
+
status: 400 | 413 | 422;
|
|
47
|
+
error: string;
|
|
48
|
+
}
|
|
49
|
+
export type TransformResult = TransformSuccess | TransformRejection;
|
|
50
|
+
export declare function applyTransform(input: ApplyTransformInput, directives: TransformDirectives): Promise<TransformResult>;
|
|
51
|
+
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/assets/transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAKH,OAAO,EAIL,KAAK,mBAAmB,EACzB,MAAM,wBAAwB,CAAA;AAyC/B,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,UAAU,CAAA;IAChB,wFAAwF;IACxF,GAAG,EAAE,MAAM,CAAA;CACZ;AAED,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,IAAI,CAAA;IACR,IAAI,EAAE,UAAU,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;IACnB,GAAG,EAAE,MAAM,CAAA;CACZ;AAED,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,KAAK,CAAA;IACT,6FAA6F;IAC7F,MAAM,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,CAAA;IACvB,KAAK,EAAE,MAAM,CAAA;CACd;AAED,MAAM,MAAM,eAAe,GAAG,gBAAgB,GAAG,kBAAkB,CAAA;AAgFnE,wBAAsB,cAAc,CAClC,KAAK,EAAE,mBAAmB,EAC1B,UAAU,EAAE,mBAAmB,GAC9B,OAAO,CAAC,eAAe,CAAC,CAwE1B"}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared transform engine: applies a parsed `TransformDirectives` to
|
|
3
|
+
* source image bytes with sharp. Server-only - never import this from
|
|
4
|
+
* client/editor code (this is why it lives in its own file, separate from
|
|
5
|
+
* the dependency-free transform-directives.ts). Used by the dev-mode lazy
|
|
6
|
+
* `/assets/t/*` emulation in api/assets.ts today, and will be reused
|
|
7
|
+
* unchanged by the prod transform Lambda (PR 7).
|
|
8
|
+
*
|
|
9
|
+
* Pipeline: a cheap metadata-only probe (`limitInputPixels: MAX_INPUT_PIXELS`,
|
|
10
|
+
* decompression-bomb defense #1) learns the real page count, so animated
|
|
11
|
+
* GIF/WebP frames can be capped at `MAX_ANIMATED_FRAMES` (decompression-bomb
|
|
12
|
+
* defense #2) without exceeding it and making sharp throw -> load for real
|
|
13
|
+
* with `{ pages: min(totalPages, MAX_ANIMATED_FRAMES), limitInputPixels }` ->
|
|
14
|
+
* `.rotate()` with no args (bakes EXIF orientation into pixels,
|
|
15
|
+
* dropping the orientation tag) -> optional crop via `.extract()` -> optional
|
|
16
|
+
* `.resize({ width, withoutEnlargement: true })` (never upscales) -> encode.
|
|
17
|
+
*
|
|
18
|
+
* Identity (`orig`) and any request that omits an explicit `f=` format
|
|
19
|
+
* re-encode through the SOURCE format rather than a fixed one: this is what
|
|
20
|
+
* guarantees EXIF/GPS gets stripped even when no other change is requested
|
|
21
|
+
* (sharp strips metadata by default on re-encode - `withMetadata()` is never
|
|
22
|
+
* called here, which would undo that).
|
|
23
|
+
*
|
|
24
|
+
* GIF has no EXIF segment (EXIF is a JPEG/TIFF APP1 marker; GIF has no such
|
|
25
|
+
* extension block), so an identity GIF has nothing to strip - it is still
|
|
26
|
+
* re-encoded through sharp's `.gif()` (verified: current sharp bundles cgif
|
|
27
|
+
* and re-encodes multi-frame GIFs through the `{ animated: true }` input
|
|
28
|
+
* path with no extra native dependency) purely for pipeline uniformity, not
|
|
29
|
+
* because GIF needs stripping.
|
|
30
|
+
*/
|
|
31
|
+
import sharp from 'sharp';
|
|
32
|
+
import { getErrorMessage } from '../utils/error.js';
|
|
33
|
+
import { MAX_INPUT_PIXELS, } from './transform-directives.js';
|
|
34
|
+
/** Raster formats the transform engine accepts as input. svg/pdf never reach here - they're served statically. */
|
|
35
|
+
const ALLOWED_INPUT_EXTS = new Set(['png', 'jpg', 'jpeg', 'webp', 'gif']);
|
|
36
|
+
/** Defensive cap on encoded output size - prevents cache-stuffing with giant re-encodes. */
|
|
37
|
+
const MAX_OUTPUT_BYTES = 10 * 1024 * 1024;
|
|
38
|
+
/**
|
|
39
|
+
* Cap on decoded animated frames (GIF/WebP) - without this, `{ animated: true }`
|
|
40
|
+
* (sharp's `pages: -1`) decodes every frame of a maliciously-crafted
|
|
41
|
+
* many-thousand-frame animation into memory at once, a decompression-bomb
|
|
42
|
+
* vector distinct from (and not covered by) `limitInputPixels`, which only
|
|
43
|
+
* bounds a single frame's width x height. 60 frames covers any reasonable
|
|
44
|
+
* animated asset (2s at 30fps) with headroom.
|
|
45
|
+
*/
|
|
46
|
+
const MAX_ANIMATED_FRAMES = 60;
|
|
47
|
+
const CONTENT_TYPE_BY_FORMAT = {
|
|
48
|
+
webp: 'image/webp',
|
|
49
|
+
jpeg: 'image/jpeg',
|
|
50
|
+
png: 'image/png',
|
|
51
|
+
};
|
|
52
|
+
const CONTENT_TYPE_BY_EXT = {
|
|
53
|
+
png: 'image/png',
|
|
54
|
+
jpg: 'image/jpeg',
|
|
55
|
+
jpeg: 'image/jpeg',
|
|
56
|
+
webp: 'image/webp',
|
|
57
|
+
gif: 'image/gif',
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Dimensions AFTER `.rotate()` has auto-oriented the pixels. sharp's
|
|
61
|
+
* `metadata()` reports the RAW (pre-rotation) width/height plus the EXIF
|
|
62
|
+
* `orientation` tag; for orientation 5-8 (the 90-degree rotations that
|
|
63
|
+
* portrait phone photos almost always carry) the visual axes are swapped.
|
|
64
|
+
* The crop rect was normalized by the editor against the browser's
|
|
65
|
+
* auto-oriented preview, so `.extract()` - which runs on the post-rotation
|
|
66
|
+
* pipeline - must be computed against these swapped dims, NOT the raw ones.
|
|
67
|
+
* Using the raw dims makes the extract region exceed the rotated image's
|
|
68
|
+
* bounds and sharp throws `bad extract area`. sharp >=0.33 also exposes an
|
|
69
|
+
* `autoOrient` block with the corrected dims; prefer it when present.
|
|
70
|
+
*/
|
|
71
|
+
function orientedDimensions(meta) {
|
|
72
|
+
const auto = meta.autoOrient;
|
|
73
|
+
if (auto && auto.width && auto.height) {
|
|
74
|
+
return { width: auto.width, height: auto.height };
|
|
75
|
+
}
|
|
76
|
+
if (!meta.width || !meta.height)
|
|
77
|
+
return null;
|
|
78
|
+
const swap = typeof meta.orientation === 'number' && meta.orientation >= 5 && meta.orientation <= 8;
|
|
79
|
+
return swap
|
|
80
|
+
? { width: meta.height, height: meta.width }
|
|
81
|
+
: { width: meta.width, height: meta.height };
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Compute a sharp `.extract()` region from a normalized crop rect and the
|
|
85
|
+
* (post-rotation) image dimensions. Rounds the left/top and right/bottom
|
|
86
|
+
* edges independently, then derives width/height from their difference -
|
|
87
|
+
* rounding width/height directly from `crop.w`/`crop.h` could drift the
|
|
88
|
+
* region past the image bounds when combined with independently-rounded
|
|
89
|
+
* left/top. Clamped defensively so float error can never produce an
|
|
90
|
+
* out-of-range extract (which sharp throws on).
|
|
91
|
+
*/
|
|
92
|
+
function computeExtractRegion(crop, width, height) {
|
|
93
|
+
const left = Math.min(Math.max(Math.round(crop.x * width), 0), Math.max(width - 1, 0));
|
|
94
|
+
const top = Math.min(Math.max(Math.round(crop.y * height), 0), Math.max(height - 1, 0));
|
|
95
|
+
const right = Math.min(Math.round((crop.x + crop.w) * width), width);
|
|
96
|
+
const bottom = Math.min(Math.round((crop.y + crop.h) * height), height);
|
|
97
|
+
const extractWidth = Math.max(1, right - left);
|
|
98
|
+
const extractHeight = Math.max(1, bottom - top);
|
|
99
|
+
return { left, top, width: extractWidth, height: extractHeight };
|
|
100
|
+
}
|
|
101
|
+
function encode(pipeline, format, quality) {
|
|
102
|
+
const options = quality !== undefined ? { quality } : undefined;
|
|
103
|
+
switch (format) {
|
|
104
|
+
case 'webp':
|
|
105
|
+
return pipeline.webp(options);
|
|
106
|
+
case 'jpeg':
|
|
107
|
+
return pipeline.jpeg(options);
|
|
108
|
+
case 'png':
|
|
109
|
+
return pipeline.png(options);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/** Re-encode through the source container format - used for identity and for requests that omit `f=`. */
|
|
113
|
+
function encodeSourceFormat(pipeline, sourceExt) {
|
|
114
|
+
switch (sourceExt) {
|
|
115
|
+
case 'gif':
|
|
116
|
+
return pipeline.gif();
|
|
117
|
+
case 'webp':
|
|
118
|
+
return pipeline.webp();
|
|
119
|
+
case 'jpg':
|
|
120
|
+
case 'jpeg':
|
|
121
|
+
return pipeline.jpeg();
|
|
122
|
+
case 'png':
|
|
123
|
+
default:
|
|
124
|
+
return pipeline.png();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
export async function applyTransform(input, directives) {
|
|
128
|
+
const sourceExt = input.ext.toLowerCase();
|
|
129
|
+
if (!ALLOWED_INPUT_EXTS.has(sourceExt)) {
|
|
130
|
+
return {
|
|
131
|
+
ok: false,
|
|
132
|
+
status: 400,
|
|
133
|
+
error: `Unsupported input format for transform: '${sourceExt}'`,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const resize = directives.identity ? undefined : directives;
|
|
137
|
+
const format = resize?.format;
|
|
138
|
+
const quality = resize?.quality;
|
|
139
|
+
try {
|
|
140
|
+
// A cheap header/metadata-only probe (no pixel decode - verified this
|
|
141
|
+
// costs effectively nothing even for a several-hundred-frame source) to
|
|
142
|
+
// learn the source's real page count before deciding whether to cap it.
|
|
143
|
+
// This has to happen before constructing the real pipeline: sharp's
|
|
144
|
+
// `pages` constructor option is a fixed request, not an upper bound - a
|
|
145
|
+
// `pages` value that EXCEEDS the source's actual page count makes sharp
|
|
146
|
+
// throw ("bad page number") rather than clamping, so `MAX_ANIMATED_FRAMES`
|
|
147
|
+
// can only be applied as `Math.min(totalPages, MAX_ANIMATED_FRAMES)`.
|
|
148
|
+
// `limitInputPixels` gates this probe exactly like it gates the real
|
|
149
|
+
// pipeline below - an oversized source throws here already, before any
|
|
150
|
+
// pixel buffer is ever allocated.
|
|
151
|
+
const probeMeta = await sharp(input.data, { limitInputPixels: MAX_INPUT_PIXELS }).metadata();
|
|
152
|
+
const totalPages = probeMeta.pages ?? 1;
|
|
153
|
+
const pagesToRead = Math.min(totalPages, MAX_ANIMATED_FRAMES);
|
|
154
|
+
let pipeline = sharp(input.data, {
|
|
155
|
+
pages: pagesToRead,
|
|
156
|
+
limitInputPixels: MAX_INPUT_PIXELS,
|
|
157
|
+
}).rotate();
|
|
158
|
+
if (resize?.crop) {
|
|
159
|
+
const oriented = orientedDimensions(await pipeline.metadata());
|
|
160
|
+
if (!oriented) {
|
|
161
|
+
return { ok: false, status: 422, error: 'Could not read image dimensions for crop' };
|
|
162
|
+
}
|
|
163
|
+
pipeline = pipeline.extract(computeExtractRegion(resize.crop, oriented.width, oriented.height));
|
|
164
|
+
}
|
|
165
|
+
if (resize?.width) {
|
|
166
|
+
pipeline = pipeline.resize({ width: resize.width, withoutEnlargement: true });
|
|
167
|
+
}
|
|
168
|
+
pipeline = format ? encode(pipeline, format, quality) : encodeSourceFormat(pipeline, sourceExt);
|
|
169
|
+
const data = await pipeline.toBuffer();
|
|
170
|
+
if (data.byteLength > MAX_OUTPUT_BYTES) {
|
|
171
|
+
return {
|
|
172
|
+
ok: false,
|
|
173
|
+
status: 413,
|
|
174
|
+
error: `Transformed output (${data.byteLength} bytes) exceeds the ${MAX_OUTPUT_BYTES}-byte cap`,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
const outExt = format ?? sourceExt;
|
|
178
|
+
const contentType = format ? CONTENT_TYPE_BY_FORMAT[format] : CONTENT_TYPE_BY_EXT[sourceExt];
|
|
179
|
+
return {
|
|
180
|
+
ok: true,
|
|
181
|
+
data: new Uint8Array(data.buffer, data.byteOffset, data.byteLength),
|
|
182
|
+
contentType,
|
|
183
|
+
ext: outExt,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
catch (err) {
|
|
187
|
+
return { ok: false, status: 422, error: `Transform failed: ${getErrorMessage(err)}` };
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=transform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../src/assets/transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EACL,gBAAgB,GAIjB,MAAM,wBAAwB,CAAA;AAW/B,kHAAkH;AAClH,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE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,CAAC;QAED,QAAQ,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;QAE/F,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,QAAQ,EAAE,CAAA;QACtC,IAAI,IAAI,CAAC,UAAU,GAAG,gBAAgB,EAAE,CAAC;YACvC,OAAO;gBACL,EAAE,EAAE,KAAK;gBACT,MAAM,EAAE,GAAG;gBACX,KAAK,EAAE,uBAAuB,IAAI,CAAC,UAAU,uBAAuB,gBAAgB,WAAW;aAChG,CAAA;QACH,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,SAAS,CAAA;QAClC,MAAM,WAAW,GAAG,MAAM,CAAC,CAAC,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAA;QAE5F,OAAO;YACL,EAAE,EAAE,IAAI;YACR,IAAI,EAAE,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC;YACnE,WAAW;YACX,GAAG,EAAE,MAAM;SACZ,CAAA;IACH,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACtB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,qBAAqB,eAAe,CAAC,GAAG,CAAC,EAAE,EAAE,CAAA;IACvF,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asset store v2 contract.
|
|
3
|
+
*
|
|
4
|
+
* Pure type declarations only — no runtime imports. This lets client-side code
|
|
5
|
+
* (the editor) `import type` from this file without ever pulling node:fs or the
|
|
6
|
+
* S3 SDK into a browser bundle. The concrete stores (store-local.ts, store-s3.ts)
|
|
7
|
+
* and the factory are server-only and must never be imported from client code.
|
|
8
|
+
*/
|
|
9
|
+
export interface AssetMeta {
|
|
10
|
+
hash32: string;
|
|
11
|
+
filename: string;
|
|
12
|
+
slug: string;
|
|
13
|
+
ext: string;
|
|
14
|
+
mime: string;
|
|
15
|
+
size: number;
|
|
16
|
+
width?: number;
|
|
17
|
+
height?: number;
|
|
18
|
+
kind: 'raster' | 'svg' | 'pdf';
|
|
19
|
+
uploadedBy?: string;
|
|
20
|
+
uploadedAt: string;
|
|
21
|
+
}
|
|
22
|
+
export type StagedUploadTarget = {
|
|
23
|
+
mode: 'direct';
|
|
24
|
+
url: string;
|
|
25
|
+
fields: Record<string, string>;
|
|
26
|
+
stagingKey: string;
|
|
27
|
+
maxBytes: number;
|
|
28
|
+
} | {
|
|
29
|
+
mode: 'proxied';
|
|
30
|
+
stagingKey: string;
|
|
31
|
+
maxBytes: number;
|
|
32
|
+
};
|
|
33
|
+
export interface BeginUploadInput {
|
|
34
|
+
filename: string;
|
|
35
|
+
contentType: string;
|
|
36
|
+
size?: number;
|
|
37
|
+
}
|
|
38
|
+
export interface PublicObject {
|
|
39
|
+
data: Uint8Array;
|
|
40
|
+
contentType?: string;
|
|
41
|
+
contentDisposition?: string;
|
|
42
|
+
cacheControl?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface AssetStore {
|
|
45
|
+
readonly capabilities: {
|
|
46
|
+
directUpload: boolean;
|
|
47
|
+
};
|
|
48
|
+
beginUpload(input: BeginUploadInput): Promise<StagedUploadTarget>;
|
|
49
|
+
writeStaging(stagingKey: string, data: Uint8Array, contentType?: string): Promise<void>;
|
|
50
|
+
readStaging(stagingKey: string): Promise<Uint8Array | null>;
|
|
51
|
+
deleteStaging(stagingKey: string): Promise<void>;
|
|
52
|
+
putOriginal(input: {
|
|
53
|
+
hash32: string;
|
|
54
|
+
ext: string;
|
|
55
|
+
data: Uint8Array;
|
|
56
|
+
contentType: string;
|
|
57
|
+
}): Promise<void>;
|
|
58
|
+
readOriginal(hash32: string): Promise<{
|
|
59
|
+
data: Uint8Array;
|
|
60
|
+
ext: string;
|
|
61
|
+
contentType?: string;
|
|
62
|
+
} | null>;
|
|
63
|
+
putPublicObject(input: {
|
|
64
|
+
key: string;
|
|
65
|
+
data: Uint8Array;
|
|
66
|
+
contentType: string;
|
|
67
|
+
contentDisposition?: string;
|
|
68
|
+
cacheControl?: string;
|
|
69
|
+
}): Promise<void>;
|
|
70
|
+
readPublicObject(key: string): Promise<PublicObject | null>;
|
|
71
|
+
putMetaIfAbsent(hash32: string, meta: AssetMeta): Promise<'created' | 'already-exists'>;
|
|
72
|
+
getMeta(hash32: string): Promise<AssetMeta | null>;
|
|
73
|
+
listMeta(input?: {
|
|
74
|
+
cursor?: string;
|
|
75
|
+
limit?: number;
|
|
76
|
+
}): Promise<{
|
|
77
|
+
items: AssetMeta[];
|
|
78
|
+
nextCursor?: string;
|
|
79
|
+
}>;
|
|
80
|
+
deleteMeta(hash32: string): Promise<void>;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/assets/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,QAAQ,GAAG,KAAK,GAAG,KAAK,CAAA;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,MAAM,kBAAkB,GAC1B;IACE,IAAI,EAAE,QAAQ,CAA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V,MAAM,EAAE,MAAM,GACb,OAAO,CAAC;QAAE,IAAI,EAAE,UAAU,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC,CAAA;IAC1E,eAAe,CAAC,KAAK,EAAE;QACrB,GAAG,EAAE,MAAM,CAAA;QACX,IAAI,EAAE,UAAU,CAAA;QAChB,WAAW,EAAE,MAAM,CAAA;QACnB,kBAAkB,CAAC,EAAE,MAAM,CAAA;QAC3B,YAAY,CAAC,EAAE,MAAM,CAAA;KACtB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACjB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAA;IAC3D,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,GAAG,gBAAgB,CAAC,CAAA;IACvF,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAAA;IAClD,QAAQ,CAAC,KAAK,CAAC,EAAE;QACf,MAAM,CAAC,EAAE,MAAM,CAAA;QACf,KAAK,CAAC,EAAE,MAAM,CAAA;KACf,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,SAAS,EAAE,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IACxD,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC1C"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asset store v2 contract.
|
|
3
|
+
*
|
|
4
|
+
* Pure type declarations only — no runtime imports. This lets client-side code
|
|
5
|
+
* (the editor) `import type` from this file without ever pulling node:fs or the
|
|
6
|
+
* S3 SDK into a browser bundle. The concrete stores (store-local.ts, store-s3.ts)
|
|
7
|
+
* and the factory are server-only and must never be imported from client code.
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/assets/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
|
@@ -28,8 +28,8 @@ export declare const GroupsFileSchema: z.ZodObject<{
|
|
|
28
28
|
description?: string | undefined;
|
|
29
29
|
}>, "many">;
|
|
30
30
|
}, "strip", z.ZodTypeAny, {
|
|
31
|
-
updatedAt: string;
|
|
32
31
|
version: 1;
|
|
32
|
+
updatedAt: string;
|
|
33
33
|
groups: {
|
|
34
34
|
name: string;
|
|
35
35
|
members: string[];
|
|
@@ -39,8 +39,8 @@ export declare const GroupsFileSchema: z.ZodObject<{
|
|
|
39
39
|
updatedBy: string;
|
|
40
40
|
contentVersion?: number | undefined;
|
|
41
41
|
}, {
|
|
42
|
-
updatedAt: string;
|
|
43
42
|
version: 1;
|
|
43
|
+
updatedAt: string;
|
|
44
44
|
groups: {
|
|
45
45
|
name: string;
|
|
46
46
|
members: string[];
|