diff options
| author | Maze Winther <mazewinther@gmail.com> | 2026-04-01 15:15:12 +0200 |
|---|---|---|
| committer | Maze Winther <mazewinther@gmail.com> | 2026-04-01 15:15:41 +0200 |
| commit | 8a1d37cf3e8d06dd7af75b5d6f9181afcc797f84 (patch) | |
| tree | 5f0e874abe3ecbdf8e5e2e3243f3743609382490 /apps/web/src/services/storage/migrations/transformers | |
| parent | e579ae120290329fd697b50ea9138ffccb65a805 (diff) | |
| download | opencut-8a1d37cf3e8d06dd7af75b5d6f9181afcc797f84.tar.gz | |
fix: align background blur with effect blur intensity scale
Diffstat (limited to 'apps/web/src/services/storage/migrations/transformers')
| -rw-r--r-- | apps/web/src/services/storage/migrations/transformers/v20-to-v21.ts | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/apps/web/src/services/storage/migrations/transformers/v20-to-v21.ts b/apps/web/src/services/storage/migrations/transformers/v20-to-v21.ts new file mode 100644 index 00000000..63ad24de --- /dev/null +++ b/apps/web/src/services/storage/migrations/transformers/v20-to-v21.ts @@ -0,0 +1,66 @@ +import { DEFAULT_BLUR_INTENSITY } from "@/constants/project-constants"; +import { INTENSITY_TO_SIGMA_DIVISOR } from "@/lib/effects/definitions/blur"; +import type { MigrationResult, ProjectRecord } from "./types"; +import { getProjectId, isRecord } from "./utils"; + +export function transformProjectV20ToV21({ + project, +}: { + project: ProjectRecord; +}): MigrationResult<ProjectRecord> { + if (!getProjectId({ project })) { + return { project, skipped: true, reason: "no project id" }; + } + + const version = project.version; + if (typeof version !== "number") { + return { project, skipped: true, reason: "invalid version" }; + } + if (version >= 21) { + return { project, skipped: true, reason: "already v21" }; + } + if (version !== 20) { + return { project, skipped: true, reason: "not v20" }; + } + + return { + project: { + ...migrateBackgroundBlurScale({ project }), + version: 21, + }, + skipped: false, + }; +} + +function migrateBackgroundBlurScale({ + project, +}: { + project: ProjectRecord; +}): ProjectRecord { + if (!isRecord(project.settings)) { + return project; + } + + const settings = { ...project.settings }; + const background = settings.background; + if (!isRecord(background) || background.type !== "blur") { + return { ...project, settings }; + } + + const raw = background.blurIntensity; + const blurIntensity = + typeof raw === "number" && Number.isFinite(raw) + ? raw * INTENSITY_TO_SIGMA_DIVISOR + : DEFAULT_BLUR_INTENSITY; + + return { + ...project, + settings: { + ...settings, + background: { + ...background, + blurIntensity, + }, + }, + }; +} |
