π₯ Make videos programmatically with React
asset cleanup
JonnyBurger1213b8522e9d
diff --git a/packages/docs/docs/editor-starter/TableOfContents.tsx b/packages/docs/docs/editor-starter/TableOfContents.tsxindex e4852f2634..0b343ba441 100644--- a/packages/docs/docs/editor-starter/TableOfContents.tsx+++ b/packages/docs/docs/editor-starter/TableOfContents.tsx@@ -46,6 +46,10 @@ export const TableOfContents: React.FC = () => {<strong>Asset Uploads</strong><div>Asset upload functionality in the Editor Starter</div></TOCItem>+ <TOCItem link="/docs/editor-starter/asset-cleanup">+ <strong>Asset Cleanup</strong>+ <div>How to cleanup assets that are no longer needed</div>+ </TOCItem><TOCItem link="/docs/editor-starter/persistance"><strong>Persistance</strong><div>How data is persisted in the Editor Starter</div>diff --git a/packages/docs/docs/editor-starter/asset-cleanup.mdx b/packages/docs/docs/editor-starter/asset-cleanup.mdxnew file mode 100644index 0000000000..c8c036b4c9--- /dev/null+++ b/packages/docs/docs/editor-starter/asset-cleanup.mdx@@ -0,0 +1,62 @@+---+image: /generated/articles-docs-editor-starter-asset-cleanup.png+title: Asset cleanup+sidebar_label: Asset cleanup+id: asset-cleanup+crumb: Editor Starter+---++You are responsible for cleaning up assets that were added by the user and are no longer needed.+Assets may lay around in S3 storage buckets and in the local IndexedDB asset cache.++## When it is safe to delete assets++When the user deletes an asset, they may still undo the deletion by pressing <kbd>β/Ctrl</kbd>+<kbd>Z</kbd>.+As long as the asset is referenced in the [undo stack](/docs/editor-starter/undo-redo), it is not safe to delete it.++If you want to clean up assets, you need to ensure that the undo stack is clean, or clear the undo stack.++## Getting deleted assets++When an asset is deleted, it is added to the `deletedAssets` array, part of the [`undoableState`](/docs/editor-starter/state-management).+As mentioned above, you need to ensure that the user is unable to undo the deletion first.++## Deleting assets++### Deleting assets from IndexedDB++If you have a `assetId` from an object in the `deletedAssets` array, you can delete it from IndexedDB by calling the [`deleteCachedAsset`](https://github.com/remotion-dev/editor-starter/blob/9fdd35812f8505273edf29f207dd9d021c901491/src/editor/caching/indexeddb.ts#L92) method.++### Deleting assets from S3++If you have a `remoteFileKey` from an object in the `deletedAssets` array, you can delete it from S3 using the following code:++```ts title="Delete an asset from S3 - must be called from the backend"+import {getAwsClient} from '@remotion/lambda/client';+import {requireServerEnv} from '../../editor/utils/server-env';++const {REMOTION_AWS_BUCKET_NAME, REMOTION_AWS_REGION} = requireServerEnv();++const {client, sdk} = getAwsClient({+ region: REMOTION_AWS_REGION,+ service: 's3',+});++const command = new sdk.DeleteObjectCommand({+ Bucket: REMOTION_AWS_BUCKET_NAME,+ Key: remoteFileKey,+});++await client.send(command);+```++You only need to clear assets which have an `assetStatus` of `uploaded`.++### Removing from the state++Once an asset has been successfully deleted from S3 and IndexedDB, you can remove it from the state by calling the [`clearDeletedAsset()`](https://github.com/remotion-dev/editor-starter/blob/main/src/editor/state/actions/clear-deleted-asset.ts) method.++## See also++- [Asset uploads](/docs/editor-starter/asset-uploads)+- [Persistance](/docs/editor-starter/persistance)diff --git a/packages/docs/docs/editor-starter/asset-uploads.mdx b/packages/docs/docs/editor-starter/asset-uploads.mdxindex de783f922c..4a4bd5095e 100644--- a/packages/docs/docs/editor-starter/asset-uploads.mdx+++ b/packages/docs/docs/editor-starter/asset-uploads.mdx@@ -92,3 +92,4 @@ Then set the `REMOTION_AWS_TRANSFER_ACCELERATION` environment variable to `true`## See also- [Tracks, items and assets](/docs/editor-starter/tracks-items-assets)+- [Asset cleanup](/docs/editor-starter/asset-cleanup)diff --git a/packages/docs/docs/editor-starter/state-management.mdx b/packages/docs/docs/editor-starter/state-management.mdxindex 04612d6d30..017510cc25 100644--- a/packages/docs/docs/editor-starter/state-management.mdx+++ b/packages/docs/docs/editor-starter/state-management.mdx@@ -19,6 +19,13 @@ State in the [Editor Starter](/docs/editor-starter) is managed with the built-inThe whole state of the Editor Starter is stored in a single object with the shape defined by the [`EditorState`](https://github.com/search?q=repo%3Aremotion-dev%2Feditor-starter%20type%20EditorState&type=code).```ts title="src/editor/state/types.ts"+type DeletedAsset = {+ remoteUrl: string | null;+ remoteFileKey: string | null;+ assetId: string;+ statusAtDeletion: AssetState;+};+export type UndoableState = {tracks: TrackType[];assets: Record<string, EditorStarterAsset>;@@ -26,6 +33,7 @@ export type UndoableState = {fps: number;compositionWidth: number;compositionHeight: number;+ deletedAssets: DeletedAsset[];};export type EditorState = {@@ -49,6 +57,7 @@ export type EditorState = {- `fps`: The frame rate (kept in state, [but no UI is exposed to change it](/docs/editor-starter/features-not-included#multiple-frame-rates))- `compositionWidth`: The width of the canvas- `compositionHeight`: The height of the canvas+ - `deletedAssets`: An array of assets [that have been deleted](/docs/editor-starter/asset-cleanup)- `selectedItems`: An array of item IDs that are currently selected- `textItemEditing`: The ID of the text item that is currently being edited, if there is one- `textItemHoverPreview`: Preview updates of a text item (for example if a font is hovered in the font picker, the text will render temporarily with the font hovered)diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.tsindex ab9e1d9b78..ccb0c4bd8a 100644--- a/packages/docs/sidebars.ts+++ b/packages/docs/sidebars.ts@@ -1359,6 +1359,7 @@ const sidebars: SidebarsConfig = {'editor-starter/undo-redo','editor-starter/fonts','editor-starter/asset-uploads',+ 'editor-starter/asset-cleanup','editor-starter/persistance','editor-starter/captioning','editor-starter/rendering',diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex 7729528809..f40ff80bd0 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -1277,6 +1277,15 @@ export const articles = [noAi: false,slug: 'easing',},+ {+ id: 'asset-cleanup',+ title: 'Asset cleanup',+ relativePath: 'docs/editor-starter/asset-cleanup.mdx',+ compId: 'articles-docs-editor-starter-asset-cleanup',+ crumb: 'Editor Starter',+ noAi: false,+ slug: 'editor-starter/asset-cleanup',+ },{id: 'asset-uploads',title: 'Asset uploads',diff --git a/packages/docs/static/generated/articles-docs-editor-starter-asset-cleanup.png b/packages/docs/static/generated/articles-docs-editor-starter-asset-cleanup.pngnew file mode 100644index 0000000000..836c1200eaBinary files /dev/null and b/packages/docs/static/generated/articles-docs-editor-starter-asset-cleanup.png differ