feat: add savefig helper for chat-artifacts S3 upload

This commit is contained in:
2026-05-21 07:31:05 +02:00
committed by root
parent 345fd09599
commit 8a3d94bfdc
+25
View File
@@ -60,6 +60,31 @@ TOMLEND
echo "$name ready at $dir"
}
savefig() {
local file="$1"
local key="${2:-$(date +%Y-%m-%d)/$(basename "$file")}"
[ -z "$file" ] || [ ! -f "$file" ] && { echo "usage: savefig <file> [key]"; return 1; }
FILE="$file" KEY="$key" uv run --with boto3 --quiet - <<'PYEOF'
import boto3, os, sys, mimetypes
from botocore.config import Config
path = os.environ["FILE"]
key = os.environ["KEY"]
ep = os.environ.get("CHAT_ARTIFACTS_ENDPOINT", "https://s3.nuclide.systems")
acc = os.environ.get("CHAT_ARTIFACTS_ACCESS_KEY", "")
sec = os.environ.get("CHAT_ARTIFACTS_SECRET_KEY", "")
bkt = os.environ.get("CHAT_ARTIFACTS_BUCKET", "chat-artifacts")
if not acc:
print("CHAT_ARTIFACTS_ACCESS_KEY not set", file=sys.stderr); sys.exit(1)
ct, _ = mimetypes.guess_type(path)
s3 = boto3.client("s3", endpoint_url=ep, aws_access_key_id=acc,
aws_secret_access_key=sec, region_name="garage",
config=Config(signature_version="s3v4"))
with open(path, "rb") as f:
s3.put_object(Bucket=bkt, Key=key, Body=f.read(), ContentType=ct or "application/octet-stream")
print(f"https://chat-artifacts.s3.nuclide.systems/{key}")
PYEOF
}
# Docker — detach from a running attach with Ctrl+P, Ctrl+Q
alias dps='docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Status}}"'
alias da='docker attach'