feat: add --publish and --republish options to meta command
- Add --publish <name> to publish cache items to L2 with asset name - Add --publish-type to specify asset type (image, video) - Add --republish to sync metadata updates to already-published items - Requires origin to be set before publishing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
54
artdag.py
54
artdag.py
@@ -445,11 +445,17 @@ def publish(run_id, output_name):
|
||||
@click.option("--folder", "-f", help="Set folder path")
|
||||
@click.option("--add-collection", help="Add to collection")
|
||||
@click.option("--remove-collection", help="Remove from collection")
|
||||
def meta(content_hash, origin, origin_url, origin_note, description, tags, folder, add_collection, remove_collection):
|
||||
@click.option("--publish", "publish_name", help="Publish to L2 with given asset name")
|
||||
@click.option("--publish-type", default="image", help="Asset type for publishing (image, video)")
|
||||
@click.option("--republish", is_flag=True, help="Re-sync with L2 after metadata changes")
|
||||
def meta(content_hash, origin, origin_url, origin_note, description, tags, folder, add_collection, remove_collection, publish_name, publish_type, republish):
|
||||
"""View or update metadata for a cached item.
|
||||
|
||||
With no options, displays current metadata.
|
||||
With options, updates the specified fields.
|
||||
|
||||
Use --publish <name> to publish to L2 (requires origin to be set).
|
||||
Use --republish to sync metadata changes to L2.
|
||||
"""
|
||||
token_data = load_token()
|
||||
if not token_data.get("access_token"):
|
||||
@@ -458,6 +464,52 @@ def meta(content_hash, origin, origin_url, origin_note, description, tags, folde
|
||||
|
||||
headers = {"Authorization": f"Bearer {token_data['access_token']}"}
|
||||
|
||||
# Handle publish action
|
||||
if publish_name:
|
||||
try:
|
||||
resp = requests.post(
|
||||
f"{get_server()}/cache/{content_hash}/publish",
|
||||
json={"asset_name": publish_name, "asset_type": publish_type},
|
||||
headers=headers
|
||||
)
|
||||
if resp.status_code == 400:
|
||||
click.echo(f"Error: {resp.json().get('detail', 'Bad request')}", err=True)
|
||||
sys.exit(1)
|
||||
if resp.status_code == 404:
|
||||
click.echo(f"Content not found: {content_hash}", err=True)
|
||||
sys.exit(1)
|
||||
resp.raise_for_status()
|
||||
result = resp.json()
|
||||
click.echo(f"Published to L2!")
|
||||
click.echo(f"Asset name: {result['asset_name']}")
|
||||
click.echo(f"Activity: {result['l2_result']['activity']['activity_id']}")
|
||||
except requests.RequestException as e:
|
||||
click.echo(f"Failed to publish: {e}", err=True)
|
||||
sys.exit(1)
|
||||
return
|
||||
|
||||
# Handle republish action
|
||||
if republish:
|
||||
try:
|
||||
resp = requests.patch(
|
||||
f"{get_server()}/cache/{content_hash}/republish",
|
||||
headers=headers
|
||||
)
|
||||
if resp.status_code == 400:
|
||||
click.echo(f"Error: {resp.json().get('detail', 'Bad request')}", err=True)
|
||||
sys.exit(1)
|
||||
if resp.status_code == 404:
|
||||
click.echo(f"Content not found: {content_hash}", err=True)
|
||||
sys.exit(1)
|
||||
resp.raise_for_status()
|
||||
result = resp.json()
|
||||
click.echo(f"Re-synced with L2!")
|
||||
click.echo(f"Asset name: {result['asset_name']}")
|
||||
except requests.RequestException as e:
|
||||
click.echo(f"Failed to republish: {e}", err=True)
|
||||
sys.exit(1)
|
||||
return
|
||||
|
||||
# If no update options, just display current metadata
|
||||
has_updates = any([origin, origin_url, origin_note, description, tags, folder, add_collection, remove_collection])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user