Add s2-storage skill with reusable upload script
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
eb8da9611e
commit
5dcfd0413d
3 changed files with 92 additions and 2 deletions
55
s2-storage/scripts/s2_upload.py
Normal file
55
s2-storage/scripts/s2_upload.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
#!/usr/bin/env python3
|
||||
# /// script
|
||||
# requires-python = ">=3.11"
|
||||
# dependencies = ["requests"]
|
||||
# ///
|
||||
"""Upload a file to S2 storage at s2.connorrhodes.com.
|
||||
|
||||
Usage:
|
||||
s2_upload.py <file_path> [--delete]
|
||||
|
||||
Options:
|
||||
--delete Delete the local file after a successful upload.
|
||||
|
||||
Output:
|
||||
Prints the S2 URL on stdout.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import requests
|
||||
|
||||
API_KEY = "LT6CXiLT5cEApfqtThz17bENr6OLP804FepOMqa1tZkfTGXiiCcSFlupl6gaYeX"
|
||||
ENDPOINT = "https://api.connorrhodes.com/agent/s2_upload"
|
||||
|
||||
|
||||
def main():
|
||||
args = sys.argv[1:]
|
||||
if not args or args[0] in ("-h", "--help"):
|
||||
print(__doc__)
|
||||
sys.exit(0 if args else 1)
|
||||
|
||||
file_path = args[0]
|
||||
delete_after = "--delete" in args
|
||||
|
||||
if not os.path.isfile(file_path):
|
||||
print(f"Error: file not found: {file_path}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
with open(file_path, "rb") as f:
|
||||
resp = requests.post(
|
||||
ENDPOINT,
|
||||
headers={"x-api-key": API_KEY},
|
||||
files={"file": (os.path.basename(file_path), f)},
|
||||
)
|
||||
|
||||
resp.raise_for_status()
|
||||
url = resp.json() if isinstance(resp.json(), str) else resp.text.strip().strip('"')
|
||||
print(url)
|
||||
|
||||
if delete_after:
|
||||
os.remove(file_path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue