feat: '我的' tab - user content management with update/delete
This commit is contained in:
@@ -705,3 +705,41 @@ async def api_market_install_scene(id: str = "", filename: str = ""):
|
||||
return {"ok": ok, "missing_dashboards": missing}
|
||||
except Exception as e:
|
||||
return {"ok": False, "error": str(e)}
|
||||
|
||||
|
||||
@router.get("/market/mine")
|
||||
async def api_market_mine(token: str = ""):
|
||||
import httpx
|
||||
cfg = get_config()
|
||||
url = cfg.get("market_url", "http://127.0.0.1:5301")
|
||||
result = {"dashboards": [], "scenes": []}
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=10) as client:
|
||||
r = await client.get(f"{url}/api/collections/dashboards/records?sort=-created&perPage=100",
|
||||
headers={"Authorization": f"Bearer {token}"})
|
||||
result["dashboards"] = r.json().get("items", [])
|
||||
r = await client.get(f"{url}/api/collections/scenes/records?sort=-created&perPage=100",
|
||||
headers={"Authorization": f"Bearer {token}"})
|
||||
result["scenes"] = r.json().get("items", [])
|
||||
except Exception:
|
||||
pass
|
||||
return result
|
||||
|
||||
|
||||
@router.post("/market/delete")
|
||||
async def api_market_delete(data: dict):
|
||||
import httpx
|
||||
cfg = get_config()
|
||||
url = cfg.get("market_url", "http://127.0.0.1:5301")
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=10) as client:
|
||||
collection = data.get("collection", "dashboards")
|
||||
record_id = data.get("id", "")
|
||||
token = data.get("token", "")
|
||||
resp = await client.delete(
|
||||
f"{url}/api/collections/{collection}/records/{record_id}",
|
||||
headers={"Authorization": f"Bearer {token}"}
|
||||
)
|
||||
return {"ok": resp.status_code < 400}
|
||||
except Exception as e:
|
||||
return {"ok": False, "error": str(e)}
|
||||
|
||||
Reference in New Issue
Block a user