Use subdomain for rasterizer (OOPIF)

This commit is contained in:
Aitor 2023-11-21 16:47:48 +01:00 committed by Andrey Antukh
parent 7404933e99
commit 16c8c4bd2a
3 changed files with 29 additions and 14 deletions

View file

@ -61,10 +61,19 @@
[message] [message]
(.push ^js queue 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 (defn render
"Renders an SVG" "Renders an SVG"
[{:keys [data styles width result] :as params}] [{:keys [data styles width result] :as params}]
(let [styles (d/nilv styles "") (let [styles (replace-uris (d/nilv styles ""))
result (d/nilv result "blob") result (d/nilv result "blob")
id (dm/str (uuid/next)) id (dm/str (uuid/next))
payload #js {:data data :styles styles :width width :result result} payload #js {:data data :styles styles :width width :result result}

View file

@ -553,13 +553,15 @@
[fixed-width [fixed-width
fixed-height] (th/get-relative-size width height) fixed-height] (th/get-relative-size width height)
data (rds/renderToStaticMarkup
(mf/element frame-imposter data (with-redefs [cfg/public-uri cfg/rasterizer-uri]
#js {:objects objects (rds/renderToStaticMarkup
:frame shape (mf/element frame-imposter
:vbox viewbox #js {:objects objects
:width width :frame shape
:height height}))] :vbox viewbox
:width width
:height height})))]
(->> (fonts/render-font-styles-cached fonts) (->> (fonts/render-font-styles-cached fonts)
(rx/catch (fn [cause] (rx/catch (fn [cause]
@ -567,11 +569,11 @@
:cause cause) :cause cause)
(rx/empty))) (rx/empty)))
(rx/map (fn [styles] (rx/map (fn [styles]
{:id object-id {:id object-id
:data data :data data
:viewbox viewbox :viewbox viewbox
:width fixed-width :width fixed-width
:height fixed-height :height fixed-height
:styles styles})))) :styles styles}))))
(do (l/warn :msg "imposter shape is nil") (do (l/warn :msg "imposter shape is nil")
(rx/empty)))) (rx/empty))))

View file

@ -221,6 +221,10 @@
scope (unchecked-get evdata "scope")] scope (unchecked-get evdata "scope")]
(when (and (some? payload) (when (and (some? payload)
(= scope "penpot/rasterizer")) (= scope "penpot/rasterizer"))
(log/dbg :hint "received message"
:id id
:payload payload
:scope scope)
(->> (render payload) (->> (render payload)
(rx/subs (partial send-success! id) (rx/subs (partial send-success! id)
(partial send-failure! id)))))))) (partial send-failure! id))))))))