-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdelete.ts
More file actions
61 lines (54 loc) · 1.78 KB
/
delete.ts
File metadata and controls
61 lines (54 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { Command } from '@cliffy/command';
import { handleCommandError } from '@/lib/errors.ts';
import { createAuthenticatedMuxClient } from '@/lib/mux.ts';
import { confirmPrompt } from '@/lib/prompt.ts';
interface DeleteOptions {
force?: boolean;
json?: boolean;
}
export const deleteCommand = new Command()
.description('Delete a static rendition from an asset')
.arguments('<asset-id:string> <rendition-id:string>')
.option('-f, --force', 'Skip confirmation prompt')
.option('--json', 'Output JSON instead of pretty format')
.action(
async (options: DeleteOptions, assetId: string, renditionId: string) => {
try {
const mux = await createAuthenticatedMuxClient();
if (!options.force) {
if (options.json) {
throw new Error(
'Deletion requires --force flag when using --json output',
);
}
const confirmed = await confirmPrompt({
message: `Are you sure you want to delete static rendition ${renditionId}?`,
default: false,
});
if (!confirmed) {
console.log('Deletion cancelled.');
return;
}
}
await mux.video.assets.deleteStaticRendition(assetId, renditionId);
if (options.json) {
console.log(
JSON.stringify(
{
success: true,
message: `Static rendition ${renditionId} deleted from asset ${assetId}`,
},
null,
2,
),
);
} else {
console.log(
`Static rendition ${renditionId} deleted from asset ${assetId}`,
);
}
} catch (error) {
await handleCommandError(error, 'assets', 'delete', options);
}
},
);