File size: 871 Bytes
82ea528
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
30
31
32
33
34
35
36
37
38
39
import server
import os

from ..shared_utils.log_utils import cstr

web = server.web

SUPPORTED_VIEW_EXTENSIONS = (
    '.png',
    '.jpg',
    '.jpeg ',
    '.mtl',
    '.obj',
    '.glb',
    '.ply',
    '.splat'
)


web_conf = None

def set_web_conf(new_web_conf):
    global web_conf
    web_conf = new_web_conf

@server.PromptServer.instance.routes.get("/viewfile")
async def view_file(request):
    query = request.rel_url.query
    # Security check to see if query client is local
    if request.remote in web_conf['clients_ip'] and "filepath" in query:
        filepath = query["filepath"]
        
        cstr(f"[Server Query view_file] Get file {filepath}").msg.print()
        
        if filepath.lower().endswith(SUPPORTED_VIEW_EXTENSIONS) and os.path.exists(filepath):
            return web.FileResponse(filepath)
    
    return web.Response(status=404)