feat: 完成项目助手与监控演示并修复聊天及云部署配置
This commit is contained in:
@@ -228,12 +228,12 @@ class RunInput(BaseModel):
|
||||
project_id: str = Field(min_length=1,max_length=120)
|
||||
period: str | None = Field(default=None,max_length=10)
|
||||
|
||||
def query_card(card, connection, project_id):
|
||||
def query_card(card, connection, project_id, demo_samples=None, exact_decimals=False):
|
||||
if connection.get("type") != "demo":
|
||||
try: return execute(connection,card.get("sql",""),project_id)
|
||||
try: return execute(connection,card.get("sql",""),project_id, exact_decimals=exact_decimals)
|
||||
except ImportError: raise ValueError("数据库驱动未安装,请安装 backend/requirements.txt 中的依赖")
|
||||
with closing(sqlite3.connect(":memory:")) as conn:
|
||||
for table, rows in SAMPLES.items():
|
||||
for table, rows in (SAMPLES if demo_samples is None else demo_samples).items():
|
||||
keys=list(rows[0])
|
||||
conn.execute(f"CREATE TABLE {table} ({','.join(keys)})")
|
||||
conn.executemany(f"INSERT INTO {table} VALUES ({','.join('?' for _ in keys)})", [tuple(r[k] for k in keys) for r in rows])
|
||||
@@ -254,6 +254,7 @@ def query_card(card, connection, project_id):
|
||||
|
||||
@router.post("/cards/{card_id}/test")
|
||||
def test_card(card_id:str, payload:RunInput,request:Request):
|
||||
check_project(request,payload.project_id)
|
||||
with _db() as db:
|
||||
card=next((x for x in _all(db,"cards") if x["id"]==card_id),None)
|
||||
if not card: raise HTTPException(404,"数据卡不存在")
|
||||
@@ -272,7 +273,7 @@ def test_card(card_id:str, payload:RunInput,request:Request):
|
||||
def history(request:Request):
|
||||
user=request.state.identity
|
||||
with _db() as db: results=[json.loads(r[0]) for r in db.execute("SELECT body FROM runs ORDER BY rowid DESC")]
|
||||
results=[r for r in results if user["role"]!="manager" or "*" in user.get("projects",[]) or r["project_id"] in user.get("projects",[])]
|
||||
results=[r for r in results if "*" in user.get("projects",[]) or r["project_id"] in user.get("projects",[])]
|
||||
return [visible_result(r,user) for r in results[:30]]
|
||||
|
||||
class ReviewInput(BaseModel):
|
||||
|
||||
Reference in New Issue
Block a user