implement instance editing capability and move user creation to a modal
This commit is contained in:
parent
b185c7a70b
commit
2e160cdd14
3 changed files with 123 additions and 35 deletions
30
main.py
30
main.py
|
|
@ -7,6 +7,7 @@ import httpx
|
|||
import base64
|
||||
import secrets
|
||||
import urllib.parse
|
||||
from typing import Optional
|
||||
from fastapi import FastAPI, Request, Depends, HTTPException
|
||||
from fastapi.responses import Response, FileResponse, JSONResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
|
@ -328,6 +329,35 @@ def create_instance(inst: InstanceCreate, request: Request):
|
|||
conn.close()
|
||||
return {"status": "ok"}
|
||||
|
||||
@app.put("/api/instances/{id}", dependencies=[Depends(is_authenticated)])
|
||||
def update_instance(id: int, inst: InstanceUpdate, request: Request):
|
||||
user_id = request.session.get("user_id")
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
c = conn.cursor()
|
||||
|
||||
# Verify ownership
|
||||
c.execute('SELECT id FROM instances WHERE id=? AND user_id=?', (id, user_id))
|
||||
if not c.fetchone():
|
||||
conn.close()
|
||||
raise HTTPException(status_code=404, detail="Instance not found")
|
||||
|
||||
if inst.secret:
|
||||
cleaned = clean_secret(inst.secret)
|
||||
encrypted = fernet.encrypt(cleaned.encode()).decode()
|
||||
c.execute('''
|
||||
UPDATE instances SET name=?, ip=?, port=?, encrypted_secret=?
|
||||
WHERE id=? AND user_id=?
|
||||
''', (inst.name, inst.ip, inst.port, encrypted, id, user_id))
|
||||
else:
|
||||
c.execute('''
|
||||
UPDATE instances SET name=?, ip=?, port=?
|
||||
WHERE id=? AND user_id=?
|
||||
''', (inst.name, inst.ip, inst.port, id, user_id))
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return {"status": "ok"}
|
||||
|
||||
@app.get("/api/config", dependencies=[Depends(is_authenticated)])
|
||||
def get_config():
|
||||
return {"firewall_host_ip": FIREWALL_HOST_IP}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue