From 16c8c4bd2aecc390b7b4e8835903b9bedf479fca Mon Sep 17 00:00:00 2001 From: Aitor Date: Tue, 21 Nov 2023 16:47:48 +0100 Subject: [PATCH] :zap: Use subdomain for rasterizer (OOPIF) --- frontend/src/app/main/rasterizer.cljs | 11 ++++++++++- frontend/src/app/main/render.cljs | 28 ++++++++++++++------------- frontend/src/app/rasterizer.cljs | 4 ++++ 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/frontend/src/app/main/rasterizer.cljs b/frontend/src/app/main/rasterizer.cljs index 7c3cedeb4..3fb1f2ca1 100644 --- a/frontend/src/app/main/rasterizer.cljs +++ b/frontend/src/app/main/rasterizer.cljs @@ -61,10 +61,19 @@ [message] (.push ^js queue message)) +(defn- replace-uris + "Replaces URIs for rasterizer ones in styles" + [styles] + (let [public-uri (str cf/public-uri) + rasterizer-uri (str cf/rasterizer-uri)] + (if-not (= public-uri rasterizer-uri) + (str/replace styles public-uri rasterizer-uri) + styles))) + (defn render "Renders an SVG" [{:keys [data styles width result] :as params}] - (let [styles (d/nilv styles "") + (let [styles (replace-uris (d/nilv styles "")) result (d/nilv result "blob") id (dm/str (uuid/next)) payload #js {:data data :styles styles :width width :result result} diff --git a/frontend/src/app/main/render.cljs b/frontend/src/app/main/render.cljs index 5345b895a..89f1e3288 100644 --- a/frontend/src/app/main/render.cljs +++ b/frontend/src/app/main/render.cljs @@ -553,13 +553,15 @@ [fixed-width fixed-height] (th/get-relative-size width height) - data (rds/renderToStaticMarkup - (mf/element frame-imposter - #js {:objects objects - :frame shape - :vbox viewbox - :width width - :height height}))] + + data (with-redefs [cfg/public-uri cfg/rasterizer-uri] + (rds/renderToStaticMarkup + (mf/element frame-imposter + #js {:objects objects + :frame shape + :vbox viewbox + :width width + :height height})))] (->> (fonts/render-font-styles-cached fonts) (rx/catch (fn [cause] @@ -567,11 +569,11 @@ :cause cause) (rx/empty))) (rx/map (fn [styles] - {:id object-id - :data data - :viewbox viewbox - :width fixed-width - :height fixed-height - :styles styles})))) + {:id object-id + :data data + :viewbox viewbox + :width fixed-width + :height fixed-height + :styles styles})))) (do (l/warn :msg "imposter shape is nil") (rx/empty)))) diff --git a/frontend/src/app/rasterizer.cljs b/frontend/src/app/rasterizer.cljs index 36fab6ded..042678711 100644 --- a/frontend/src/app/rasterizer.cljs +++ b/frontend/src/app/rasterizer.cljs @@ -221,6 +221,10 @@ scope (unchecked-get evdata "scope")] (when (and (some? payload) (= scope "penpot/rasterizer")) + (log/dbg :hint "received message" + :id id + :payload payload + :scope scope) (->> (render payload) (rx/subs (partial send-success! id) (partial send-failure! id))))))))