()
| 141 | |
| 142 | @app.route("/api/create_project", methods=["POST"]) |
| 143 | def create_project(): |
| 144 | request_data = request.get_json() |
| 145 | name = request_data["name"] |
| 146 | template_id = request_data.get("template_id", "empty") |
| 147 | port = request_data.get("port") |
| 148 | |
| 149 | # set id to a folder friendly name of the project name (lowercase, no spaces, etc.) |
| 150 | id = slugify(name) |
| 151 | |
| 152 | project_path = os.path.join(PROJECTS_DIR, id) |
| 153 | assert not os.path.exists(project_path), f"Project with id {id} already exists" |
| 154 | |
| 155 | models_path = MODELS_DIR |
| 156 | |
| 157 | launcher_json = None |
| 158 | template_folder = os.path.join(TEMPLATES_DIR, template_id) |
| 159 | template_launcher_json_fp = os.path.join(template_folder, "launcher.json") |
| 160 | if os.path.exists(template_launcher_json_fp): |
| 161 | with open(template_launcher_json_fp, "r") as f: |
| 162 | launcher_json = json.load(f) |
| 163 | else: |
| 164 | template_workflow_json_fp = os.path.join(template_folder, "workflow.json") |
| 165 | if os.path.exists(template_workflow_json_fp): |
| 166 | with open(template_workflow_json_fp, "r") as f: |
| 167 | template_workflow_json = json.load(f) |
| 168 | res = get_launcher_json_for_workflow_json(template_workflow_json, resolved_missing_models=[], skip_model_validation=True) |
| 169 | if (res["success"] and res["launcher_json"]): |
| 170 | launcher_json = res["launcher_json"] |
| 171 | else: |
| 172 | return jsonify({ "success": False, "missing_models": [], "error": res["error"] }) |
| 173 | |
| 174 | print(f"Creating project with id {id} and name {name} from template {template_id}") |
| 175 | |
| 176 | # set the project's first status message |
| 177 | assert not os.path.exists( |
| 178 | project_path |
| 179 | ), f"Project folder already exists: {project_path}" |
| 180 | os.makedirs(project_path) |
| 181 | set_launcher_state_data( |
| 182 | project_path, |
| 183 | {"id":id,"name":name, "status_message": "Downloading ComfyUI...", "state": "download_comfyui"}, |
| 184 | ) |
| 185 | |
| 186 | result = create_comfyui_project.delay( |
| 187 | project_path, models_path, id=id, name=name, launcher_json=launcher_json, port=port, create_project_folder=False |
| 188 | ) |
| 189 | |
| 190 | with open(os.path.join(project_path, "setup_task_id.txt"), "w") as f: |
| 191 | f.write(result.id) |
| 192 | |
| 193 | return jsonify({"success": True, "id": id}) |
| 194 | |
| 195 | |
| 196 | @app.route("/api/import_project", methods=["POST"]) |
nothing calls this directly
no test coverage detected