mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-11-19 23:56:59 +08:00
API routes for getting file & folder paths
This commit is contained in:
parent
1c1b0e7299
commit
17c7d32973
@ -146,6 +146,23 @@ def get_full_path(folder_name, filename):
|
|||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def get_relative_path(folder_name, full_path):
|
||||||
|
global folder_names_and_paths
|
||||||
|
if folder_name not in folder_names_and_paths:
|
||||||
|
return None
|
||||||
|
if not os.path.exists(full_path):
|
||||||
|
return None
|
||||||
|
folders = folder_names_and_paths[folder_name]
|
||||||
|
full_path = os.path.normpath(full_path)
|
||||||
|
for x in folders[0]:
|
||||||
|
x = os.path.normpath(x)
|
||||||
|
if os.path.commonprefix([x, full_path]):
|
||||||
|
return os.path.relpath(full_path, x)
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_filename_list_(folder_name):
|
def get_filename_list_(folder_name):
|
||||||
global folder_names_and_paths
|
global folder_names_and_paths
|
||||||
output_list = set()
|
output_list = set()
|
||||||
|
|||||||
23
server.py
23
server.py
@ -414,6 +414,29 @@ class PromptServer():
|
|||||||
queue_info['queue_pending'] = current_queue[1]
|
queue_info['queue_pending'] = current_queue[1]
|
||||||
return web.json_response(queue_info)
|
return web.json_response(queue_info)
|
||||||
|
|
||||||
|
@routes.get("/filepaths")
|
||||||
|
async def get_filepaths(request):
|
||||||
|
folder = request.rel_url.query.get("folder")
|
||||||
|
if folder is None:
|
||||||
|
return web.Response(status=404)
|
||||||
|
filepaths = folder_paths.get_filename_list(folder)
|
||||||
|
out = {
|
||||||
|
"filepaths": filepaths
|
||||||
|
}
|
||||||
|
return web.json_response(out)
|
||||||
|
|
||||||
|
@routes.get("/relative_path")
|
||||||
|
async def get_relative_path(request):
|
||||||
|
folder = request.rel_url.query.get("folder")
|
||||||
|
full_path = request.rel_url.query.get("full_path")
|
||||||
|
if folder is None or full_path is None:
|
||||||
|
return web.Response(status=404)
|
||||||
|
relpath = folder_paths.get_relative_path(folder, full_path)
|
||||||
|
out = {
|
||||||
|
"relative_path": relpath
|
||||||
|
}
|
||||||
|
return web.json_response(out)
|
||||||
|
|
||||||
@routes.post("/prompt")
|
@routes.post("/prompt")
|
||||||
async def post_prompt(request):
|
async def post_prompt(request):
|
||||||
print("got prompt")
|
print("got prompt")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user