feat: require login for upload command
Upload now requires authentication and sends Bearer token. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
30
artdag.py
30
artdag.py
@@ -363,14 +363,28 @@ def import_file(filepath):
|
|||||||
@cli.command()
|
@cli.command()
|
||||||
@click.argument("filepath", type=click.Path(exists=True))
|
@click.argument("filepath", type=click.Path(exists=True))
|
||||||
def upload(filepath):
|
def upload(filepath):
|
||||||
"""Upload a file to cache (works with remote servers)."""
|
"""Upload a file to cache (works with remote servers). Requires login."""
|
||||||
with open(filepath, "rb") as f:
|
# Check auth
|
||||||
files = {"file": (Path(filepath).name, f)}
|
token_data = load_token()
|
||||||
resp = requests.post(f"{get_server()}/cache/upload", files=files)
|
if not token_data.get("access_token"):
|
||||||
resp.raise_for_status()
|
click.echo("Not logged in. Please run: artdag login <username>", err=True)
|
||||||
result = resp.json()
|
sys.exit(1)
|
||||||
click.echo(f"Uploaded: {result['content_hash']}")
|
|
||||||
click.echo(f"Size: {result['size']} bytes")
|
try:
|
||||||
|
with open(filepath, "rb") as f:
|
||||||
|
files = {"file": (Path(filepath).name, f)}
|
||||||
|
headers = {"Authorization": f"Bearer {token_data['access_token']}"}
|
||||||
|
resp = requests.post(f"{get_server()}/cache/upload", files=files, headers=headers)
|
||||||
|
if resp.status_code == 401:
|
||||||
|
click.echo("Authentication failed. Please login again.", err=True)
|
||||||
|
sys.exit(1)
|
||||||
|
resp.raise_for_status()
|
||||||
|
result = resp.json()
|
||||||
|
click.echo(f"Uploaded: {result['content_hash']}")
|
||||||
|
click.echo(f"Size: {result['size']} bytes")
|
||||||
|
except requests.RequestException as e:
|
||||||
|
click.echo(f"Upload failed: {e}", err=True)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
|
|||||||
Reference in New Issue
Block a user