@aphexcms/cms-core 9.9.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/schemas/documents.d.ts +1 -0
- package/dist/api/schemas/documents.d.ts.map +1 -1
- package/dist/api/schemas/documents.js +1 -0
- 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 +213 -32
- 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 +107 -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/schemas/documents.d.ts +1 -0
- package/dist/lib/api/schemas/documents.d.ts.map +1 -1
- package/dist/lib/api/schemas/documents.js +1 -0
- package/dist/lib/api/schemas/documents.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 +107 -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 +25 -2
- package/dist/lib/local-api/collection-api.d.ts.map +1 -1
- package/dist/lib/local-api/collection-api.js +107 -20
- 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/schema-utils/utils.d.ts +31 -1
- package/dist/lib/schema-utils/utils.d.ts.map +1 -1
- package/dist/lib/schema-utils/utils.js +68 -0
- package/dist/lib/schema-utils/utils.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 +28 -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/type-gen.d.ts.map +1 -1
- package/dist/lib/type-gen.js +11 -5
- package/dist/lib/type-gen.js.map +1 -1
- 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/types/filters.d.ts +31 -0
- package/dist/lib/types/filters.d.ts.map +1 -1
- package/dist/lib/types/schemas.d.ts +14 -0
- package/dist/lib/types/schemas.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 +25 -2
- package/dist/local-api/collection-api.d.ts.map +1 -1
- package/dist/local-api/collection-api.js +107 -20
- 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/schema-utils/utils.d.ts +31 -1
- package/dist/schema-utils/utils.d.ts.map +1 -1
- package/dist/schema-utils/utils.js +68 -0
- 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 +28 -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/type-gen.d.ts.map +1 -1
- package/dist/type-gen.js +11 -5
- 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/types/filters.d.ts +31 -0
- package/dist/types/filters.d.ts.map +1 -1
- package/dist/types/schemas.d.ts +14 -0
- package/dist/types/schemas.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
|
@@ -6,9 +6,17 @@ import type { SchemaType } from '../types/schemas.js';
|
|
|
6
6
|
* its schema; we walk the data via the schema-aware walker, dedupe the
|
|
7
7
|
* resulting ref IDs, and atomically replace the rows for that referencer.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* **Written inside the document's own write transaction, and failures throw.**
|
|
10
|
+
*
|
|
11
|
+
* Previously logged-and-swallowed, on the grounds that a stale index shouldn't
|
|
12
|
+
* block a save. The trouble is what reads it: the publish and unpublish guards.
|
|
13
|
+
* An under-populated index there doesn't show a wrong badge, it lets a
|
|
14
|
+
* still-referenced document be unpublished — the index says nothing points at
|
|
15
|
+
* it, so nothing stops you. A guard that silently weakens when a write failed is
|
|
16
|
+
* worse than no guard, because it is trusted.
|
|
17
|
+
*
|
|
18
|
+
* Same contract as the sibling {@link AssetReferencesService}, for the same
|
|
19
|
+
* reason, and see its note for the tradeoff being accepted.
|
|
12
20
|
*/
|
|
13
21
|
export declare class ReferencesService {
|
|
14
22
|
private databaseAdapter;
|
|
@@ -16,20 +24,16 @@ export declare class ReferencesService {
|
|
|
16
24
|
/**
|
|
17
25
|
* Sync the back-reference rows for a single document. Idempotent —
|
|
18
26
|
* safe to call repeatedly with the same data.
|
|
27
|
+
*
|
|
28
|
+
* Takes the adapter to write through so the caller can pass a
|
|
29
|
+
* `withTransaction` handle and have these rows commit with the document.
|
|
19
30
|
*/
|
|
20
|
-
syncReferencesFor(organizationId: string, documentId: string, data: unknown, schema: SchemaType | null, registry: SchemaType[]): Promise<void>;
|
|
31
|
+
syncReferencesFor(db: DatabaseAdapter, organizationId: string, documentId: string, data: unknown, schema: SchemaType | null, registry: SchemaType[]): Promise<void>;
|
|
21
32
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* Skipped silently in error paths — boot must keep going even if the
|
|
27
|
-
* scan can't run (missing perms, connection issues, etc).
|
|
33
|
+
* One-time rebuild for content that predates the index. Unconditional — see
|
|
34
|
+
* {@link AssetReferencesService.backfill} for why the old "is the table empty"
|
|
35
|
+
* gate was unsound, and what replaced it.
|
|
28
36
|
*/
|
|
29
|
-
|
|
30
|
-
id: string;
|
|
31
|
-
type: string;
|
|
32
|
-
data: unknown;
|
|
33
|
-
}>>): Promise<void>;
|
|
37
|
+
backfill(organizationId: string, schemas: SchemaType[]): Promise<void>;
|
|
34
38
|
}
|
|
35
39
|
//# sourceMappingURL=references-service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"references-service.d.ts","sourceRoot":"","sources":["../../src/lib/services/references-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAInD
|
|
1
|
+
{"version":3,"file":"references-service.d.ts","sourceRoot":"","sources":["../../src/lib/services/references-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAInD;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,iBAAiB;IACjB,OAAO,CAAC,eAAe;gBAAf,eAAe,EAAE,eAAe;IAEpD;;;;;;OAMG;IACG,iBAAiB,CACtB,EAAE,EAAE,eAAe,EACnB,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,UAAU,GAAG,IAAI,EACzB,QAAQ,EAAE,UAAU,EAAE,GACpB,OAAO,CAAC,IAAI,CAAC;IAKhB;;;;OAIG;IACG,QAAQ,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CA6C5E"}
|
|
@@ -6,9 +6,17 @@ import { cmsLogger } from '../utils/logger.js';
|
|
|
6
6
|
* its schema; we walk the data via the schema-aware walker, dedupe the
|
|
7
7
|
* resulting ref IDs, and atomically replace the rows for that referencer.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* **Written inside the document's own write transaction, and failures throw.**
|
|
10
|
+
*
|
|
11
|
+
* Previously logged-and-swallowed, on the grounds that a stale index shouldn't
|
|
12
|
+
* block a save. The trouble is what reads it: the publish and unpublish guards.
|
|
13
|
+
* An under-populated index there doesn't show a wrong badge, it lets a
|
|
14
|
+
* still-referenced document be unpublished — the index says nothing points at
|
|
15
|
+
* it, so nothing stops you. A guard that silently weakens when a write failed is
|
|
16
|
+
* worse than no guard, because it is trusted.
|
|
17
|
+
*
|
|
18
|
+
* Same contract as the sibling {@link AssetReferencesService}, for the same
|
|
19
|
+
* reason, and see its note for the tradeoff being accepted.
|
|
12
20
|
*/
|
|
13
21
|
export class ReferencesService {
|
|
14
22
|
databaseAdapter;
|
|
@@ -18,42 +26,62 @@ export class ReferencesService {
|
|
|
18
26
|
/**
|
|
19
27
|
* Sync the back-reference rows for a single document. Idempotent —
|
|
20
28
|
* safe to call repeatedly with the same data.
|
|
29
|
+
*
|
|
30
|
+
* Takes the adapter to write through so the caller can pass a
|
|
31
|
+
* `withTransaction` handle and have these rows commit with the document.
|
|
21
32
|
*/
|
|
22
|
-
async syncReferencesFor(organizationId, documentId, data, schema, registry) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
await this.databaseAdapter.replaceReferencesFor(organizationId, documentId, refIds);
|
|
26
|
-
}
|
|
27
|
-
catch (err) {
|
|
28
|
-
cmsLogger.error('[References]', 'Failed to sync references for', documentId, err);
|
|
29
|
-
}
|
|
33
|
+
async syncReferencesFor(db, organizationId, documentId, data, schema, registry) {
|
|
34
|
+
const refIds = collectReferenceIds(data, schema, registry);
|
|
35
|
+
await db.replaceReferencesFor(organizationId, documentId, refIds);
|
|
30
36
|
}
|
|
31
37
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* Skipped silently in error paths — boot must keep going even if the
|
|
37
|
-
* scan can't run (missing perms, connection issues, etc).
|
|
38
|
+
* One-time rebuild for content that predates the index. Unconditional — see
|
|
39
|
+
* {@link AssetReferencesService.backfill} for why the old "is the table empty"
|
|
40
|
+
* gate was unsound, and what replaced it.
|
|
38
41
|
*/
|
|
39
|
-
async
|
|
42
|
+
async backfill(organizationId, schemas) {
|
|
40
43
|
try {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
44
|
+
cmsLogger.info('[References]', `Rebuilding reference index for org ${organizationId}`);
|
|
45
|
+
let indexed = 0;
|
|
46
|
+
for (const schema of schemas.filter((candidate) => candidate.type === 'document')) {
|
|
47
|
+
// Paged rather than loaded whole. The caller used to supply a
|
|
48
|
+
// `listAllDocuments()` that materialised an entire content set in
|
|
49
|
+
// memory, which is part of why this was never wired to anything.
|
|
50
|
+
const PAGE = 100;
|
|
51
|
+
for (let offset = 0;; offset += PAGE) {
|
|
52
|
+
const page = await this.databaseAdapter.findManyDocAdvanced(organizationId, schema.name, {
|
|
53
|
+
limit: PAGE,
|
|
54
|
+
offset
|
|
55
|
+
});
|
|
56
|
+
const docs = page?.docs ?? [];
|
|
57
|
+
if (docs.length === 0)
|
|
58
|
+
break;
|
|
59
|
+
for (const doc of docs) {
|
|
60
|
+
try {
|
|
61
|
+
// Draft data is what the guards care about: an unpublished draft
|
|
62
|
+
// pointing at a document still blocks that document's deletion.
|
|
63
|
+
const refIds = collectReferenceIds(doc.draftData, schema, schemas);
|
|
64
|
+
await this.databaseAdapter.replaceReferencesFor(organizationId, doc.id, refIds);
|
|
65
|
+
indexed++;
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
cmsLogger.error('[References]', 'Skipping document', doc.id, err);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (docs.length < PAGE)
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
52
74
|
}
|
|
53
|
-
cmsLogger.info('[References]',
|
|
75
|
+
cmsLogger.info('[References]', `Backfill complete — ${indexed} document(s)`);
|
|
54
76
|
}
|
|
55
77
|
catch (err) {
|
|
56
|
-
|
|
78
|
+
// Rethrow so the queue retries — see the note on
|
|
79
|
+
// AssetReferencesService.backfill. Swallowing here would mark a
|
|
80
|
+
// half-finished rebuild as completed, and this index feeds the publish
|
|
81
|
+
// and unpublish guards, so an incomplete one doesn't mislabel anything:
|
|
82
|
+
// it lets a still-referenced document through.
|
|
83
|
+
cmsLogger.error('[References]', 'Backfill failed — will retry', err);
|
|
84
|
+
throw err;
|
|
57
85
|
}
|
|
58
86
|
}
|
|
59
87
|
}
|
|
@@ -35,8 +35,17 @@ export declare class VersionService {
|
|
|
35
35
|
enforceRetentionFor(db: DatabaseAdapter, organizationId: string, documentId: string): Promise<void>;
|
|
36
36
|
/**
|
|
37
37
|
* Save draft and create version atomically using adapter transaction.
|
|
38
|
+
*
|
|
39
|
+
* `alsoInTx` runs against the same handle once the write has succeeded, for
|
|
40
|
+
* work that must commit with the document — the reference indexes. It exists
|
|
41
|
+
* because this method owns the transaction: a caller that wrapped its own
|
|
42
|
+
* around this one would be nesting `withTransaction`, which is not something
|
|
43
|
+
* every adapter promises. Handing the inside out is the honest version.
|
|
44
|
+
*
|
|
45
|
+
* Skipped when the write returns null (nothing was updated), and its failure
|
|
46
|
+
* rolls the document write back with it — which is the entire point.
|
|
38
47
|
*/
|
|
39
|
-
saveWithVersion(db: DatabaseAdapter, organizationId: string, documentId: string, data: any, userId?: string, expectedRevision?: number): Promise<Document | null>;
|
|
48
|
+
saveWithVersion(db: DatabaseAdapter, organizationId: string, documentId: string, data: any, userId?: string, expectedRevision?: number, alsoInTx?: (tx: DatabaseAdapter, document: Document) => Promise<void>): Promise<Document | null>;
|
|
40
49
|
/**
|
|
41
50
|
* Publish and create version.
|
|
42
51
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version-service.d.ts","sourceRoot":"","sources":["../../src/lib/services/version-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAG7E;;;;;;GAMG;AACH,qBAAa,cAAc;IAC1B,OAAO,CAAC,WAAW,CAAS;gBAEhB,OAAO,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE;IAI9C;;OAEG;IACG,aAAa,CAClB,EAAE,EAAE,eAAe,EACnB,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,OAAO,GAAG,SAAS,EAC9B,IAAI,EAAE,GAAG,EACT,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GACpB,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAelC;;;;OAIG;IACG,UAAU,CACf,EAAE,EAAE,eAAe,EACnB,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,OAAO,GAAG,SAAS,EAC9B,IAAI,EAAE,GAAG,EACT,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GACpB,OAAO,CAAC,IAAI,CAAC;IAWhB;;;OAGG;IACG,SAAS,CACd,EAAE,EAAE,eAAe,EACnB,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,gBAAgB,CAAC,EAAE,MAAM,GACvB,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAoB3B;;;OAGG;IACG,mBAAmB,CACxB,EAAE,EAAE,eAAe,EACnB,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC;IAIhB
|
|
1
|
+
{"version":3,"file":"version-service.d.ts","sourceRoot":"","sources":["../../src/lib/services/version-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAG7E;;;;;;GAMG;AACH,qBAAa,cAAc;IAC1B,OAAO,CAAC,WAAW,CAAS;gBAEhB,OAAO,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE;IAI9C;;OAEG;IACG,aAAa,CAClB,EAAE,EAAE,eAAe,EACnB,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,OAAO,GAAG,SAAS,EAC9B,IAAI,EAAE,GAAG,EACT,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GACpB,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAelC;;;;OAIG;IACG,UAAU,CACf,EAAE,EAAE,eAAe,EACnB,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,OAAO,GAAG,SAAS,EAC9B,IAAI,EAAE,GAAG,EACT,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GACpB,OAAO,CAAC,IAAI,CAAC;IAWhB;;;OAGG;IACG,SAAS,CACd,EAAE,EAAE,eAAe,EACnB,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,gBAAgB,CAAC,EAAE,MAAM,GACvB,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAoB3B;;;OAGG;IACG,mBAAmB,CACxB,EAAE,EAAE,eAAe,EACnB,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC;IAIhB;;;;;;;;;;;OAWG;IACG,eAAe,CACpB,EAAE,EAAE,eAAe,EACnB,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,GAAG,EACT,MAAM,CAAC,EAAE,MAAM,EACf,gBAAgB,CAAC,EAAE,MAAM,EACzB,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,eAAe,EAAE,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,GACnE,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAyC3B;;OAEG;IACG,kBAAkB,CACvB,EAAE,EAAE,eAAe,EACnB,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,gBAAgB,CAAC,EAAE,MAAM,GACvB,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAiB3B;;OAEG;IACG,cAAc,CACnB,EAAE,EAAE,eAAe,EACnB,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,MAAM,EACrB,MAAM,CAAC,EAAE,MAAM,EACf,gBAAgB,CAAC,EAAE,MAAM,GACvB,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IA6BrB,YAAY,CACjB,EAAE,EAAE,eAAe,EACnB,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAC3C,OAAO,CAAC,mBAAmB,CAAC;IAKzB,UAAU,CACf,EAAE,EAAE,eAAe,EACnB,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,MAAM,GACnB,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;YAKpB,gBAAgB;CAuB9B"}
|
|
@@ -68,18 +68,40 @@ export class VersionService {
|
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
70
|
* Save draft and create version atomically using adapter transaction.
|
|
71
|
+
*
|
|
72
|
+
* `alsoInTx` runs against the same handle once the write has succeeded, for
|
|
73
|
+
* work that must commit with the document — the reference indexes. It exists
|
|
74
|
+
* because this method owns the transaction: a caller that wrapped its own
|
|
75
|
+
* around this one would be nesting `withTransaction`, which is not something
|
|
76
|
+
* every adapter promises. Handing the inside out is the honest version.
|
|
77
|
+
*
|
|
78
|
+
* Skipped when the write returns null (nothing was updated), and its failure
|
|
79
|
+
* rolls the document write back with it — which is the entire point.
|
|
71
80
|
*/
|
|
72
|
-
async saveWithVersion(db, organizationId, documentId, data, userId, expectedRevision) {
|
|
73
|
-
// No versioning support: a single write,
|
|
81
|
+
async saveWithVersion(db, organizationId, documentId, data, userId, expectedRevision, alsoInTx) {
|
|
82
|
+
// No versioning support: a single write, which still needs the index to
|
|
83
|
+
// land with it, so it gets a transaction of its own rather than staying a
|
|
84
|
+
// bare update.
|
|
74
85
|
if (!db.createDocumentVersion) {
|
|
75
|
-
|
|
86
|
+
if (!alsoInTx) {
|
|
87
|
+
return db.updateDocDraft(organizationId, documentId, data, userId, expectedRevision);
|
|
88
|
+
}
|
|
89
|
+
return db.withTransaction(async (txAdapter) => {
|
|
90
|
+
const result = await txAdapter.updateDocDraft(organizationId, documentId, data, userId, expectedRevision);
|
|
91
|
+
if (result)
|
|
92
|
+
await alsoInTx(txAdapter, result);
|
|
93
|
+
return result;
|
|
94
|
+
});
|
|
76
95
|
}
|
|
77
96
|
// RevisionConflictError propagates out of the transaction un-swallowed —
|
|
78
97
|
// callers must surface it distinctly from a validation error.
|
|
79
98
|
const updated = await db.withTransaction(async (txAdapter) => {
|
|
80
99
|
const result = await txAdapter.updateDocDraft(organizationId, documentId, data, userId, expectedRevision);
|
|
81
|
-
if (result)
|
|
100
|
+
if (result) {
|
|
82
101
|
await this.snapshotTx(txAdapter, organizationId, documentId, 'draft', data, userId);
|
|
102
|
+
if (alsoInTx)
|
|
103
|
+
await alsoInTx(txAdapter, result);
|
|
104
|
+
}
|
|
83
105
|
return result;
|
|
84
106
|
});
|
|
85
107
|
if (updated)
|
|
@@ -6,6 +6,8 @@ export declare class LocalStorageAdapter implements StorageAdapter {
|
|
|
6
6
|
readonly name = "local";
|
|
7
7
|
private config;
|
|
8
8
|
constructor(config: StorageConfig);
|
|
9
|
+
/** See {@link StorageAdapter.setMaxFileSize}. */
|
|
10
|
+
setMaxFileSize(bytes: number): void;
|
|
9
11
|
/**
|
|
10
12
|
* Strip path traversal sequences, keeping only the base filename.
|
|
11
13
|
*/
|
|
@@ -26,11 +28,47 @@ export declare class LocalStorageAdapter implements StorageAdapter {
|
|
|
26
28
|
* Store a file and return storage info
|
|
27
29
|
*/
|
|
28
30
|
store(data: UploadFileData): Promise<StorageFile>;
|
|
31
|
+
/**
|
|
32
|
+
* Make a caller-supplied key safe to join onto `basePath`.
|
|
33
|
+
*
|
|
34
|
+
* Keys may contain `/` — that's the point, `{assetId}/original.png` is a
|
|
35
|
+
* directory and a file. What they may not do is climb out of the storage
|
|
36
|
+
* root, so each segment is stripped of traversal and empty segments are
|
|
37
|
+
* dropped. A key that sanitizes to nothing falls back to the raw basename.
|
|
38
|
+
*/
|
|
39
|
+
private sanitizeKey;
|
|
40
|
+
/**
|
|
41
|
+
* Resolve a path and prove it stays inside `basePath`, or throw.
|
|
42
|
+
*
|
|
43
|
+
* Every read/write entry point funnels through here. Keeping one copy is a
|
|
44
|
+
* safety property, not tidiness: this is the only thing standing between a
|
|
45
|
+
* caller-influenced path and the rest of the filesystem, and a
|
|
46
|
+
* per-call-site copy is how one of them ends up missing the check.
|
|
47
|
+
*/
|
|
48
|
+
private assertWithinBase;
|
|
49
|
+
/**
|
|
50
|
+
* Where a key lives on disk. Mirrors what `store()` reports, for callers
|
|
51
|
+
* holding a key that never went through it.
|
|
52
|
+
*/
|
|
53
|
+
resolvePath(key: string): string;
|
|
29
54
|
/**
|
|
30
55
|
* Read a file from storage
|
|
31
56
|
* Used by API endpoint to serve files
|
|
32
57
|
*/
|
|
33
58
|
getObject(path: string): Promise<Buffer>;
|
|
59
|
+
/**
|
|
60
|
+
* Read a file from storage as a stream.
|
|
61
|
+
*
|
|
62
|
+
* Same containment check as `getObject` — a streaming read is still a read,
|
|
63
|
+
* and skipping the check here would reintroduce the traversal escape on the
|
|
64
|
+
* path callers now prefer.
|
|
65
|
+
*/
|
|
66
|
+
getStream(path: string): Promise<ReadableStream<Uint8Array>>;
|
|
67
|
+
/**
|
|
68
|
+
* Ranged read. Node's `start`/`end` are both inclusive, which is already the
|
|
69
|
+
* convention the port specifies, so the bounds pass through unchanged.
|
|
70
|
+
*/
|
|
71
|
+
getObjectRange(path: string, start: number, end: number): Promise<ReadableStream<Uint8Array>>;
|
|
34
72
|
/**
|
|
35
73
|
* Delete a file from storage
|
|
36
74
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-storage-adapter.d.ts","sourceRoot":"","sources":["../../../src/lib/storage/adapters/local-storage-adapter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACX,cAAc,EACd,aAAa,EACb,cAAc,EACd,WAAW,EACX,MAAM,uBAAuB,CAAC;AAK/B;;GAEG;AACH,qBAAa,mBAAoB,YAAW,cAAc;IACzD,QAAQ,CAAC,IAAI,WAAW;IACxB,OAAO,CAAC,MAAM,CAA0B;gBAE5B,MAAM,EAAE,aAAa;IASjC;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAIxB;;OAEG;YACW,sBAAsB;IAepC;;OAEG;IACH,OAAO,CAAC,aAAa;IAWrB;;OAEG;YACW,gBAAgB;IAU9B;;OAEG;IACG,KAAK,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"local-storage-adapter.d.ts","sourceRoot":"","sources":["../../../src/lib/storage/adapters/local-storage-adapter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACX,cAAc,EACd,aAAa,EACb,cAAc,EACd,WAAW,EACX,MAAM,uBAAuB,CAAC;AAK/B;;GAEG;AACH,qBAAa,mBAAoB,YAAW,cAAc;IACzD,QAAQ,CAAC,IAAI,WAAW;IACxB,OAAO,CAAC,MAAM,CAA0B;gBAE5B,MAAM,EAAE,aAAa;IASjC,iDAAiD;IACjD,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAInC;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAIxB;;OAEG;YACW,sBAAsB;IAepC;;OAEG;IACH,OAAO,CAAC,aAAa;IAWrB;;OAEG;YACW,gBAAgB;IAU9B;;OAEG;IACG,KAAK,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC;IA0CvD;;;;;;;OAOG;IACH,OAAO,CAAC,WAAW;IAQnB;;;;;;;OAOG;IACH,OAAO,CAAC,gBAAgB;IASxB;;;OAGG;IACH,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAIhC;;;OAGG;IACG,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAM9C;;;;;;OAMG;IACG,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IAWlE;;;OAGG;IACG,cAAc,CACnB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,GACT,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IAUtC;;OAEG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAU5C;;OAEG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAW5C;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAM5B;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,cAAc,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAyB/E;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;CAYnC"}
|
|
@@ -17,6 +17,11 @@ export class LocalStorageAdapter {
|
|
|
17
17
|
options: config.options || {}
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
+
/** See {@link StorageAdapter.setMaxFileSize}. */
|
|
21
|
+
setMaxFileSize(bytes) {
|
|
22
|
+
if (Number.isFinite(bytes) && bytes > 0)
|
|
23
|
+
this.config.maxFileSize = bytes;
|
|
24
|
+
}
|
|
20
25
|
/**
|
|
21
26
|
* Strip path traversal sequences, keeping only the base filename.
|
|
22
27
|
*/
|
|
@@ -72,14 +77,19 @@ export class LocalStorageAdapter {
|
|
|
72
77
|
if (data.size > this.config.maxFileSize) {
|
|
73
78
|
throw new Error(`File too large: ${data.size} bytes. Maximum size: ${this.config.maxFileSize} bytes`);
|
|
74
79
|
}
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
|
|
80
|
+
// An explicit key is authoritative — the caller owns uniqueness and wants
|
|
81
|
+
// a predictable location (e.g. `{assetId}/original.png`, so variants can
|
|
82
|
+
// be written alongside it). Otherwise fall back to deriving a
|
|
83
|
+
// non-colliding name from the original filename.
|
|
84
|
+
const key = data.key
|
|
85
|
+
? this.sanitizeKey(data.key)
|
|
86
|
+
: await this.generateUniqueFilename(data.filename);
|
|
87
|
+
const filePath = join(this.config.basePath, key);
|
|
78
88
|
// Store internal path only - URL will be generated by API with asset ID
|
|
79
89
|
// This forces all access through /assets/{id} for proper authorization
|
|
80
90
|
const url = ''; // Will be populated as /assets/{assetId}/{filename} by the API
|
|
81
91
|
cmsLogger.debug('[LocalStorageAdapter] Storing file:', {
|
|
82
|
-
|
|
92
|
+
key,
|
|
83
93
|
filePath,
|
|
84
94
|
note: 'URL will be generated as /assets/{assetId}/{filename}',
|
|
85
95
|
basePath: this.config.basePath
|
|
@@ -89,35 +99,95 @@ export class LocalStorageAdapter {
|
|
|
89
99
|
// Save file to disk
|
|
90
100
|
await writeFile(filePath, data.buffer);
|
|
91
101
|
return {
|
|
102
|
+
key,
|
|
92
103
|
path: filePath,
|
|
93
104
|
url, // Empty - API will generate clean URL with asset ID
|
|
94
105
|
size: data.size
|
|
95
106
|
};
|
|
96
107
|
}
|
|
97
108
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
109
|
+
* Make a caller-supplied key safe to join onto `basePath`.
|
|
110
|
+
*
|
|
111
|
+
* Keys may contain `/` — that's the point, `{assetId}/original.png` is a
|
|
112
|
+
* directory and a file. What they may not do is climb out of the storage
|
|
113
|
+
* root, so each segment is stripped of traversal and empty segments are
|
|
114
|
+
* dropped. A key that sanitizes to nothing falls back to the raw basename.
|
|
100
115
|
*/
|
|
101
|
-
|
|
116
|
+
sanitizeKey(key) {
|
|
117
|
+
const segments = key
|
|
118
|
+
.split('/')
|
|
119
|
+
.map((segment) => basename(segment).replace(/^\.+/, '_'))
|
|
120
|
+
.filter((segment) => segment.length > 0 && segment !== '.' && segment !== '..');
|
|
121
|
+
return segments.length > 0 ? segments.join('/') : this.sanitizeFilename(key);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Resolve a path and prove it stays inside `basePath`, or throw.
|
|
125
|
+
*
|
|
126
|
+
* Every read/write entry point funnels through here. Keeping one copy is a
|
|
127
|
+
* safety property, not tidiness: this is the only thing standing between a
|
|
128
|
+
* caller-influenced path and the rest of the filesystem, and a
|
|
129
|
+
* per-call-site copy is how one of them ends up missing the check.
|
|
130
|
+
*/
|
|
131
|
+
assertWithinBase(path) {
|
|
102
132
|
const resolved = resolve(path);
|
|
103
133
|
const base = resolve(this.config.basePath);
|
|
104
134
|
if (!resolved.startsWith(base + '/') && resolved !== base) {
|
|
105
135
|
throw new Error('Access denied: path outside storage directory');
|
|
106
136
|
}
|
|
137
|
+
return resolved;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Where a key lives on disk. Mirrors what `store()` reports, for callers
|
|
141
|
+
* holding a key that never went through it.
|
|
142
|
+
*/
|
|
143
|
+
resolvePath(key) {
|
|
144
|
+
return join(this.config.basePath, this.sanitizeKey(key));
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Read a file from storage
|
|
148
|
+
* Used by API endpoint to serve files
|
|
149
|
+
*/
|
|
150
|
+
async getObject(path) {
|
|
151
|
+
const resolved = this.assertWithinBase(path);
|
|
107
152
|
const { readFile } = await import('fs/promises');
|
|
108
153
|
return await readFile(resolved);
|
|
109
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Read a file from storage as a stream.
|
|
157
|
+
*
|
|
158
|
+
* Same containment check as `getObject` — a streaming read is still a read,
|
|
159
|
+
* and skipping the check here would reintroduce the traversal escape on the
|
|
160
|
+
* path callers now prefer.
|
|
161
|
+
*/
|
|
162
|
+
async getStream(path) {
|
|
163
|
+
const resolved = this.assertWithinBase(path);
|
|
164
|
+
const { createReadStream } = await import('fs');
|
|
165
|
+
const { Readable } = await import('stream');
|
|
166
|
+
// Surface a missing file as a rejected promise, matching getObject —
|
|
167
|
+
// otherwise the error would only appear mid-stream, after headers had
|
|
168
|
+
// already been sent and the status code was no longer changeable.
|
|
169
|
+
await stat(resolved);
|
|
170
|
+
return Readable.toWeb(createReadStream(resolved));
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Ranged read. Node's `start`/`end` are both inclusive, which is already the
|
|
174
|
+
* convention the port specifies, so the bounds pass through unchanged.
|
|
175
|
+
*/
|
|
176
|
+
async getObjectRange(path, start, end) {
|
|
177
|
+
const resolved = this.assertWithinBase(path);
|
|
178
|
+
const { createReadStream } = await import('fs');
|
|
179
|
+
const { Readable } = await import('stream');
|
|
180
|
+
// Same reason as getStream: a missing file has to reject before headers go
|
|
181
|
+
// out, not mid-stream once the status is already committed.
|
|
182
|
+
await stat(resolved);
|
|
183
|
+
return Readable.toWeb(createReadStream(resolved, { start, end }));
|
|
184
|
+
}
|
|
110
185
|
/**
|
|
111
186
|
* Delete a file from storage
|
|
112
187
|
*/
|
|
113
188
|
async delete(path) {
|
|
114
189
|
try {
|
|
115
|
-
|
|
116
|
-
const base = resolve(this.config.basePath);
|
|
117
|
-
if (!resolved.startsWith(base + '/') && resolved !== base) {
|
|
118
|
-
throw new Error('Access denied: path outside storage directory');
|
|
119
|
-
}
|
|
120
|
-
await unlink(resolved);
|
|
190
|
+
await unlink(this.assertWithinBase(path));
|
|
121
191
|
return true;
|
|
122
192
|
}
|
|
123
193
|
catch (error) {
|
|
@@ -130,15 +200,12 @@ export class LocalStorageAdapter {
|
|
|
130
200
|
*/
|
|
131
201
|
async exists(path) {
|
|
132
202
|
try {
|
|
133
|
-
|
|
134
|
-
const base = resolve(this.config.basePath);
|
|
135
|
-
if (!resolved.startsWith(base + '/') && resolved !== base) {
|
|
136
|
-
return false;
|
|
137
|
-
}
|
|
138
|
-
await stat(resolved);
|
|
203
|
+
await stat(this.assertWithinBase(path));
|
|
139
204
|
return true;
|
|
140
205
|
}
|
|
141
206
|
catch {
|
|
207
|
+
// Covers both "outside the base" and "not there" — `exists` reports a
|
|
208
|
+
// boolean either way, so the distinction has no caller.
|
|
142
209
|
return false;
|
|
143
210
|
}
|
|
144
211
|
}
|
package/dist/storage/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/storage/index.ts"],"names":[],"mappings":"AAIA,cAAc,oBAAoB,CAAC;AAGnC,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/storage/index.ts"],"names":[],"mappings":"AAIA,cAAc,oBAAoB,CAAC;AAGnC,cAAc,QAAQ,CAAC;AAGvB,cAAc,kBAAkB,CAAC"}
|
package/dist/storage/index.js
CHANGED