资源清理
你负责清理用户添加的且不再需要的资源。
这些资源可能存放在 S3 存储桶中,也可能保存在本地 IndexedDB 资源缓存中。
🌐 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
当用户删除资源时,他们仍然可以通过按 Cmd/Ctrl+Z来撤销删除。
只要资源在撤销堆栈中被引用,就不可以安全地删除它。
如果你想清理资源,你需要确保撤销栈是干净的,或者清空撤销栈。
🌐 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
当一个资源被删除时,它会被添加到 deletedAssets 数组中,这是 undoableState 的一部分。如上所述,你需要首先确保用户无法撤销删除操作。
🌐 When an asset is deleted, it is added to the deletedAssets array, part of the undoableState.
As mentioned above, you need to ensure that the user is unable to undo the deletion first.
删除资源
🌐 Deleting assets
从 IndexedDB 删除资源
🌐 Deleting assets from IndexedDB
如果你从 deletedAssets 数组中的一个对象获得了 assetId,你可以通过调用 deleteCachedAsset 方法从 IndexedDB 中删除它。
🌐 If you have a assetId from an object in the deletedAssets array, you can delete it from IndexedDB by calling the deleteCachedAsset method.
从 S3 删除资源
🌐 Deleting assets from S3
如果你从 deletedAssets 数组中的一个对象获得了 remoteFileKey,你可以使用以下代码将其从 S3 删除:
🌐 If you have a remoteFileKey from an object in the deletedAssets array, you can delete it from S3 using the following code:
Delete an asset from S3 - must be called from the backendimport {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);
你只需要清理 assetStatus 为 uploaded 的资源。
🌐 You only need to clear assets which have an assetStatus of uploaded.
从状态中移除
🌐 Removing from the state
一旦资源已从 S3 和 IndexedDB 成功删除,你可以通过调用 clearDeletedAsset() 方法将其从状态中移除。
🌐 Once an asset has been successfully deleted from S3 and IndexedDB, you can remove it from the state by calling the clearDeletedAsset() method.
另请参阅
🌐 See also