Download api/routes/projects.py from lhc-lab/AI-Colab: direct link, hf CLI and curl.
- Browser
- Download file 4 kB
-
https://huggingface.co/datasets/lhc-lab/AI-Colab/resolve/main/api/routes/projects.py
- Command line
-
hf download hf://datasets/lhc-lab/AI-Colab/api/routes/projects.py
-
curl -L -o projects.py https://huggingface.co/datasets/lhc-lab/AI-Colab/resolve/main/api/routes/projects.py
4 kB
| """ | |
| API endpoints для управления проектами. | |
| """ | |
| from quart import Blueprint, request, jsonify | |
| from core.project_manager import ProjectManager | |
| projects_bp = Blueprint('projects', __name__) | |
| project_manager = ProjectManager() | |
| async def create_project(): | |
| """Создает новый проект из шаблона.""" | |
| try: | |
| data = await request.get_json() | |
| name = data.get('name', 'Новый проект') | |
| template = data.get('template', 'debug') | |
| description = data.get('description') | |
| result = await project_manager.create_project( | |
| name=name, | |
| template=template, | |
| description=description | |
| ) | |
| # Обновляем общее состояние | |
| from core.shared_state import shared_state | |
| shared_state.set("current_project_path", result["project_path"]) | |
| # Уведомляем другие процессы | |
| from core.multi_process_sync import multi_process_sync | |
| multi_process_sync.notify_state_change("project_created", {"project_path": result["project_path"]}) | |
| return jsonify({ | |
| "success": True, | |
| "project_path": result["project_path"], | |
| "project_id": result["project_id"], | |
| "project_info": result["project_info"] | |
| }), 201 | |
| except Exception as e: | |
| return jsonify({ | |
| "success": False, | |
| "error": str(e) | |
| }), 400 | |
| async def list_projects(): | |
| """Возвращает список всех проектов.""" | |
| try: | |
| projects = await project_manager.list_projects() | |
| return jsonify({ | |
| "success": True, | |
| "projects": projects | |
| }) | |
| except Exception as e: | |
| return jsonify({ | |
| "success": False, | |
| "error": str(e) | |
| }), 500 | |
| async def open_project(): | |
| """Открывает существующий проект.""" | |
| try: | |
| data = await request.get_json() | |
| path = data.get('path') | |
| if not path: | |
| return jsonify({ | |
| "success": False, | |
| "error": "Path is required" | |
| }), 400 | |
| result = await project_manager.open_project(path) | |
| # Обновляем общее состояние для всех воркеров | |
| from core.shared_state import shared_state | |
| shared_state.set("current_project_path", path) | |
| # Уведомляем другие процессы об изменении текущего проекта | |
| from core.multi_process_sync import multi_process_sync | |
| multi_process_sync.notify_state_change("project_opened", {"project_path": path}) | |
| return jsonify({ | |
| "success": True, | |
| **result | |
| }) | |
| except Exception as e: | |
| return jsonify({ | |
| "success": False, | |
| "error": str(e) | |
| }), 400 | |
| async def save_project_as(): | |
| """Сохраняет проект под новым именем.""" | |
| try: | |
| data = await request.get_json() | |
| current_path = data.get('current_path') | |
| new_name = data.get('new_name') | |
| if not current_path or not new_name: | |
| return jsonify({ | |
| "success": False, | |
| "error": "Both current_path and new_name are required" | |
| }), 400 | |
| result = await project_manager.save_project_as(current_path, new_name) | |
| return jsonify({ | |
| "success": True, | |
| **result | |
| }) | |
| except Exception as e: | |
| return jsonify({ | |
| "success": False, | |
| "error": str(e) | |
| }), 400 | |