mirror of
https://github.com/penpot/penpot.git
synced 2025-01-23 06:58:58 -05:00
✨ Adapt exporter app to deployment related chages.
This commit is contained in:
parent
b8526c6e3b
commit
f8881b3c72
4 changed files with 37 additions and 10 deletions
|
@ -54,7 +54,9 @@
|
|||
:incognito (.-CONCURRENCY_CONTEXT ^js ppc/Cluster)
|
||||
:page (.-CONCURRENCY_PAGE ^js ppc/Cluster))
|
||||
opts #js {:concurrency ccst
|
||||
:maxConcurrency concurrency}]
|
||||
:maxConcurrency concurrency
|
||||
:puppeteerOptions #js {:args #js ["--no-sandbox"
|
||||
"--explicitly-allowed-ports=6000"]}}]
|
||||
(.launch ^js ppc/Cluster opts))))
|
||||
|
||||
(defn stop!
|
||||
|
|
|
@ -17,4 +17,4 @@
|
|||
(js/Object.keys env)))))
|
||||
|
||||
(defonce config
|
||||
{:domain (:app-domain env "localhost:3449")})
|
||||
{:public-uri (:app-public-uri env "http://localhost:3449")})
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
[promesa.core :as p]
|
||||
[lambdaisland.glogi :as log]
|
||||
[app.browser :as bwr]
|
||||
[app.http.screenshot :refer [bitmap-handler]]
|
||||
[app.http.screenshot :refer [bitmap-handler
|
||||
page-handler]]
|
||||
[app.util.transit :as t]
|
||||
[reitit.core :as r]
|
||||
[cuerdas.core :as str]
|
||||
|
@ -90,7 +91,8 @@
|
|||
|
||||
(def routes
|
||||
[["/export"
|
||||
["/bitmap" {:handler bitmap-handler}]]])
|
||||
["/bitmap" {:handler bitmap-handler}]
|
||||
["/page" {:handler page-handler}]]])
|
||||
|
||||
(defn- router-handler
|
||||
[router]
|
||||
|
|
|
@ -2,10 +2,13 @@
|
|||
(:require
|
||||
[app.browser :as bwr]
|
||||
[app.config :as cfg]
|
||||
[lambdaisland.glogi :as log]
|
||||
[cljs.spec.alpha :as s]
|
||||
[promesa.core :as p]
|
||||
[uxbox.common.exceptions :as exc :include-macros true]
|
||||
[uxbox.common.spec :as us]))
|
||||
[uxbox.common.spec :as us])
|
||||
(:import
|
||||
goog.Uri))
|
||||
|
||||
(defn- load-and-screenshot
|
||||
[page url cookie]
|
||||
|
@ -15,19 +18,24 @@
|
|||
(bwr/navigate! page url)
|
||||
(bwr/sleep page 500)
|
||||
(.evaluate page (js* "() => document.body.style.background = 'transparent'"))
|
||||
;; (.screenshot ^js page #js {:omitBackground true :fullPage true})
|
||||
(p/let [dom (.$ page "#screenshot")]
|
||||
(.screenshot ^js dom #js {:omitBackground true}))))
|
||||
|
||||
(defn- take-screenshot
|
||||
[browser {:keys [page-id object-id token]}]
|
||||
(letfn [(on-browser [page]
|
||||
(let [url (str "http://" (:domain cfg/config)
|
||||
"/#/render-object/"
|
||||
page-id "/" object-id)
|
||||
cookie {:domain (:domain cfg/config)
|
||||
(let [path (str "/render-object/" page-id "/" object-id)
|
||||
uri (doto (Uri. (:public-uri cfg/config))
|
||||
(.setPath "/")
|
||||
(.setFragment path))
|
||||
cookie {:domain (str (.getDomain uri)
|
||||
":"
|
||||
(.getPort uri))
|
||||
:key "auth-token"
|
||||
:value token}]
|
||||
(load-and-screenshot page url cookie)))]
|
||||
(log/info :uri (.toString uri))
|
||||
(load-and-screenshot page (.toString uri) cookie)))]
|
||||
(bwr/exec! browser on-browser)))
|
||||
|
||||
(s/def ::page-id ::us/uuid)
|
||||
|
@ -48,3 +56,18 @@
|
|||
:headers {"content-type" "image/png"
|
||||
"content-length" (alength result)}})))))
|
||||
|
||||
(defn page-handler
|
||||
[{:keys [params browser] :as request}]
|
||||
(letfn [(screenshot [page uri]
|
||||
(p/do!
|
||||
(bwr/emulate! page {:viewport [1920 1080]})
|
||||
(bwr/navigate! page uri)
|
||||
(bwr/sleep page 500)
|
||||
;; (.evaluate page (js* "() => document.body.style.background = 'transparent'"))
|
||||
(.screenshot ^js page #js {:omitBackground false})))]
|
||||
(p/let [uri (get-in params [:query :uri])
|
||||
sht (bwr/exec! browser #(screenshot % uri))]
|
||||
{:status 200
|
||||
:body sht
|
||||
:headers {"content-type" "image/png"
|
||||
"content-length" (alength sht)}})))
|
||||
|
|
Loading…
Add table
Reference in a new issue