appos 0.3.5-0 → 0.3.7-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/bin/main.mjs +3 -3
- package/dist/bin/youch-handler-D7REmh8Z.mjs +2 -0
- package/dist/exports/api/adapter-C2mMJKvG.mjs +1504 -0
- package/dist/exports/api/{auth-schema.mjs → auth-schema-CON4yFFY.mjs} +2 -3
- package/dist/exports/api/bun-sqlite-dialect-CPpPZa23.mjs +155 -0
- package/dist/exports/{cli/_virtual/rolldown_runtime.mjs → api/chunk-CyXqrcp_.mjs} +14 -1
- package/dist/exports/api/conditions-DjBAWfiK.mjs +116 -0
- package/dist/exports/api/dialect-CUUD24Ge.mjs +72 -0
- package/dist/exports/api/env-CwT3zhez.mjs +1 -0
- package/dist/exports/api/esm-_hkVMulx.mjs +15816 -0
- package/dist/exports/api/event-BHFSE6hY.mjs +20983 -0
- package/dist/exports/api/extract-blob-metadata-BMgUEPcW.mjs +4 -0
- package/dist/exports/api/extract-blob-metadata-_9RUEwoU.mjs +9818 -0
- package/dist/exports/api/generate-image-variant-DOIzj1wJ.mjs +4 -0
- package/dist/exports/api/generate-image-variant-DxOPoGAk.mjs +118 -0
- package/dist/exports/api/generate-preview-CvTFuq58.mjs +160 -0
- package/dist/exports/api/generate-preview-Dk3coswZ.mjs +4 -0
- package/dist/exports/api/index.d.mts +7347 -20
- package/dist/exports/api/index.mjs +146856 -18
- package/dist/exports/api/kysely-adapter-CmP2TbkS.mjs +296 -0
- package/dist/exports/api/memory-adapter-BzhRhLFK.mjs +212 -0
- package/dist/exports/api/node-sqlite-dialect-Bl5suBxl.mjs +155 -0
- package/dist/exports/api/orm-CMqufD21.mjs +153690 -0
- package/dist/exports/api/orm-DXqYuKvB.d.mts +11 -0
- package/dist/exports/api/orm.d.mts +2 -11
- package/dist/exports/api/orm.mjs +4 -42
- package/dist/exports/api/pdf-YxB2Hm1p.mjs +25822 -0
- package/dist/exports/api/purge-attachment-Cf6KH2Jv.mjs +34 -0
- package/dist/exports/api/purge-attachment-DIuil7ps.mjs +4 -0
- package/dist/exports/{cli/api/workflows/purge-audit-logs.mjs → api/purge-audit-logs-z6j_Pu47.mjs} +3 -3
- package/dist/exports/{cli/api/workflows/purge-unattached-blobs.mjs → api/purge-unattached-blobs-B0TfY5Hk.mjs} +1 -1
- package/dist/exports/api/react-BYhV5bYt.mjs +1131 -0
- package/dist/exports/api/server.node-DyVrQ6cz.mjs +19298 -0
- package/dist/exports/api/table-6bTIEqON.mjs +2636 -0
- package/dist/exports/api/{workflows/track-db-changes.mjs → track-db-changes-BysaV6nN.mjs} +14 -14
- package/dist/exports/api/{workflow.mjs → workflow-BuSWHcX-.mjs} +121 -10
- package/dist/exports/api/workflows/auth-schema-BFve3hgZ.mjs +2813 -0
- package/dist/exports/api/workflows/{_virtual/rolldown_runtime.mjs → chunk-B36mNPO4.mjs} +5 -1
- package/dist/exports/api/workflows/extract-blob-metadata-BcWKvY2K.mjs +9818 -0
- package/dist/exports/{cli/api/workflows/generate-image-variant.mjs → api/workflows/generate-image-variant-BAFvL_zV.mjs} +20 -20
- package/dist/exports/{cli/api/workflows/generate-preview.mjs → api/workflows/generate-preview-BjlIVYYp.mjs} +6 -6
- package/dist/exports/api/workflows/index.d.mts +2011 -1
- package/dist/exports/api/workflows/index.mjs +2 -1
- package/dist/exports/api/workflows/pdf-DUB8zyIc.mjs +25822 -0
- package/dist/exports/{cli/api/workflows/purge-attachment.mjs → api/workflows/purge-attachment-k_sdxTPY.mjs} +3 -3
- package/dist/exports/api/workflows/{purge-audit-logs.mjs → purge-audit-logs-zCyWj4Mw.mjs} +12 -3
- package/dist/exports/api/workflows/{purge-unattached-blobs.mjs → purge-unattached-blobs-CdsuFAeW.mjs} +1 -1
- package/dist/exports/api/workflows/track-db-changes-CiKaI9gT.mjs +20943 -0
- package/dist/exports/api/workflows/track-db-changes-DEWQYryO.mjs +4 -0
- package/dist/exports/{cli/api/workflow.mjs → api/workflows/workflow-BjM2xCa6.mjs} +23 -3
- package/dist/exports/api/workflows/zod-Br0enFWK.mjs +12333 -0
- package/dist/exports/api/zod-CdrJdBtV.mjs +12571 -0
- package/dist/exports/cli/auth-schema-CNuOqPi-.mjs +2813 -0
- package/dist/exports/{api/_virtual/rolldown_runtime.mjs → cli/chunk-B36mNPO4.mjs} +5 -1
- package/dist/exports/cli/extract-blob-metadata-CV1Ke90d.mjs +9818 -0
- package/dist/exports/{api/workflows/generate-image-variant.mjs → cli/generate-image-variant-CM1BrVvZ.mjs} +20 -20
- package/dist/exports/{api/workflows/generate-preview.mjs → cli/generate-preview-DdHQ3ukz.mjs} +6 -6
- package/dist/exports/cli/index.d.mts +2142 -2
- package/dist/exports/cli/index.mjs +41 -1
- package/dist/exports/cli/pdf-CLUPEIdT.mjs +25822 -0
- package/dist/exports/{api/workflows/purge-attachment.mjs → cli/purge-attachment-Dc_J74dG.mjs} +3 -3
- package/dist/exports/cli/purge-audit-logs-DFhWh-Bx.mjs +56 -0
- package/dist/exports/cli/purge-unattached-blobs-C1MRlM_2.mjs +46 -0
- package/dist/exports/cli/track-db-changes-CfneOF2_.mjs +20943 -0
- package/dist/exports/{api/workflows/api/workflow.mjs → cli/workflow-DSbbXBMt.mjs} +23 -3
- package/dist/exports/cli/zod-7q0_Mtnn.mjs +12333 -0
- package/dist/exports/tests/api.d.mts +7354 -5
- package/dist/exports/tests/api.mjs +79 -1
- package/dist/exports/tests/auth-schema-B_qHPoa4.mjs +1 -0
- package/dist/exports/tests/chunk-Cii4FAhs.mjs +1 -0
- package/dist/exports/tests/conditions-BeWxRN_Z.mjs +1 -0
- package/dist/exports/tests/constants-D_m07gCJ.mjs +1 -0
- package/dist/exports/tests/dist-Cx2HEBOB.mjs +296 -0
- package/dist/exports/tests/dist-DnACOvNW.mjs +7 -0
- package/dist/exports/tests/extract-blob-metadata-6xQrarjB.mjs +169 -0
- package/dist/exports/tests/generate-image-variant-KQITLmCx.mjs +1 -0
- package/dist/exports/tests/generate-preview-YnujQo5I.mjs +1 -0
- package/dist/exports/tests/mock-BvoS23fi.mjs +1 -0
- package/dist/exports/tests/mock.mjs +1 -1
- package/dist/exports/tests/pdf-lZ-as2o7.mjs +13 -0
- package/dist/exports/tests/purge-attachment-DTSmCl-z.mjs +1 -0
- package/dist/exports/tests/purge-audit-logs-D0_UUhN2.mjs +1 -0
- package/dist/exports/tests/purge-unattached-blobs-IENmSB8K.mjs +1 -0
- package/dist/exports/tests/react.mjs +6 -1
- package/dist/exports/tests/setup.d.mts +1 -1
- package/dist/exports/tests/setup.mjs +34 -1
- package/dist/exports/tests/table-CmPSf_pE.mjs +1 -0
- package/dist/exports/tests/track-db-changes-Td9Q3DLd.mjs +1 -0
- package/dist/exports/tests/{api/workflow.mjs → workflow-BWRWyC83.mjs} +1 -1
- package/dist/exports/tests/youch-handler-efUxKCCs.mjs +1 -0
- package/dist/exports/tests/zod-CkJO9qpV.mjs +23 -0
- package/dist/exports/vendors/date.js +13236 -1
- package/dist/exports/vendors/toolkit.js +2206 -1
- package/dist/exports/vendors/zod.js +12344 -1
- package/dist/exports/vite/index.d.mts +1 -1
- package/dist/exports/vite/index.mjs +26 -1
- package/dist/exports/vite/lib-B0s0q6aX.mjs +382 -0
- package/dist/exports/vite/lib-BkrbWMaV.mjs +1 -0
- package/dist/exports/web/browser-ponyfill-DxTJMXNq.js +443 -0
- package/dist/exports/web/chunk-DksrlJLg.js +49 -0
- package/dist/exports/web/index.d.ts +2546 -2
- package/dist/exports/web/index.js +9295 -6
- package/dist/exports/web/plugin-DqTFWG7p.js +250 -0
- package/package.json +1 -7
- package/dist/bin/youch-handler-DrYdbUhe.mjs +0 -2
- package/dist/exports/api/app-context.d.mts +0 -115
- package/dist/exports/api/app-context.mjs +0 -24
- package/dist/exports/api/auth-schema.d.mts +0 -4248
- package/dist/exports/api/auth.d.mts +0 -402
- package/dist/exports/api/auth.mjs +0 -188
- package/dist/exports/api/cache.d.mts +0 -44
- package/dist/exports/api/cache.mjs +0 -28
- package/dist/exports/api/config.d.mts +0 -28
- package/dist/exports/api/config.mjs +0 -72
- package/dist/exports/api/constants.mjs +0 -92
- package/dist/exports/api/container.d.mts +0 -210
- package/dist/exports/api/container.mjs +0 -49
- package/dist/exports/api/database.d.mts +0 -101
- package/dist/exports/api/database.mjs +0 -219
- package/dist/exports/api/event.d.mts +0 -235
- package/dist/exports/api/event.mjs +0 -236
- package/dist/exports/api/i18n.d.mts +0 -34
- package/dist/exports/api/i18n.mjs +0 -45
- package/dist/exports/api/instrumentation.d.mts +0 -7
- package/dist/exports/api/instrumentation.mjs +0 -40
- package/dist/exports/api/logger.d.mts +0 -21
- package/dist/exports/api/logger.mjs +0 -26
- package/dist/exports/api/mailer.d.mts +0 -70
- package/dist/exports/api/mailer.mjs +0 -37
- package/dist/exports/api/middleware/request-logger.d.mts +0 -24
- package/dist/exports/api/middleware.d.mts +0 -39
- package/dist/exports/api/middleware.mjs +0 -73
- package/dist/exports/api/openapi.d.mts +0 -271
- package/dist/exports/api/openapi.mjs +0 -507
- package/dist/exports/api/otel.d.mts +0 -40
- package/dist/exports/api/otel.mjs +0 -56
- package/dist/exports/api/redis.d.mts +0 -34
- package/dist/exports/api/redis.mjs +0 -41
- package/dist/exports/api/storage-schema.d.mts +0 -707
- package/dist/exports/api/storage-schema.mjs +0 -72
- package/dist/exports/api/storage.d.mts +0 -506
- package/dist/exports/api/storage.mjs +0 -833
- package/dist/exports/api/web/auth.mjs +0 -17
- package/dist/exports/api/workflow.d.mts +0 -250
- package/dist/exports/api/workflows/api/auth-schema.mjs +0 -373
- package/dist/exports/api/workflows/api/auth.d.mts +0 -379
- package/dist/exports/api/workflows/api/cache.d.mts +0 -44
- package/dist/exports/api/workflows/api/config.d.mts +0 -18
- package/dist/exports/api/workflows/api/container.d.mts +0 -167
- package/dist/exports/api/workflows/api/database.d.mts +0 -47
- package/dist/exports/api/workflows/api/event.d.mts +0 -68
- package/dist/exports/api/workflows/api/event.mjs +0 -126
- package/dist/exports/api/workflows/api/logger.d.mts +0 -21
- package/dist/exports/api/workflows/api/mailer.d.mts +0 -70
- package/dist/exports/api/workflows/api/orm.d.mts +0 -13
- package/dist/exports/api/workflows/api/redis.mjs +0 -3
- package/dist/exports/api/workflows/api/storage-schema.d.mts +0 -699
- package/dist/exports/api/workflows/api/storage.d.mts +0 -396
- package/dist/exports/api/workflows/api/workflow.d.mts +0 -24
- package/dist/exports/api/workflows/constants.mjs +0 -23
- package/dist/exports/api/workflows/extract-blob-metadata.mjs +0 -132
- package/dist/exports/api/workflows/generate-image-variant.d.mts +0 -63
- package/dist/exports/api/workflows/track-db-changes.d.mts +0 -72
- package/dist/exports/cli/api/auth-schema.mjs +0 -373
- package/dist/exports/cli/api/auth.d.mts +0 -379
- package/dist/exports/cli/api/cache.d.mts +0 -44
- package/dist/exports/cli/api/config.d.mts +0 -18
- package/dist/exports/cli/api/container.d.mts +0 -167
- package/dist/exports/cli/api/database.d.mts +0 -47
- package/dist/exports/cli/api/event.d.mts +0 -68
- package/dist/exports/cli/api/event.mjs +0 -126
- package/dist/exports/cli/api/logger.d.mts +0 -21
- package/dist/exports/cli/api/mailer.d.mts +0 -70
- package/dist/exports/cli/api/orm.d.mts +0 -13
- package/dist/exports/cli/api/redis.mjs +0 -3
- package/dist/exports/cli/api/storage-schema.d.mts +0 -699
- package/dist/exports/cli/api/storage.d.mts +0 -396
- package/dist/exports/cli/api/workflow.d.mts +0 -2
- package/dist/exports/cli/api/workflows/extract-blob-metadata.mjs +0 -132
- package/dist/exports/cli/api/workflows/generate-image-variant.d.mts +0 -63
- package/dist/exports/cli/api/workflows/track-db-changes.mjs +0 -110
- package/dist/exports/cli/command.d.mts +0 -56
- package/dist/exports/cli/command.mjs +0 -43
- package/dist/exports/cli/constants.mjs +0 -23
- package/dist/exports/cli/context.d.mts +0 -170
- package/dist/exports/devtools/index.d.ts +0 -3
- package/dist/exports/devtools/index.js +0 -4
- package/dist/exports/tests/_virtual/rolldown_runtime.mjs +0 -1
- package/dist/exports/tests/api/app-context.d.mts +0 -115
- package/dist/exports/tests/api/app-context.mjs +0 -1
- package/dist/exports/tests/api/auth-schema.d.mts +0 -4248
- package/dist/exports/tests/api/auth-schema.mjs +0 -1
- package/dist/exports/tests/api/auth.d.mts +0 -402
- package/dist/exports/tests/api/cache.d.mts +0 -44
- package/dist/exports/tests/api/config.d.mts +0 -28
- package/dist/exports/tests/api/container.d.mts +0 -210
- package/dist/exports/tests/api/database.d.mts +0 -101
- package/dist/exports/tests/api/database.mjs +0 -1
- package/dist/exports/tests/api/event.d.mts +0 -235
- package/dist/exports/tests/api/event.mjs +0 -1
- package/dist/exports/tests/api/i18n.d.mts +0 -34
- package/dist/exports/tests/api/index.d.mts +0 -26
- package/dist/exports/tests/api/logger.d.mts +0 -21
- package/dist/exports/tests/api/mailer.d.mts +0 -70
- package/dist/exports/tests/api/middleware/error-handler.mjs +0 -1
- package/dist/exports/tests/api/middleware/health.mjs +0 -1
- package/dist/exports/tests/api/middleware/i18n.mjs +0 -1
- package/dist/exports/tests/api/middleware/request-logger.d.mts +0 -24
- package/dist/exports/tests/api/middleware/request-logger.mjs +0 -1
- package/dist/exports/tests/api/middleware/shutdown.mjs +0 -1
- package/dist/exports/tests/api/middleware/timeout.mjs +0 -1
- package/dist/exports/tests/api/middleware/youch-handler.mjs +0 -1
- package/dist/exports/tests/api/middleware.d.mts +0 -39
- package/dist/exports/tests/api/middleware.mjs +0 -1
- package/dist/exports/tests/api/openapi.d.mts +0 -271
- package/dist/exports/tests/api/openapi.mjs +0 -1
- package/dist/exports/tests/api/orm.d.mts +0 -13
- package/dist/exports/tests/api/otel.d.mts +0 -40
- package/dist/exports/tests/api/redis.d.mts +0 -34
- package/dist/exports/tests/api/redis.mjs +0 -1
- package/dist/exports/tests/api/server.mjs +0 -1
- package/dist/exports/tests/api/storage-schema.d.mts +0 -707
- package/dist/exports/tests/api/storage.d.mts +0 -506
- package/dist/exports/tests/api/workflow.d.mts +0 -250
- package/dist/exports/tests/api/workflows/extract-blob-metadata.mjs +0 -1
- package/dist/exports/tests/api/workflows/generate-image-variant.d.mts +0 -63
- package/dist/exports/tests/api/workflows/generate-image-variant.mjs +0 -1
- package/dist/exports/tests/api/workflows/generate-preview.mjs +0 -1
- package/dist/exports/tests/api/workflows/purge-attachment.mjs +0 -1
- package/dist/exports/tests/api/workflows/purge-audit-logs.mjs +0 -1
- package/dist/exports/tests/api/workflows/purge-unattached-blobs.mjs +0 -1
- package/dist/exports/tests/api/workflows/track-db-changes.mjs +0 -1
- package/dist/exports/tests/constants.mjs +0 -1
- package/dist/exports/tests/instrumentation.d.mts +0 -7
- package/dist/exports/tests/instrumentation.mjs +0 -1
- package/dist/exports/web/api/auth.d.ts +0 -125
- package/dist/exports/web/api/database.d.ts +0 -4
- package/dist/exports/web/api/logger.d.ts +0 -1
- package/dist/exports/web/auth.d.ts +0 -2388
- package/dist/exports/web/auth.js +0 -75
- package/dist/exports/web/i18n.d.ts +0 -42
- package/dist/exports/web/i18n.js +0 -45
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { C as object, E as string, S as number, b as literal, l as _enum, p as boolean } from "./zod-CdrJdBtV.mjs";
|
|
2
|
+
import { n as defineWorkflow } from "./workflow-BuSWHcX-.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/api/workflows/generate-image-variant.ts
|
|
5
|
+
/**
|
|
6
|
+
* Resize options schema for image transformations.
|
|
7
|
+
*/
|
|
8
|
+
const resizeSchema = object({
|
|
9
|
+
width: number().optional(),
|
|
10
|
+
height: number().optional(),
|
|
11
|
+
fit: _enum([
|
|
12
|
+
"cover",
|
|
13
|
+
"contain",
|
|
14
|
+
"fill",
|
|
15
|
+
"inside",
|
|
16
|
+
"outside"
|
|
17
|
+
]).optional(),
|
|
18
|
+
position: _enum([
|
|
19
|
+
"top",
|
|
20
|
+
"right top",
|
|
21
|
+
"right",
|
|
22
|
+
"right bottom",
|
|
23
|
+
"bottom",
|
|
24
|
+
"left bottom",
|
|
25
|
+
"left",
|
|
26
|
+
"left top",
|
|
27
|
+
"centre"
|
|
28
|
+
]).optional(),
|
|
29
|
+
kernel: _enum([
|
|
30
|
+
"nearest",
|
|
31
|
+
"linear",
|
|
32
|
+
"cubic",
|
|
33
|
+
"mitchell",
|
|
34
|
+
"lanczos2",
|
|
35
|
+
"lanczos3"
|
|
36
|
+
]).optional()
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* Image transformations schema.
|
|
40
|
+
* Supports resize, rotate, flip, flop, sharpen, blur, grayscale, format conversion.
|
|
41
|
+
*/
|
|
42
|
+
const transformationsSchema = object({
|
|
43
|
+
resize: resizeSchema.optional(),
|
|
44
|
+
rotate: number().optional(),
|
|
45
|
+
flip: boolean().optional(),
|
|
46
|
+
flop: boolean().optional(),
|
|
47
|
+
sharpen: boolean().optional(),
|
|
48
|
+
blur: number().optional(),
|
|
49
|
+
grayscale: boolean().optional(),
|
|
50
|
+
format: _enum([
|
|
51
|
+
"jpeg",
|
|
52
|
+
"png",
|
|
53
|
+
"webp",
|
|
54
|
+
"avif",
|
|
55
|
+
"gif"
|
|
56
|
+
]).optional(),
|
|
57
|
+
quality: number().min(1).max(100).optional(),
|
|
58
|
+
preview: literal(true).optional()
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* Generate image variant workflow. Applies transformations to create variants.
|
|
62
|
+
*
|
|
63
|
+
* Algorithm:
|
|
64
|
+
* 1. Fetch blob by ID
|
|
65
|
+
* 2. Download blob content
|
|
66
|
+
* 3. Apply transformations using Sharp:
|
|
67
|
+
* - Resize with various fit options
|
|
68
|
+
* - Rotate by degrees
|
|
69
|
+
* - Flip/flop (vertical/horizontal mirror)
|
|
70
|
+
* - Sharpen, blur, grayscale filters
|
|
71
|
+
* - Format conversion with quality settings
|
|
72
|
+
* 4. Store variant with transformation metadata
|
|
73
|
+
*/
|
|
74
|
+
const generateImageVariant = defineWorkflow({
|
|
75
|
+
input: object({
|
|
76
|
+
blobId: string(),
|
|
77
|
+
transformations: transformationsSchema
|
|
78
|
+
}),
|
|
79
|
+
async run({ container, input: { blobId, transformations }, step }) {
|
|
80
|
+
if (!await step("fetch-blob", async () => {
|
|
81
|
+
return container.storage.primary.getBlob(blobId);
|
|
82
|
+
})) throw new Error(`Blob ${blobId} not found`);
|
|
83
|
+
const buffer = await step("download-blob", async () => {
|
|
84
|
+
return container.storage.primary.downloadBlob(blobId);
|
|
85
|
+
});
|
|
86
|
+
if (!buffer) throw new Error(`Failed to download blob ${blobId}`);
|
|
87
|
+
const variantBuffer = await step("apply-transformations", async () => {
|
|
88
|
+
const sharp = (await import("sharp")).default;
|
|
89
|
+
let pipeline = sharp(buffer);
|
|
90
|
+
if (transformations.resize) pipeline = pipeline.resize({
|
|
91
|
+
width: transformations.resize.width,
|
|
92
|
+
height: transformations.resize.height,
|
|
93
|
+
fit: transformations.resize.fit,
|
|
94
|
+
position: transformations.resize.position,
|
|
95
|
+
kernel: transformations.resize.kernel
|
|
96
|
+
});
|
|
97
|
+
if (transformations.rotate !== void 0) pipeline = pipeline.rotate(transformations.rotate);
|
|
98
|
+
if (transformations.flip) pipeline = pipeline.flip();
|
|
99
|
+
if (transformations.flop) pipeline = pipeline.flop();
|
|
100
|
+
if (transformations.sharpen) pipeline = pipeline.sharpen();
|
|
101
|
+
if (transformations.blur !== void 0) pipeline = pipeline.blur(transformations.blur);
|
|
102
|
+
if (transformations.grayscale) pipeline = pipeline.grayscale();
|
|
103
|
+
if (transformations.format) pipeline = pipeline.toFormat(transformations.format, { quality: transformations.quality });
|
|
104
|
+
return pipeline.toBuffer();
|
|
105
|
+
});
|
|
106
|
+
const variant = await step("store-variant", async () => {
|
|
107
|
+
return container.storage.primary.createVariant(blobId, transformations, variantBuffer);
|
|
108
|
+
});
|
|
109
|
+
container.logger.info({
|
|
110
|
+
blobId,
|
|
111
|
+
variantId: variant.id
|
|
112
|
+
}, "Image variant generated");
|
|
113
|
+
return variant;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
//#endregion
|
|
118
|
+
export { resizeSchema as n, transformationsSchema as r, generateImageVariant as t };
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { t as zod_default } from "./zod-CdrJdBtV.mjs";
|
|
2
|
+
import { n as defineWorkflow } from "./workflow-BuSWHcX-.mjs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
|
|
6
|
+
//#region src/api/workflows/generate-preview.ts
|
|
7
|
+
/**
|
|
8
|
+
* Generate preview workflow. Creates preview images/thumbnails for PDFs and videos.
|
|
9
|
+
*
|
|
10
|
+
* Algorithm:
|
|
11
|
+
* 1. Fetch blob by ID
|
|
12
|
+
* 2. Download blob content
|
|
13
|
+
* 3. Generate preview based on content type:
|
|
14
|
+
* - Video: Extract frame at specified time using FFmpeg
|
|
15
|
+
* - PDF: Render first page using pdfjs-dist + canvas
|
|
16
|
+
* - Image: Resize to max 800x800 maintaining aspect ratio
|
|
17
|
+
* 4. Store preview as a special variant with "preview" transformation key
|
|
18
|
+
*/
|
|
19
|
+
const generatePreview = defineWorkflow({
|
|
20
|
+
input: zod_default.object({
|
|
21
|
+
blobId: zod_default.string(),
|
|
22
|
+
timeInSeconds: zod_default.number().optional()
|
|
23
|
+
}),
|
|
24
|
+
async run({ container, input: { blobId, timeInSeconds = 1 }, step }) {
|
|
25
|
+
const blob = await step("fetch-blob", async () => {
|
|
26
|
+
return container.storage.primary.getBlob(blobId);
|
|
27
|
+
});
|
|
28
|
+
if (!blob) throw new Error(`Blob ${blobId} not found`);
|
|
29
|
+
const buffer = await step("download-blob", async () => {
|
|
30
|
+
return container.storage.primary.downloadBlob(blobId);
|
|
31
|
+
});
|
|
32
|
+
if (!buffer) throw new Error(`Failed to download blob ${blobId}`);
|
|
33
|
+
let previewBuffer = null;
|
|
34
|
+
if (blob.contentType?.startsWith("video/")) previewBuffer = await step("generate-video-preview", async () => {
|
|
35
|
+
return new Promise((resolve$1, reject) => {
|
|
36
|
+
try {
|
|
37
|
+
const ffmpeg = spawn("ffmpeg", [
|
|
38
|
+
"-i",
|
|
39
|
+
"pipe:0",
|
|
40
|
+
"-ss",
|
|
41
|
+
timeInSeconds.toString(),
|
|
42
|
+
"-frames:v",
|
|
43
|
+
"1",
|
|
44
|
+
"-f",
|
|
45
|
+
"image2pipe",
|
|
46
|
+
"-c:v",
|
|
47
|
+
"png",
|
|
48
|
+
"pipe:1"
|
|
49
|
+
]);
|
|
50
|
+
const chunks = [];
|
|
51
|
+
const errorChunks = [];
|
|
52
|
+
ffmpeg.stdout.on("data", (chunk) => {
|
|
53
|
+
chunks.push(chunk);
|
|
54
|
+
});
|
|
55
|
+
ffmpeg.stderr.on("data", (chunk) => {
|
|
56
|
+
errorChunks.push(chunk);
|
|
57
|
+
});
|
|
58
|
+
ffmpeg.on("close", async (code) => {
|
|
59
|
+
if (code === 0) try {
|
|
60
|
+
const pngBuffer = Buffer.concat(chunks);
|
|
61
|
+
const sharp = (await import("sharp")).default;
|
|
62
|
+
resolve$1(await sharp(pngBuffer).jpeg({ quality: 80 }).toBuffer());
|
|
63
|
+
} catch (error) {
|
|
64
|
+
container.logger.error({
|
|
65
|
+
error,
|
|
66
|
+
blobId
|
|
67
|
+
}, "Failed to convert video frame to JPEG");
|
|
68
|
+
reject(error);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
const errorMessage = Buffer.concat(errorChunks).toString();
|
|
72
|
+
const error = /* @__PURE__ */ new Error(`FFmpeg exited with code ${code}: ${errorMessage}`);
|
|
73
|
+
container.logger.error({
|
|
74
|
+
error,
|
|
75
|
+
blobId,
|
|
76
|
+
code,
|
|
77
|
+
stderr: errorMessage
|
|
78
|
+
}, "Failed to generate video preview");
|
|
79
|
+
reject(error);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
ffmpeg.on("error", (error) => {
|
|
83
|
+
container.logger.error({
|
|
84
|
+
error,
|
|
85
|
+
blobId
|
|
86
|
+
}, "Failed to spawn FFmpeg process");
|
|
87
|
+
reject(error);
|
|
88
|
+
});
|
|
89
|
+
ffmpeg.stdin.on("error", (error) => {
|
|
90
|
+
if (error.code !== "EPIPE") container.logger.error({
|
|
91
|
+
error,
|
|
92
|
+
blobId
|
|
93
|
+
}, "Failed to write to FFmpeg stdin");
|
|
94
|
+
});
|
|
95
|
+
ffmpeg.stdin.write(buffer);
|
|
96
|
+
ffmpeg.stdin.end();
|
|
97
|
+
} catch (error) {
|
|
98
|
+
container.logger.error({
|
|
99
|
+
error,
|
|
100
|
+
blobId
|
|
101
|
+
}, "Failed to generate video preview");
|
|
102
|
+
reject(error);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
else if (blob.contentType === "application/pdf") previewBuffer = await step("generate-pdf-preview", async () => {
|
|
107
|
+
try {
|
|
108
|
+
const pdfjsLib = await import("./pdf-YxB2Hm1p.mjs");
|
|
109
|
+
const { createCanvas } = await import("canvas");
|
|
110
|
+
const sharp = (await import("sharp")).default;
|
|
111
|
+
const standardFontDataUrl = `${join(process.cwd(), "node_modules/pdfjs-dist/standard_fonts")}/`;
|
|
112
|
+
const page = await (await pdfjsLib.getDocument({
|
|
113
|
+
data: new Uint8Array(buffer),
|
|
114
|
+
standardFontDataUrl
|
|
115
|
+
}).promise).getPage(1);
|
|
116
|
+
const viewport = page.getViewport({ scale: 2 });
|
|
117
|
+
const canvas = createCanvas(viewport.width, viewport.height);
|
|
118
|
+
const context = canvas.getContext("2d");
|
|
119
|
+
await page.render({
|
|
120
|
+
canvasContext: context,
|
|
121
|
+
viewport,
|
|
122
|
+
canvas
|
|
123
|
+
}).promise;
|
|
124
|
+
return await sharp(canvas.toBuffer("image/png")).resize(800, 800, {
|
|
125
|
+
fit: "inside",
|
|
126
|
+
withoutEnlargement: true
|
|
127
|
+
}).jpeg({ quality: 85 }).toBuffer();
|
|
128
|
+
} catch (error) {
|
|
129
|
+
container.logger.error({
|
|
130
|
+
error,
|
|
131
|
+
errorMessage: error instanceof Error ? error.message : String(error),
|
|
132
|
+
errorStack: error instanceof Error ? error.stack : void 0,
|
|
133
|
+
errorCode: error?.code,
|
|
134
|
+
blobId
|
|
135
|
+
}, "Failed to generate PDF preview");
|
|
136
|
+
throw error;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
else if (blob.contentType?.startsWith("image/")) previewBuffer = await step("generate-image-preview", async () => {
|
|
140
|
+
const sharp = (await import("sharp")).default;
|
|
141
|
+
return await sharp(buffer).resize(800, 800, {
|
|
142
|
+
fit: "inside",
|
|
143
|
+
withoutEnlargement: true
|
|
144
|
+
}).jpeg({ quality: 85 }).toBuffer();
|
|
145
|
+
});
|
|
146
|
+
else throw new Error(`Preview generation not supported for content type: ${blob.contentType}`);
|
|
147
|
+
const preview = await step("store-preview", async () => {
|
|
148
|
+
return await container.storage.primary.createVariant(blobId, { preview: true }, previewBuffer);
|
|
149
|
+
});
|
|
150
|
+
container.logger.info({
|
|
151
|
+
blobId,
|
|
152
|
+
previewId: preview.id,
|
|
153
|
+
contentType: blob.contentType
|
|
154
|
+
}, "Preview generated");
|
|
155
|
+
return preview;
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
//#endregion
|
|
160
|
+
export { generatePreview as t };
|