Files

45 lines
1.7 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""图片资产列表 — list the image assets you have generated.
tripocli imgs --size 10
实测:`POST /v2/studio/image/image_assets` body `{page_num, page_size}`,
返回 `{assets:[{asset_id, input:{prompt, prompt_image:[{bucket,key,url}]}, ...}]}`。
"""
NAME = "imgs"
HELP = "列出我的图片资产(生成过的参考图)"
def add_arguments(parser):
parser.add_argument("--page", type=int, default=1, help="页码(默认 1)")
parser.add_argument("--size", type=int, default=8, help="每页数量(默认 8)")
parser.add_argument("--delete", help="删除指定的图片资产 asset_id(对应网页端垃圾桶按钮)")
def run(ctx):
args = ctx.args
if args.delete:
target_id = args.delete.strip()
body = {"items": [{"asset_id": target_id, "keys": []}]}
ctx.client.get_data("POST", "/v2/studio/image/batch_delete", body=body)
ctx.out.line(f"🗑️ 已成功删除图片资产: {target_id}")
return {"deleted": target_id}
data = ctx.client.get_data(
"POST", "/v2/studio/image/image_assets",
body={"page_num": args.page, "page_size": args.size},
) or {}
assets = data.get("assets") or []
def show():
for item in assets:
source = item.get("input") or {}
prompt = source.get("prompt_text") or source.get("prompt") or ""
ctx.out.line(f" {item.get('asset_id')} [{item.get('status', '')}] {prompt[:56]}")
pictures = ((item.get("output") or {}).get("data")) or source.get("prompt_image") or []
for picture in pictures[:2]:
ctx.out.line(f" {picture.get('url', '')[:100]}")
ctx.out.data({"assets": assets}, human=show)
return data