From a950bfbdf7d597e734d4c227e264716233994011 Mon Sep 17 00:00:00 2001 From: adosikas Date: Sun, 10 Dec 2023 18:32:57 +0100 Subject: [PATCH] Fix CORS errors by proxying the image --- src/synth_mapping_helper/gui_tabs/wall_art.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/synth_mapping_helper/gui_tabs/wall_art.py b/src/synth_mapping_helper/gui_tabs/wall_art.py index d0af889..a2e41fb 100644 --- a/src/synth_mapping_helper/gui_tabs/wall_art.py +++ b/src/synth_mapping_helper/gui_tabs/wall_art.py @@ -1,9 +1,12 @@ from dataclasses import dataclass, field +from io import BytesIO +from fastapi.responses import Response from nicegui import ui, app, events from nicegui.elements.scene_objects import Extrusion, Texture import numpy as np import pyperclip +import requests from .map_render import MapScene, SettingsPanel from .utils import ParseInputError, info, error @@ -40,6 +43,11 @@ def parsed_value(self) -> float: except ValueError as ve: raise ParseInputError(self.storage_id, self.value) from ve +@app.get("/image_proxy") +def image_proxy(url:str): + r = requests.get(url) + return Response(content=r.content) + def wall_art_tab(): preview_scene: MapScene|None = None refimg_obj: Texture|None = None @@ -355,7 +363,7 @@ def _soft_refresh(): coords = np.array([[[-1/2,0,1/2],[1/2,0,1/2]],[[-1/2,0,-1/2],[1/2,0,-1/2]]]) * [refimg_width.parsed_value,0,refimg_height.parsed_value] pos = (refimg_x.parsed_value, refimg_t.parsed_value*time_scale.parsed_value, refimg_y.parsed_value) opacity = refimg_opacity.parsed_value - refimg_obj = preview_scene.texture(refimg_url.value,coords).move(*pos).material(opacity=opacity) + refimg_obj = preview_scene.texture(f"/image_proxy?url={refimg_url.value}",coords).move(*pos).material(opacity=opacity) except ParseInputError as pie: error(f"Error parsing reference image setting: {pie.input_id}", pie, data=pie.value) wall_data = synth_format.DataContainer(walls=walls)