API routes for getting file & folder paths

This commit is contained in:
space-nuko 2023-07-03 23:05:44 -05:00
parent 1c1b0e7299
commit 17c7d32973
2 changed files with 40 additions and 0 deletions

View File

@ -146,6 +146,23 @@ def get_full_path(folder_name, filename):
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):
global folder_names_and_paths
output_list = set()

View File

@ -414,6 +414,29 @@ class PromptServer():
queue_info['queue_pending'] = current_queue[1]
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")
async def post_prompt(request):
print("got prompt")