mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-05-25 08:27:25 +08:00
Compare commits
4 Commits
1b7bcdd144
...
d6a42e7e3a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d6a42e7e3a | ||
|
|
6bcd8b96ab | ||
|
|
5585cca20b | ||
|
|
ea86d843de |
@ -3,6 +3,7 @@ from typing import Optional
|
||||
from folder_paths import folder_names_and_paths, get_directory_by_type
|
||||
from api_server.services.terminal_service import TerminalService
|
||||
import app.logger
|
||||
import ipaddress
|
||||
import os
|
||||
|
||||
class InternalRoutes:
|
||||
@ -72,7 +73,19 @@ class InternalRoutes:
|
||||
|
||||
def get_app(self):
|
||||
if self._app is None:
|
||||
self._app = web.Application()
|
||||
self._app = web.Application(middlewares=[self._local_only_middleware])
|
||||
self.setup_routes()
|
||||
self._app.add_routes(self.routes)
|
||||
return self._app
|
||||
|
||||
@web.middleware
|
||||
async def _local_only_middleware(self, request, handler):
|
||||
remote = request.remote
|
||||
if remote is None:
|
||||
raise web.HTTPForbidden(reason="Internal endpoints are only accessible from localhost")
|
||||
try:
|
||||
if not ipaddress.ip_address(remote).is_loopback:
|
||||
raise web.HTTPForbidden(reason="Internal endpoints are only accessible from localhost")
|
||||
except ValueError:
|
||||
raise web.HTTPForbidden(reason="Internal endpoints are only accessible from localhost")
|
||||
return await handler(request)
|
||||
|
||||
@ -560,7 +560,7 @@ class PromptServer():
|
||||
buffer.seek(0)
|
||||
|
||||
return web.Response(body=buffer.read(), content_type=f'image/{image_format}',
|
||||
headers={"Content-Disposition": f"attachment; filename=\"{filename}\""})
|
||||
headers={"Content-Disposition": f"filename=\"{filename}\""})
|
||||
|
||||
if 'channel' not in request.rel_url.query:
|
||||
channel = 'rgba'
|
||||
@ -580,7 +580,7 @@ class PromptServer():
|
||||
buffer.seek(0)
|
||||
|
||||
return web.Response(body=buffer.read(), content_type='image/png',
|
||||
headers={"Content-Disposition": f"attachment; filename=\"{filename}\""})
|
||||
headers={"Content-Disposition": f"filename=\"{filename}\""})
|
||||
|
||||
elif channel == 'a':
|
||||
with Image.open(file) as img:
|
||||
@ -597,7 +597,7 @@ class PromptServer():
|
||||
alpha_buffer.seek(0)
|
||||
|
||||
return web.Response(body=alpha_buffer.read(), content_type='image/png',
|
||||
headers={"Content-Disposition": f"attachment; filename=\"{filename}\""})
|
||||
headers={"Content-Disposition": f"filename=\"{filename}\""})
|
||||
else:
|
||||
# Use the content type from asset resolution if available,
|
||||
# otherwise guess from the filename.
|
||||
@ -614,7 +614,7 @@ class PromptServer():
|
||||
return web.FileResponse(
|
||||
file,
|
||||
headers={
|
||||
"Content-Disposition": f"attachment; filename=\"{filename}\"",
|
||||
"Content-Disposition": f"filename=\"{filename}\"",
|
||||
"Content-Type": content_type
|
||||
}
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user