working
This commit is contained in:
27
app/sbin/api
27
app/sbin/api
@@ -35,7 +35,14 @@ def run_command(cmd: list[str]) -> str:
|
||||
"""Run a shell command and return stdout or raise HTTPException on error."""
|
||||
result = subprocess.run(cmd, capture_output=True, text=True)
|
||||
if result.returncode != 0:
|
||||
raise HTTPException(status_code=500, detail=result.stderr.strip() or "Unknown error")
|
||||
error_msg = (
|
||||
f"Command failed\n"
|
||||
f"Command: {' '.join(cmd)}\n"
|
||||
f"Return code: {result.returncode}\n"
|
||||
f"Stdout: {result.stdout.strip()}\n"
|
||||
f"Stderr: {result.stderr.strip() or 'None'}"
|
||||
)
|
||||
raise HTTPException(status_code=500, detail=error_msg)
|
||||
return result.stdout.strip()
|
||||
|
||||
|
||||
@@ -155,16 +162,18 @@ def nuke_container(request: UUIDRequest):
|
||||
|
||||
@app.post("/container/info", dependencies=[Depends(verify_api_key)])
|
||||
def info_container(request: Optional[UUIDRequest] = None):
|
||||
# Fields to select
|
||||
fields = [
|
||||
"ID", "UUID", "email", "expires", "tags", "env", "affiliate",
|
||||
"image", "history", "comment", "domains", "status", "created"
|
||||
]
|
||||
field_str = ", ".join(fields)
|
||||
|
||||
# Execute query
|
||||
if request:
|
||||
rows = execute_db(
|
||||
f"SELECT {field_str} FROM containers WHERE UUID=?",
|
||||
(request.UUID,),
|
||||
(str(request.UUID),),
|
||||
fetch=True
|
||||
)
|
||||
else:
|
||||
@@ -173,15 +182,21 @@ def info_container(request: Optional[UUIDRequest] = None):
|
||||
fetch=True
|
||||
)
|
||||
|
||||
# Map rows to dicts with field names
|
||||
containers = [dict(zip(fields, row)) for row in rows]
|
||||
# Map rows to dicts safely
|
||||
containers = []
|
||||
for row in rows:
|
||||
if isinstance(row, dict):
|
||||
# Already a dict (e.g., some DB wrappers)
|
||||
containers.append(row)
|
||||
else:
|
||||
# Tuple/list -> map with fields
|
||||
containers.append(dict(zip(fields, row)))
|
||||
|
||||
# Wrap in N8N JSON format
|
||||
# Wrap in n8n JSON format
|
||||
n8n_items = [{"json": container} for container in containers]
|
||||
|
||||
return n8n_items
|
||||
|
||||
|
||||
@app.post("/container/bump", dependencies=[Depends(verify_api_key)])
|
||||
def bump_container(request: UUIDRequest):
|
||||
today = datetime.utcnow().strftime("%Y-%m-%d")
|
||||
|
||||
Reference in New Issue
Block a user