feat: 新增 /download slash 命令——实时打包项目tgz并生成下载链接

This commit is contained in:
ymq 2026-08-18 16:03:59 +08:00
parent 31ba001482
commit 8108d7d902

View File

@ -1602,11 +1602,46 @@ async def _slash_diagnose(args, ctx):
return r or "无诊断数据"
async def _slash_download(args, ctx):
"""下载项目实时 tgz打包 + 生成下载链接,弹窗带下载按钮。"""
ex = ctx.get("executor")
base = (ctx.get("base_url") or "").rstrip("/")
pid = ctx.get("project_id") or ""
if not pid:
return {"widgettype": "Message", "options": {"title": "错误", "message": "请先切换到项目"}}
# 实时打包 tgz复用 backup_project
r = await ex._execute_ability_tool("backup_project", {"project_id": pid}) if ex else None
if not r or r.startswith("ERROR"):
return {"widgettype": "Message", "options": {"title": "错误", "message": r or "打包失败"}}
# r 格式:"OK: /d/pipeline/workspaces/0/_archive/xxx.tgz"
tgz_path = (r[4:].strip() if r.startswith("OK: ") else "").strip()
if not tgz_path:
return {"widgettype": "Message", "options": {"title": "错误", "message": "打包结果异常: " + r}}
from urllib.parse import quote
dl_url = f"{base}/pipeline-sdlc/api/download_project.dspy?path={quote(tgz_path)}"
fname = tgz_path.split('/')[-1]
return {
"widgettype": "PopupWindow",
"options": {"title": "项目备份下载", "cwidth": 60, "cheight": 12, "auto_open": True},
"subwidgets": [
{"widgettype": "Text", "options": {"text": f"项目备份已生成:{fname}", "cfontsize": 1.0}},
{"widgettype": "Button", "options": {"label": "点击下载 tgz", "css": "filler"},
"binds": [{"wid": "self", "event": "click", "actiontype": "script", "target": "self",
"script": f"window.location.href='{dl_url}';"}]},
],
}
def register_sdlc_slash_commands():
for cmd in [
SlashCommand("tasks", "列出任务(可按角色筛选)", _slash_tasks, "pipeline", "sdlc_general"),
SlashCommand("task", "任务树+输入输出(弹窗)", _slash_task, "pipeline", "sdlc_general"),
SlashCommand("diagnose", "诊断项目状态", _slash_diagnose, "pipeline", "sdlc_general"),
SlashCommand("download", "下载项目tgz备份生成下载链接", _slash_download, "pipeline", "sdlc_general"),
]:
register_slash_command(cmd)