创建项目,返回project_id Args: st: Session Token title: 项目标题 Returns: project_id (UUID)
(self, st: str, title: str)
| 1226 | # ========== 项目管理 (使用ST) ========== |
| 1227 | |
| 1228 | async def create_project(self, st: str, title: str) -> str: |
| 1229 | """创建项目,返回project_id |
| 1230 | |
| 1231 | Args: |
| 1232 | st: Session Token |
| 1233 | title: 项目标题 |
| 1234 | |
| 1235 | Returns: |
| 1236 | project_id (UUID) |
| 1237 | """ |
| 1238 | url = f"{self.labs_base_url}/trpc/project.createProject" |
| 1239 | json_data = { |
| 1240 | "json": { |
| 1241 | "projectTitle": title, |
| 1242 | "toolName": "PINHOLE" |
| 1243 | } |
| 1244 | } |
| 1245 | max_retries = config.flow_max_retries |
| 1246 | request_timeout = max(self._get_control_plane_timeout(), min(self.timeout, 15)) |
| 1247 | last_error: Optional[Exception] = None |
| 1248 | |
| 1249 | for retry_attempt in range(max_retries): |
| 1250 | try: |
| 1251 | result = await self._make_request( |
| 1252 | method="POST", |
| 1253 | url=url, |
| 1254 | json_data=json_data, |
| 1255 | use_st=True, |
| 1256 | st_token=st, |
| 1257 | timeout=request_timeout, |
| 1258 | ) |
| 1259 | project_result = ( |
| 1260 | result.get("result", {}) |
| 1261 | .get("data", {}) |
| 1262 | .get("json", {}) |
| 1263 | .get("result", {}) |
| 1264 | ) |
| 1265 | project_id = project_result.get("projectId") |
| 1266 | if not project_id: |
| 1267 | raise Exception("Invalid project.createProject response: missing projectId") |
| 1268 | return project_id |
| 1269 | except Exception as e: |
| 1270 | last_error = e |
| 1271 | retry_reason = "网络超时" if self._is_timeout_error(e) else self._get_retry_reason(str(e)) |
| 1272 | if retry_reason and retry_attempt < max_retries - 1: |
| 1273 | debug_logger.log_warning( |
| 1274 | f"[PROJECT] 创建项目失败,准备重试 ({retry_attempt + 2}/{max_retries}) " |
| 1275 | f"title={title!r}, reason={retry_reason}: {e}" |
| 1276 | ) |
| 1277 | await asyncio.sleep(1) |
| 1278 | continue |
| 1279 | raise |
| 1280 | |
| 1281 | if last_error is not None: |
| 1282 | raise last_error |
| 1283 | raise RuntimeError("创建项目失败") |
| 1284 | |
| 1285 | async def delete_project(self, st: str, project_id: str): |
no test coverage detected