pref: optimize parameter transmission

This commit is contained in:
hayden
2024-11-11 12:08:01 +08:00
parent dfae915b77
commit 254ad8c597
3 changed files with 23 additions and 23 deletions

View File

@@ -99,7 +99,8 @@ async def create_model(request):
""" """
post = await request.post() post = await request.post()
try: try:
task_id = await services.create_model_download_task(post, request) task_data = dict(post)
task_id = await services.create_model_download_task(task_data, request)
return web.json_response({"success": True, "data": {"taskId": task_id}}) return web.json_response({"success": True, "data": {"taskId": task_id}})
except Exception as e: except Exception as e:
error_msg = f"Create model download task failed: {str(e)}" error_msg = f"Create model download task failed: {str(e)}"
@@ -163,7 +164,8 @@ async def update_model(request):
model_path = utils.get_valid_full_path(model_type, index, filename) model_path = utils.get_valid_full_path(model_type, index, filename)
if model_path is None: if model_path is None:
raise RuntimeError(f"File {filename} not found") raise RuntimeError(f"File {filename} not found")
services.update_model(model_path, post) model_data = dict(post)
services.update_model(model_path, model_data)
return web.json_response({"success": True}) return web.json_response({"success": True})
except Exception as e: except Exception as e:
error_msg = f"Update model failed: {str(e)}" error_msg = f"Update model failed: {str(e)}"

View File

@@ -111,13 +111,13 @@ async def scan_model_download_task_list():
return utils.unpack_dataclass(task_list) return utils.unpack_dataclass(task_list)
async def create_model_download_task(post: dict, request): async def create_model_download_task(task_data: dict, request):
""" """
Creates a download task for the given post. Creates a download task for the given post.
""" """
model_type = post.get("type", None) model_type = task_data.get("type", None)
path_index = int(post.get("pathIndex", None)) path_index = int(task_data.get("pathIndex", None))
fullname = post.get("fullname", None) fullname = task_data.get("fullname", None)
model_path = utils.get_full_path(model_type, path_index, fullname) model_path = utils.get_full_path(model_type, path_index, fullname)
# Check if the model path is valid # Check if the model path is valid
@@ -132,16 +132,16 @@ async def create_model_download_task(post: dict, request):
raise RuntimeError(f"Task {task_id} already exists") raise RuntimeError(f"Task {task_id} already exists")
try: try:
previewFile = post.pop("previewFile", None) previewFile = task_data.pop("previewFile", None)
utils.save_model_preview_image(task_path, previewFile) utils.save_model_preview_image(task_path, previewFile)
set_task_content(task_id, post) set_task_content(task_id, task_data)
task_status = TaskStatus( task_status = TaskStatus(
taskId=task_id, taskId=task_id,
type=model_type, type=model_type,
fullname=fullname, fullname=fullname,
preview=utils.get_model_preview_name(task_path), preview=utils.get_model_preview_name(task_path),
platform=post.get("downloadPlatform", None), platform=task_data.get("downloadPlatform", None),
totalSize=float(post.get("sizeBytes", 0)), totalSize=float(task_data.get("sizeBytes", 0)),
) )
download_model_task_status[task_id] = task_status download_model_task_status[task_id] = task_status
await utils.send_json("create_download_task", task_status) await utils.send_json("create_download_task", task_status)

View File

@@ -2,7 +2,6 @@ import os
import folder_paths import folder_paths
from multidict import MultiDictProxy
from . import config from . import config
from . import utils from . import utils
from . import download from . import download
@@ -75,20 +74,20 @@ def get_model_info(model_path: str):
} }
def update_model(model_path: str, post: MultiDictProxy): def update_model(model_path: str, model_data: dict):
if "previewFile" in post: if "previewFile" in model_data:
previewFile = post["previewFile"] previewFile = model_data["previewFile"]
utils.save_model_preview_image(model_path, previewFile) utils.save_model_preview_image(model_path, previewFile)
if "description" in post: if "description" in model_data:
description = post["description"] description = model_data["description"]
utils.save_model_description(model_path, description) utils.save_model_description(model_path, description)
if "type" in post and "pathIndex" in post and "fullname" in post: if "type" in model_data and "pathIndex" in model_data and "fullname" in model_data:
model_type = post.get("type", None) model_type = model_data.get("type", None)
path_index = int(post.get("pathIndex", None)) path_index = int(model_data.get("pathIndex", None))
fullname = post.get("fullname", None) fullname = model_data.get("fullname", None)
if model_type is None or path_index is None or fullname is None: if model_type is None or path_index is None or fullname is None:
raise RuntimeError("Invalid type or pathIndex or fullname") raise RuntimeError("Invalid type or pathIndex or fullname")
@@ -111,9 +110,8 @@ def remove_model(model_path: str):
os.remove(utils.join_path(model_dirname, description)) os.remove(utils.join_path(model_dirname, description))
async def create_model_download_task(post, request): async def create_model_download_task(task_data, request):
dict_post = dict(post) return await download.create_model_download_task(task_data, request)
return await download.create_model_download_task(dict_post, request)
async def scan_model_download_task_list(): async def scan_model_download_task_list():