Delete Preview
This section details how to remove preview metadata associated with your objects in DID Spaces using the DeletePreviewObjectCommand
. This command is useful for cleaning up preview data, such as .meta/preview.yml
files, when they are no longer needed.
For creating or updating preview metadata, see Put Preview. To retrieve existing preview metadata, see Get Preview.
How to Delete Preview Metadata#
To delete preview metadata, you will use the DeletePreviewObjectCommand
. This command requires the key
of the folder whose preview metadata you wish to remove. The SDK will automatically target the .meta/preview.yml
file within that folder.
Parameters#
Name | Type | Description |
---|---|---|
|
| The path to the folder whose preview metadata you want to delete. This path must end with a |
Returns#
Name | Type | Description |
---|---|---|
|
| The HTTP status code of the operation. A |
|
| A descriptive message about the operation's status. |
|
| This command does not return any specific data upon successful deletion. |
Example#
import { SpaceClient, DeletePreviewObjectCommand } from '@did-spaces/client';
import { Wallet } from '@ocap/wallet';
async function deleteObjectPreview(folderKey) {
try {
// Initialize SpaceClient
const client = new SpaceClient({
endpoint: 'YOUR_DID_SPACE_ENDPOINT', // e.g., 'https://did.space'
wallet: new Wallet('YOUR_MNEMONIC'), // Replace with your DID Wallet mnemonic
});
// Create a DeletePreviewObjectCommand instance
const command = new DeletePreviewObjectCommand({
key: folderKey, // e.g., 'my-app/public/'
});
// Send the command
const response = await client.send(command);
if (response.statusCode === 200) {
console.log(`Successfully deleted preview for folder: ${folderKey}`);
} else {
console.error(`Failed to delete preview: ${response.statusMessage} (Code: ${response.statusCode})`);
}
} catch (error) {
console.error(`Error deleting preview: ${error.message}`);
}
}
// Example usage:
deleteObjectPreview('my-documents/project-alpha/');
This example demonstrates how to delete the preview metadata associated with the my-documents/project-alpha/
folder. Ensure the folderKey
ends with a /
.
Conclusion#
You have learned how to use the DeletePreviewObjectCommand
to remove unwanted preview metadata from your DID Spaces. This helps in maintaining a clean and organized space.
To continue exploring preview operations, you might want to review Put Preview for adding new previews or Get Preview for retrieving existing ones. You can also return to the Preview Commands Overview.