MCPcopy Create free account
hub / github.com/ComfyWorkflows/ComfyUI-Launcher / import_project

Function import_project

server/server.py:197–261  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

195
196@app.route("/api/import_project", methods=["POST"])
197def import_project():
198 request_data = request.get_json()
199 name = request_data["name"]
200 import_json = request_data["import_json"]
201 resolved_missing_models = request_data["resolved_missing_models"]
202 skipping_model_validation = request_data["skipping_model_validation"]
203 port = request_data.get("port")
204 # skipping_model_validation = request_data.get("skipping_model_validation")
205
206 # set id to a folder friendly name of the project name (lowercase, no spaces, etc.)
207 id = slugify(name)
208
209 project_path = os.path.join(PROJECTS_DIR, id)
210 assert not os.path.exists(project_path), f"Project with id {id} already exists"
211
212 models_path = MODELS_DIR
213
214 if is_launcher_json_format(import_json):
215 print("Detected launcher json format")
216 launcher_json = import_json
217 else:
218 print("Detected workflow json format, converting to launcher json format")
219 #only resolve missing models for workflows w/ workflow json format
220 skip_model_validation = True if skipping_model_validation else False
221 if len(resolved_missing_models) > 0:
222 for model in resolved_missing_models:
223 if (model["filename"] is None or model["node_type"] is None or model["dest_relative_path"] is None):
224 return jsonify({ "success": False, "error": f"one of the resolved models has an empty filename, node type, or destination path. please try again." })
225 elif (model["source"]["url"] is not None and model["source"]["file_id"] is None):
226 is_valid = check_url_structure(model["source"]["url"])
227 if (is_valid is False):
228 return jsonify({ "success": False, "error": f"the url f{model['source']['url']} is invalid. please make sure it is a link to a model file on huggingface or a civitai model." })
229 elif (model["source"]["file_id"] is None and model["source"]["url"] is None):
230 return jsonify({ "success": False, "error": f"you didn't select one of the suggestions (or import a url) for the following missing file: {model['filename']}" })
231 skip_model_validation = True
232
233 res = get_launcher_json_for_workflow_json(import_json, resolved_missing_models, skip_model_validation)
234 if (res["success"] and res["launcher_json"]):
235 launcher_json = res["launcher_json"]
236 elif (res["success"] is False and res["error"] == "MISSING_MODELS" and len(res["missing_models"]) > 0):
237 return jsonify({ "success": False, "missing_models": res["missing_models"], "error": res["error"] })
238 else:
239 print(f"something went wrong when fetching res from get_launcher_json_for_workflow_json: {res}")
240 return jsonify({ "success": False, "error": res["error"] })
241
242 print(f"Creating project with id {id} and name {name} from imported json")
243
244 # set the project's first status message
245 assert not os.path.exists(
246 project_path
247 ), f"Project folder already exists: {project_path}"
248 os.makedirs(project_path)
249 set_launcher_state_data(
250 project_path,
251 {"id":id,"name":name, "status_message": "Downloading ComfyUI...", "state": "download_comfyui"},
252 )
253
254 result = create_comfyui_project.delay(

Callers

nothing calls this directly

Calls 5

slugifyFunction · 0.90
is_launcher_json_formatFunction · 0.90
check_url_structureFunction · 0.90
set_launcher_state_dataFunction · 0.90

Tested by

no test coverage detected