-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi_server.py
More file actions
29 lines (22 loc) · 909 Bytes
/
api_server.py
File metadata and controls
29 lines (22 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
from aiohttp import web
from folder_paths import get_directory_by_type
from server import PromptServer
routes = PromptServer.instance.routes
@routes.get("/ig1api/images")
async def get_images(request: web.Request) -> web.Response:
input_dir = get_directory_by_type("input")
input_images = sorted(
(entry for entry in os.scandir(input_dir) if entry.is_file()),
key=lambda entry: -entry.stat().st_mtime
)
input_names = [entry.name for entry in input_images]
output_dir = get_directory_by_type("output")
output_images = sorted(
(entry for entry in os.scandir(output_dir) if entry.is_file()),
key=lambda entry: -entry.stat().st_mtime
)
output_names = [entry.name + " [output]" for entry in output_images]
return web.json_response(input_names + output_names, status=200)
def run_api_server():
print("IG1 API Server started")