diff options
| author | Maze Winther <mazewinther@gmail.com> | 2026-03-25 16:47:22 +0100 |
|---|---|---|
| committer | Maze Winther <mazewinther@gmail.com> | 2026-03-29 15:48:22 +0200 |
| commit | 8db3bead13441a5882d8689dfc6a9f09c82375d9 (patch) | |
| tree | e9d0cafa93904ffcbec3188c37961bcc16c6422d /apps/web/src/lib/commands/media/remove-media-asset.ts | |
| parent | 39ea298a9ccba3104c549c0ca079c231981811f5 (diff) | |
| download | opencut-8db3bead13441a5882d8689dfc6a9f09c82375d9.tar.gz | |
feat: masks, properties refactor, shaders, storage migrations, and more
Diffstat (limited to 'apps/web/src/lib/commands/media/remove-media-asset.ts')
| -rw-r--r-- | apps/web/src/lib/commands/media/remove-media-asset.ts | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/apps/web/src/lib/commands/media/remove-media-asset.ts b/apps/web/src/lib/commands/media/remove-media-asset.ts index ee9ffa2d..f519baef 100644 --- a/apps/web/src/lib/commands/media/remove-media-asset.ts +++ b/apps/web/src/lib/commands/media/remove-media-asset.ts @@ -1,10 +1,10 @@ import { Command } from "@/lib/commands/base-command"; import { EditorCore } from "@/core"; -import type { MediaAsset } from "@/types/assets"; +import type { MediaAsset } from "@/lib/media/types"; import { storageService } from "@/services/storage/service"; import { videoCache } from "@/services/video-cache/service"; import { hasMediaId } from "@/lib/timeline/element-utils"; -import type { TimelineTrack } from "@/types/timeline"; +import type { TimelineTrack } from "@/lib/timeline"; export class RemoveMediaAssetCommand extends Command { private savedAssets: MediaAsset[] | null = null; @@ -33,6 +33,13 @@ export class RemoveMediaAssetCommand extends Command { return; } + if (this.removedAsset.url) { + URL.revokeObjectURL(this.removedAsset.url); + } + if (this.removedAsset.thumbnailUrl) { + URL.revokeObjectURL(this.removedAsset.thumbnailUrl); + } + videoCache.clearVideo({ mediaId: this.assetId }); editor.media.setAssets({ @@ -63,23 +70,30 @@ export class RemoveMediaAssetCommand extends Command { undo(): void { const editor = EditorCore.getInstance(); - if (this.savedAssets) { - editor.media.setAssets({ assets: this.savedAssets }); - } + if (this.savedAssets && this.removedAsset) { + const restoredAsset: MediaAsset = { + ...this.removedAsset, + url: URL.createObjectURL(this.removedAsset.file), + }; - if (this.savedTracks) { - editor.timeline.updateTracks(this.savedTracks); - } + editor.media.setAssets({ + assets: this.savedAssets.map((a) => + a.id === this.assetId ? restoredAsset : a, + ), + }); - if (this.removedAsset) { storageService .saveMediaAsset({ projectId: this.projectId, - mediaAsset: this.removedAsset, + mediaAsset: restoredAsset, }) .catch((error) => { console.error("Failed to restore media item on undo:", error); }); } + + if (this.savedTracks) { + editor.timeline.updateTracks(this.savedTracks); + } } } |
