diff --git a/README.md b/README.md index 8c138a5..f561e50 100644 --- a/README.md +++ b/README.md @@ -111,11 +111,12 @@ listenhub openapi subscription -j ### Images -| Command | Description | -| -------------------------- | -------------------- | -| `listenhub image create` | Generate an AI image | -| `listenhub image list` | List AI images | -| `listenhub image get ` | Get image details | +| Command | Description | +| -------------------------------- | ---------------------------- | +| `listenhub image create` | Generate an AI image | +| `listenhub image list` | List AI images | +| `listenhub image get ` | Get image details | +| `listenhub image delete ` | Delete one or more AI images | ### Video Generation diff --git a/README.zh-CN.md b/README.zh-CN.md index 9b8543f..1d83c73 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -111,11 +111,12 @@ listenhub openapi subscription -j ### 图片 -| 命令 | 说明 | -| -------------------------- | ------------ | -| `listenhub image create` | AI 生图 | -| `listenhub image list` | 列出图片 | -| `listenhub image get ` | 查看图片详情 | +| 命令 | 说明 | +| -------------------------------- | ------------------ | +| `listenhub image create` | AI 生图 | +| `listenhub image list` | 列出图片 | +| `listenhub image get ` | 查看图片详情 | +| `listenhub image delete ` | 删除一个或多个图片 | ### 视频生成 diff --git a/package.json b/package.json index 2319e23..1e799c6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@marswave/listenhub-cli", - "version": "0.0.10", + "version": "0.0.11", "description": "Command-line interface for ListenHub", "license": "MIT", "repository": "marswaveai/listenhub-cli", @@ -25,7 +25,7 @@ "prepublishOnly": "pnpm run build" }, "dependencies": { - "@marswave/listenhub-sdk": "^0.0.11", + "@marswave/listenhub-sdk": "^0.0.13", "commander": "^14.0.3", "open": "^10.0.0", "ora": "^8.0.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d175b9d..0da6b4c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,8 +9,8 @@ importers: .: dependencies: '@marswave/listenhub-sdk': - specifier: ^0.0.11 - version: 0.0.11 + specifier: ^0.0.13 + version: 0.0.13 commander: specifier: ^14.0.3 version: 14.0.3 @@ -57,8 +57,8 @@ packages: '@jridgewell/sourcemap-codec@1.5.5': resolution: {integrity: sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==} - '@marswave/listenhub-sdk@0.0.11': - resolution: {integrity: sha512-DpRRbCMcjT56qPmCX3ndNpjS8IY7PkqfTT9B6iSZvhVvWwp2VWRxtI5VFIP2aLjKCjJVXC17el2j+xHujWngPw==} + '@marswave/listenhub-sdk@0.0.13': + resolution: {integrity: sha512-70DDiyk+z8onExIOimGq5SzPBz/P5KZlBXZeliFRoiZS13L89dwKPiRrp2bYvY+2xjxspbgT+9HWYFOjhbFvMQ==} engines: {node: '>=20'} '@napi-rs/wasm-runtime@1.1.4': @@ -1118,7 +1118,7 @@ snapshots: '@jridgewell/sourcemap-codec@1.5.5': {} - '@marswave/listenhub-sdk@0.0.11': + '@marswave/listenhub-sdk@0.0.13': dependencies: ky: 1.14.3 diff --git a/source/image/_cli.ts b/source/image/_cli.ts index e7ffbd9..d1809c3 100644 --- a/source/image/_cli.ts +++ b/source/image/_cli.ts @@ -5,6 +5,7 @@ import { type ImageCreateOptions, type ImageListOptions, createImage, + deleteImages, getImage, listImages, } from './image.js'; @@ -75,4 +76,17 @@ export function register(program: Command) { handleError(error, options.json); } }); + + cmd + .command('delete ') + .description('Delete one or more AI images') + .option('-j, --json', 'Output JSON', false) + .action(async (ids: string[], options: {json: boolean}) => { + try { + const client = await getClient(); + await deleteImages(client, ids, options.json); + } catch (error) { + handleError(error, options.json); + } + }); } diff --git a/source/image/image.ts b/source/image/image.ts index aa85ad5..24c0844 100644 --- a/source/image/image.ts +++ b/source/image/image.ts @@ -122,3 +122,17 @@ export async function getImage( ['Created:', new Date(item.createdAt).toISOString()], ]); } + +export async function deleteImages( + client: ListenHubClient, + ids: string[], + json: boolean, +): Promise { + await client.deleteAIImages({ids}); + + if (json) { + printJson({deleted: ids}); + } else { + console.log(`✓ Deleted ${String(ids.length)} image(s)`); + } +}