Skip to content

Commit

Permalink
Fix CORS errors by proxying the image
Browse files Browse the repository at this point in the history
  • Loading branch information
adosikas committed Dec 10, 2023
1 parent 04eeb1f commit a950bfb
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/synth_mapping_helper/gui_tabs/wall_art.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a950bfb

Please sign in to comment.