mirror of
https://github.com/penpot/penpot.git
synced 2025-05-28 03:56:12 +02:00
♻️ Refactor error handling on exporter browser module.
This commit is contained in:
parent
bf51e3db60
commit
0be2b2791f
9 changed files with 106 additions and 64 deletions
|
@ -6,14 +6,17 @@
|
||||||
|
|
||||||
(ns app.browser
|
(ns app.browser
|
||||||
(:require
|
(:require
|
||||||
["puppeteer-core" :as pp]
|
|
||||||
["generic-pool" :as gp]
|
["generic-pool" :as gp]
|
||||||
|
["puppeteer-core" :as pp]
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
|
[app.common.logging :as l]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
[lambdaisland.glogi :as log]
|
|
||||||
[promesa.core :as p]))
|
[promesa.core :as p]))
|
||||||
|
|
||||||
|
|
||||||
|
(l/set-level! :trace)
|
||||||
|
|
||||||
;; --- BROWSER API
|
;; --- BROWSER API
|
||||||
|
|
||||||
(def default-timeout 30000)
|
(def default-timeout 30000)
|
||||||
|
@ -107,18 +110,18 @@
|
||||||
(-> (pp/launch #js {:executablePath path :args #js ["--no-sandbox" "--font-render-hinting=none"]})
|
(-> (pp/launch #js {:executablePath path :args #js ["--no-sandbox" "--font-render-hinting=none"]})
|
||||||
(p/then (fn [browser]
|
(p/then (fn [browser]
|
||||||
(let [id (deref pool-browser-id)]
|
(let [id (deref pool-browser-id)]
|
||||||
(log/info :origin "factory" :action "create" :browser-id id)
|
(l/info :origin "factory" :action "create" :browser-id id)
|
||||||
(unchecked-set browser "__id" id)
|
(unchecked-set browser "__id" id)
|
||||||
(swap! pool-browser-id inc)
|
(swap! pool-browser-id inc)
|
||||||
browser))))))
|
browser))))))
|
||||||
(destroy [obj]
|
(destroy [obj]
|
||||||
(let [id (unchecked-get obj "__id")]
|
(let [id (unchecked-get obj "__id")]
|
||||||
(log/info :origin "factory" :action "destroy" :browser-id id)
|
(l/info :origin "factory" :action "destroy" :browser-id id)
|
||||||
(.close ^js obj)))
|
(.close ^js obj)))
|
||||||
|
|
||||||
(validate [obj]
|
(validate [obj]
|
||||||
(let [id (unchecked-get obj "__id")]
|
(let [id (unchecked-get obj "__id")]
|
||||||
(log/info :origin "factory" :action "validate" :browser-id id :obj obj)
|
(l/info :origin "factory" :action "validate" :browser-id id :obj obj)
|
||||||
(p/resolved (.isConnected ^js obj))))]
|
(p/resolved (.isConnected ^js obj))))]
|
||||||
|
|
||||||
#js {:create create
|
#js {:create create
|
||||||
|
@ -127,7 +130,7 @@
|
||||||
|
|
||||||
(defn init
|
(defn init
|
||||||
[]
|
[]
|
||||||
(log/info :msg "initializing browser pool")
|
(l/info :msg "initializing browser pool")
|
||||||
(let [opts #js {:max (cf/get :browser-pool-max 3)
|
(let [opts #js {:max (cf/get :browser-pool-max 3)
|
||||||
:min (cf/get :browser-pool-min 0)
|
:min (cf/get :browser-pool-min 0)
|
||||||
:testOnBorrow true
|
:testOnBorrow true
|
||||||
|
@ -142,34 +145,74 @@
|
||||||
(defn stop
|
(defn stop
|
||||||
[]
|
[]
|
||||||
(when-let [pool (deref pool)]
|
(when-let [pool (deref pool)]
|
||||||
(log/info :msg "finalizing browser pool")
|
(l/info :msg "finalizing browser pool")
|
||||||
(-> (.drain ^js pool)
|
(-> (.drain ^js pool)
|
||||||
(p/then (fn [] (.clear ^js pool))))))
|
(p/then (fn [] (.clear ^js pool))))))
|
||||||
|
|
||||||
(defn exec!
|
(defn exec!
|
||||||
[callback]
|
[callback]
|
||||||
(letfn [(on-release [pool browser ctx result error]
|
(letfn [(release-browser [pool browser]
|
||||||
(-> (p/do! (.close ^js ctx))
|
(let [id (unchecked-get browser "__id")]
|
||||||
(p/handle
|
(-> (p/do! (.release ^js pool browser))
|
||||||
(fn [_ _]
|
(p/handle (fn [res err]
|
||||||
(.release ^js pool browser)))
|
(l/trace :action "exec:release-browser" :browser-id id)
|
||||||
(p/handle
|
(when err (js/console.log err))
|
||||||
(fn [_ _]
|
(if err
|
||||||
(let [id (unchecked-get browser "__id")]
|
(p/rejected err)
|
||||||
(log/info :origin "exec" :action "release" :browser-id id))
|
(p/resolved res)))))))
|
||||||
(if result
|
|
||||||
(p/resolved result)
|
(destroy-browser [pool browser]
|
||||||
(p/rejected error))))))
|
(let [id (unchecked-get browser "__id")]
|
||||||
|
(-> (p/do! (.destroy ^js pool browser))
|
||||||
|
(p/handle (fn [res err]
|
||||||
|
(l/trace :action "exec:destroy-browser" :browser-id id)
|
||||||
|
(when err (js/console.log err))
|
||||||
|
(if err
|
||||||
|
(p/rejected err)
|
||||||
|
(p/resolved res)))))))
|
||||||
|
|
||||||
|
(handle-error [pool browser obj err]
|
||||||
|
(let [id (unchecked-get browser "__id")]
|
||||||
|
(if err
|
||||||
|
(do
|
||||||
|
(l/trace :action "exec:handle-error" :browser-id id)
|
||||||
|
(-> (p/do! (destroy-browser pool browser))
|
||||||
|
(p/handle #(p/rejected err))))
|
||||||
|
(p/resolved obj))))
|
||||||
|
|
||||||
|
(on-result [pool browser context result]
|
||||||
|
(let [id (unchecked-get browser "__id")]
|
||||||
|
(l/trace :action "exec:on-result" :browser-id id)
|
||||||
|
(-> (p/do! (.close ^js context))
|
||||||
|
(p/handle (fn [_ err]
|
||||||
|
(if err
|
||||||
|
(destroy-browser pool browser)
|
||||||
|
(release-browser pool browser))))
|
||||||
|
(p/handle #(p/resolved result)))))
|
||||||
|
|
||||||
|
(on-page [pool browser context page]
|
||||||
|
(let [id (unchecked-get browser "__id")]
|
||||||
|
(l/trace :action "exec:on-page" :browser-id id)
|
||||||
|
(-> (p/do! (callback page))
|
||||||
|
(p/handle (partial handle-error pool browser))
|
||||||
|
(p/then (partial on-result pool browser context)))))
|
||||||
|
|
||||||
(on-context [pool browser ctx]
|
(on-context [pool browser ctx]
|
||||||
(-> (p/do! (.newPage ^js ctx))
|
(let [id (unchecked-get browser "__id")]
|
||||||
(p/then callback)
|
(l/trace :action "exec:on-context" :browser-id id)
|
||||||
(p/handle #(on-release pool browser ctx %1 %2))))
|
(-> (p/do! (.newPage ^js ctx))
|
||||||
|
(p/handle (partial handle-error pool browser))
|
||||||
|
(p/then (partial on-page pool browser ctx)))))
|
||||||
|
|
||||||
(on-acquire [pool browser]
|
(on-acquire [pool browser err]
|
||||||
(-> (.createIncognitoBrowserContext ^js browser)
|
(let [id (unchecked-get browser "__id")]
|
||||||
(p/then #(on-context pool browser %))))]
|
(l/trace :action "exec:on-acquire" :browser-id id)
|
||||||
|
(if err
|
||||||
|
(js/console.log err)
|
||||||
|
(-> (p/do! (.createIncognitoBrowserContext ^js browser))
|
||||||
|
(p/handle (partial handle-error pool browser))
|
||||||
|
(p/then (partial on-context pool browser))))))]
|
||||||
|
|
||||||
(when-let [pool (deref pool)]
|
(when-let [pool (deref pool)]
|
||||||
(-> (p/do! (.acquire ^js pool))
|
(-> (p/do! (.acquire ^js pool))
|
||||||
(p/then (partial on-acquire pool))))))
|
(p/handle (partial on-acquire pool))))))
|
||||||
|
|
|
@ -6,23 +6,22 @@
|
||||||
|
|
||||||
(ns app.core
|
(ns app.core
|
||||||
(:require
|
(:require
|
||||||
[lambdaisland.glogi :as log]
|
[app.browser :as bwr]
|
||||||
[lambdaisland.glogi.console :as glogi-console]
|
[app.common.logging :as l]
|
||||||
[promesa.core :as p]
|
[app.config]
|
||||||
[app.http :as http]
|
[app.http :as http]
|
||||||
[app.sentry :as sentry]
|
[app.sentry :as sentry]
|
||||||
[app.config]
|
[promesa.core :as p]))
|
||||||
[app.browser :as bwr]))
|
|
||||||
|
|
||||||
(glogi-console/install!)
|
|
||||||
(enable-console-print!)
|
(enable-console-print!)
|
||||||
|
(l/initialize!)
|
||||||
(sentry/init!)
|
(sentry/init!)
|
||||||
|
|
||||||
(defonce state (atom nil))
|
(defonce state (atom nil))
|
||||||
|
|
||||||
(defn start
|
(defn start
|
||||||
[& args]
|
[& args]
|
||||||
(log/info :msg "initializing")
|
(l/info :msg "initializing")
|
||||||
(p/do!
|
(p/do!
|
||||||
(bwr/init)
|
(bwr/init)
|
||||||
(http/init)))
|
(http/init)))
|
||||||
|
@ -34,7 +33,7 @@
|
||||||
;; an empty line for visual feedback of restart
|
;; an empty line for visual feedback of restart
|
||||||
(js/console.log "")
|
(js/console.log "")
|
||||||
|
|
||||||
(log/info :msg "stoping")
|
(l/info :msg "stoping")
|
||||||
(p/do!
|
(p/do!
|
||||||
(bwr/stop)
|
(bwr/stop)
|
||||||
(http/stop)
|
(http/stop)
|
||||||
|
|
|
@ -6,17 +6,19 @@
|
||||||
|
|
||||||
(ns app.http
|
(ns app.http
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.logging :as l]
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
[app.http.export :refer [export-handler]]
|
[app.http.export :refer [export-handler]]
|
||||||
[app.http.export-frames :refer [export-frames-handler]]
|
[app.http.export-frames :refer [export-frames-handler]]
|
||||||
[app.http.impl :as impl]
|
[app.http.impl :as impl]
|
||||||
[app.util.transit :as t]
|
|
||||||
[app.sentry :as sentry]
|
[app.sentry :as sentry]
|
||||||
|
[app.util.transit :as t]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[lambdaisland.glogi :as log]
|
|
||||||
[promesa.core :as p]
|
[promesa.core :as p]
|
||||||
[reitit.core :as r]))
|
[reitit.core :as r]))
|
||||||
|
|
||||||
|
(l/set-level! :info)
|
||||||
|
|
||||||
(def routes
|
(def routes
|
||||||
[["/export-frames" {:handler export-frames-handler}]
|
[["/export-frames" {:handler export-frames-handler}]
|
||||||
["/export" {:handler export-handler}]])
|
["/export" {:handler export-handler}]])
|
||||||
|
@ -49,7 +51,7 @@
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(do
|
(do
|
||||||
(log/error :msg "Unexpected error" :error error)
|
(l/error :msg "Unexpected error" :error error)
|
||||||
(js/console.error error)
|
(js/console.error error)
|
||||||
{:status 500
|
{:status 500
|
||||||
:headers {"x-error" (t/encode data)}
|
:headers {"x-error" (t/encode data)}
|
||||||
|
@ -62,10 +64,10 @@
|
||||||
server (impl/server handler on-error)
|
server (impl/server handler on-error)
|
||||||
port (cf/get :http-server-port 6061)]
|
port (cf/get :http-server-port 6061)]
|
||||||
(.listen server port)
|
(.listen server port)
|
||||||
(log/info :msg "welcome to penpot"
|
(l/info :msg "welcome to penpot"
|
||||||
:module "exporter"
|
:module "exporter"
|
||||||
:version (:full @cf/version))
|
:version (:full @cf/version))
|
||||||
(log/info :msg "starting http server" :port port)
|
(l/info :msg "starting http server" :port port)
|
||||||
(reset! instance server)))
|
(reset! instance server)))
|
||||||
|
|
||||||
(defn stop
|
(defn stop
|
||||||
|
@ -73,6 +75,6 @@
|
||||||
(if-let [server @instance]
|
(if-let [server @instance]
|
||||||
(p/create (fn [resolve]
|
(p/create (fn [resolve]
|
||||||
(.close server (fn []
|
(.close server (fn []
|
||||||
(log/info :msg "shutdown http server")
|
(l/info :msg "shutdown http server")
|
||||||
(resolve)))))
|
(resolve)))))
|
||||||
(p/resolved nil)))
|
(p/resolved nil)))
|
||||||
|
|
|
@ -9,12 +9,11 @@
|
||||||
[app.common.exceptions :as exc :include-macros true]
|
[app.common.exceptions :as exc :include-macros true]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[app.renderer.bitmap :as rb]
|
[app.renderer.bitmap :as rb]
|
||||||
[app.renderer.svg :as rs]
|
|
||||||
[app.renderer.pdf :as rp]
|
[app.renderer.pdf :as rp]
|
||||||
|
[app.renderer.svg :as rs]
|
||||||
[app.zipfile :as zip]
|
[app.zipfile :as zip]
|
||||||
[cljs.spec.alpha :as s]
|
[cljs.spec.alpha :as s]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[lambdaisland.glogi :as log]
|
|
||||||
[promesa.core :as p]))
|
[promesa.core :as p]))
|
||||||
|
|
||||||
(s/def ::name ::us/string)
|
(s/def ::name ::us/string)
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
["raw-body" :as raw-body]
|
["raw-body" :as raw-body]
|
||||||
[app.util.transit :as t]
|
[app.util.transit :as t]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[lambdaisland.glogi :as log]
|
|
||||||
[lambdaisland.uri :as u]
|
[lambdaisland.uri :as u]
|
||||||
[promesa.core :as p]
|
[promesa.core :as p]
|
||||||
[reitit.core :as r]))
|
[reitit.core :as r]))
|
||||||
|
|
|
@ -10,13 +10,13 @@
|
||||||
[app.browser :as bw]
|
[app.browser :as bw]
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.exceptions :as ex :include-macros true]
|
[app.common.exceptions :as ex :include-macros true]
|
||||||
|
[app.common.logging :as l]
|
||||||
[app.common.pages :as cp]
|
[app.common.pages :as cp]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
[cljs.spec.alpha :as s]
|
[cljs.spec.alpha :as s]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[lambdaisland.uri :as u]
|
[lambdaisland.uri :as u]
|
||||||
[lambdaisland.glogi :as log]
|
|
||||||
[promesa.core :as p]))
|
[promesa.core :as p]))
|
||||||
|
|
||||||
(defn create-cookie
|
(defn create-cookie
|
||||||
|
@ -39,7 +39,7 @@
|
||||||
(screenshot page (str uri) cookie)))
|
(screenshot page (str uri) cookie)))
|
||||||
|
|
||||||
(screenshot [page uri cookie]
|
(screenshot [page uri cookie]
|
||||||
(log/info :uri uri)
|
(l/info :uri uri)
|
||||||
(let [viewport {:width 1920
|
(let [viewport {:width 1920
|
||||||
:height 1080
|
:height 1080
|
||||||
:scale scale}
|
:scale scale}
|
||||||
|
|
|
@ -9,11 +9,11 @@
|
||||||
(:require
|
(:require
|
||||||
[app.browser :as bw]
|
[app.browser :as bw]
|
||||||
[app.common.exceptions :as ex :include-macros true]
|
[app.common.exceptions :as ex :include-macros true]
|
||||||
|
[app.common.logging :as l]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
[cljs.spec.alpha :as s]
|
[cljs.spec.alpha :as s]
|
||||||
[lambdaisland.uri :as u]
|
[lambdaisland.uri :as u]
|
||||||
[lambdaisland.glogi :as log]
|
|
||||||
[promesa.core :as p]))
|
[promesa.core :as p]))
|
||||||
|
|
||||||
(defn create-cookie
|
(defn create-cookie
|
||||||
|
@ -36,7 +36,7 @@
|
||||||
(pdf-from page (str uri) cookie)))
|
(pdf-from page (str uri) cookie)))
|
||||||
|
|
||||||
(pdf-from [page uri cookie]
|
(pdf-from [page uri cookie]
|
||||||
(log/info :uri uri)
|
(l/info :uri uri)
|
||||||
(let [options {:cookie cookie}]
|
(let [options {:cookie cookie}]
|
||||||
(p/do!
|
(p/do!
|
||||||
(bw/configure-page! page options)
|
(bw/configure-page! page options)
|
||||||
|
|
|
@ -11,19 +11,19 @@
|
||||||
[app.browser :as bw]
|
[app.browser :as bw]
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.exceptions :as ex :include-macros true]
|
[app.common.exceptions :as ex :include-macros true]
|
||||||
|
[app.common.logging :as l]
|
||||||
[app.common.pages :as cp]
|
[app.common.pages :as cp]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
|
[app.renderer.bitmap :refer [create-cookie]]
|
||||||
[app.util.shell :as sh]
|
[app.util.shell :as sh]
|
||||||
[cljs.spec.alpha :as s]
|
[cljs.spec.alpha :as s]
|
||||||
[clojure.walk :as walk]
|
[clojure.walk :as walk]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[lambdaisland.glogi :as log]
|
|
||||||
[lambdaisland.uri :as u]
|
[lambdaisland.uri :as u]
|
||||||
[app.renderer.bitmap :refer [create-cookie]]
|
|
||||||
[promesa.core :as p]))
|
[promesa.core :as p]))
|
||||||
|
|
||||||
(log/set-level "app.renderer.svg" :trace)
|
(l/set-level! :trace)
|
||||||
|
|
||||||
(defn- xml->clj
|
(defn- xml->clj
|
||||||
[data]
|
[data]
|
||||||
|
@ -116,22 +116,22 @@
|
||||||
(defn- render-object
|
(defn- render-object
|
||||||
[{:keys [page-id file-id object-id token scale suffix type]}]
|
[{:keys [page-id file-id object-id token scale suffix type]}]
|
||||||
(letfn [(convert-to-ppm [pngpath]
|
(letfn [(convert-to-ppm [pngpath]
|
||||||
(log/trace :fn :convert-to-ppm)
|
(l/trace :fn :convert-to-ppm)
|
||||||
(let [basepath (path/dirname pngpath)
|
(let [basepath (path/dirname pngpath)
|
||||||
ppmpath (path/join basepath "origin.ppm")]
|
ppmpath (path/join basepath "origin.ppm")]
|
||||||
(-> (sh/run-cmd! (str "convert " pngpath " " ppmpath))
|
(-> (sh/run-cmd! (str "convert " pngpath " " ppmpath))
|
||||||
(p/then (constantly ppmpath)))))
|
(p/then (constantly ppmpath)))))
|
||||||
|
|
||||||
(trace-color-mask [pbmpath]
|
(trace-color-mask [pbmpath]
|
||||||
(log/trace :fn :trace-color-mask :pbmpath pbmpath)
|
(l/trace :fn :trace-color-mask :pbmpath pbmpath)
|
||||||
(let [basepath (path/dirname pbmpath)
|
(let [basepath (path/dirname pbmpath)
|
||||||
basename (path/basename pbmpath ".pbm")
|
basename (path/basename pbmpath ".pbm")
|
||||||
svgpath (path/join basepath (str basename ".svg"))]
|
svgpath (path/join basepath (str basename ".svg"))]
|
||||||
(-> (sh/run-cmd! (str "potrace --flat -b svg " pbmpath " -o " svgpath))
|
(-> (sh/run-cmd! (str "potrace --flat -b svg " pbmpath " -o " svgpath))
|
||||||
(p/then (constantly svgpath)))))
|
(p/then (constantly svgpath)))))
|
||||||
|
|
||||||
(generate-color-layer [ppmpath color]
|
(generate-color-layer [ppmpath color]
|
||||||
(log/trace :fn :generate-color-layer :ppmpath ppmpath :color color)
|
(l/trace :fn :generate-color-layer :ppmpath ppmpath :color color)
|
||||||
(let [basepath (path/dirname ppmpath)
|
(let [basepath (path/dirname ppmpath)
|
||||||
pbmpath (path/join basepath (str "mask-" (subs color 1) ".pbm"))]
|
pbmpath (path/join basepath (str "mask-" (subs color 1) ".pbm"))]
|
||||||
(-> (sh/run-cmd! (str/format "ppmcolormask \"%s\" %s" color ppmpath))
|
(-> (sh/run-cmd! (str/format "ppmcolormask \"%s\" %s" color ppmpath))
|
||||||
|
@ -193,7 +193,7 @@
|
||||||
(mapv (partial data->gradient-def id))))
|
(mapv (partial data->gradient-def id))))
|
||||||
|
|
||||||
(join-color-layers [{:keys [id x y width height mapping] :as node} layers]
|
(join-color-layers [{:keys [id x y width height mapping] :as node} layers]
|
||||||
(log/trace :fn :join-color-layers :mapping mapping)
|
(l/trace :fn :join-color-layers :mapping mapping)
|
||||||
(loop [result (-> (:svgdata (first layers))
|
(loop [result (-> (:svgdata (first layers))
|
||||||
(assoc "elements" []))
|
(assoc "elements" []))
|
||||||
layers (seq layers)]
|
layers (seq layers)]
|
||||||
|
@ -241,12 +241,12 @@
|
||||||
(assoc "elements" elements))))))
|
(assoc "elements" elements))))))
|
||||||
|
|
||||||
(convert-to-svg [ppmpath {:keys [colors] :as node}]
|
(convert-to-svg [ppmpath {:keys [colors] :as node}]
|
||||||
(log/trace :fn :convert-to-svg :ppmpath ppmpath :colors colors)
|
(l/trace :fn :convert-to-svg :ppmpath ppmpath :colors colors)
|
||||||
(-> (p/all (map (partial generate-color-layer ppmpath) colors))
|
(-> (p/all (map (partial generate-color-layer ppmpath) colors))
|
||||||
(p/then (partial join-color-layers node))))
|
(p/then (partial join-color-layers node))))
|
||||||
|
|
||||||
(trace-node [{:keys [data] :as node}]
|
(trace-node [{:keys [data] :as node}]
|
||||||
(log/trace :fn :trace-node)
|
(l/trace :fn :trace-node)
|
||||||
(p/let [tdpath (sh/create-tmpdir! "svgexport-")
|
(p/let [tdpath (sh/create-tmpdir! "svgexport-")
|
||||||
pngpath (path/join tdpath "origin.png")
|
pngpath (path/join tdpath "origin.png")
|
||||||
_ (sh/write-file! pngpath data)
|
_ (sh/write-file! pngpath data)
|
||||||
|
@ -270,7 +270,7 @@
|
||||||
:mapping (js/JSON.parse mapping)}))
|
:mapping (js/JSON.parse mapping)}))
|
||||||
|
|
||||||
(extract-single-node [[shot node]]
|
(extract-single-node [[shot node]]
|
||||||
(log/trace :fn :extract-single-node)
|
(l/trace :fn :extract-single-node)
|
||||||
|
|
||||||
(p/let [attrs (bw/eval! node extract-element-attrs)]
|
(p/let [attrs (bw/eval! node extract-element-attrs)]
|
||||||
{:id (unchecked-get attrs "id")
|
{:id (unchecked-get attrs "id")
|
||||||
|
@ -302,7 +302,7 @@
|
||||||
(p/then clean-temp-data)))
|
(p/then clean-temp-data)))
|
||||||
|
|
||||||
(process-text-nodes [page]
|
(process-text-nodes [page]
|
||||||
(log/trace :fn :process-text-nodes)
|
(l/trace :fn :process-text-nodes)
|
||||||
(-> (bw/select-all page "#screenshot foreignObject")
|
(-> (bw/select-all page "#screenshot foreignObject")
|
||||||
(p/then (fn [nodes] (p/all (map (partial process-text-node page) nodes))))))
|
(p/then (fn [nodes] (p/all (map (partial process-text-node page) nodes))))))
|
||||||
|
|
||||||
|
@ -345,7 +345,7 @@
|
||||||
cookie (create-cookie uri token)
|
cookie (create-cookie uri token)
|
||||||
rctx {:cookie cookie
|
rctx {:cookie cookie
|
||||||
:uri (str uri)}]
|
:uri (str uri)}]
|
||||||
(log/info :uri (:uri rctx))
|
(l/info :uri (:uri rctx))
|
||||||
(bw/exec! (partial handle rctx)))))
|
(bw/exec! (partial handle rctx)))))
|
||||||
|
|
||||||
(s/def ::name ::us/string)
|
(s/def ::name ::us/string)
|
||||||
|
|
|
@ -11,10 +11,10 @@
|
||||||
["fs" :as fs]
|
["fs" :as fs]
|
||||||
["os" :as os]
|
["os" :as os]
|
||||||
["path" :as path]
|
["path" :as path]
|
||||||
[lambdaisland.glogi :as log]
|
[app.common.logging :as l]
|
||||||
[promesa.core :as p]))
|
[promesa.core :as p]))
|
||||||
|
|
||||||
(log/set-level "app.util.shell" :trace)
|
(l/set-level! :trace)
|
||||||
|
|
||||||
(defn create-tmpdir!
|
(defn create-tmpdir!
|
||||||
[prefix]
|
[prefix]
|
||||||
|
@ -47,10 +47,10 @@
|
||||||
[cmd]
|
[cmd]
|
||||||
(p/create
|
(p/create
|
||||||
(fn [resolve reject]
|
(fn [resolve reject]
|
||||||
(log/trace :fn :run-cmd :cmd cmd)
|
(l/trace :fn :run-cmd :cmd cmd)
|
||||||
(chp/exec cmd #js {:encoding "buffer"}
|
(chp/exec cmd #js {:encoding "buffer"}
|
||||||
(fn [error stdout stderr]
|
(fn [error stdout stderr]
|
||||||
;; (log/trace :fn :run-cmd :stdout stdout)
|
;; (l/trace :fn :run-cmd :stdout stdout)
|
||||||
(if error
|
(if error
|
||||||
(reject error)
|
(reject error)
|
||||||
(resolve stdout)))))))
|
(resolve stdout)))))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue