mirror of
https://github.com/penpot/penpot.git
synced 2025-06-06 22:41:37 +02:00
✨ Import/export workers
This commit is contained in:
parent
21aa23e7f5
commit
61545ea13e
2 changed files with 97 additions and 31 deletions
|
@ -7,25 +7,12 @@
|
|||
(ns app.worker.export
|
||||
(:require
|
||||
[app.main.render :as r]
|
||||
[app.main.repo :as rp]
|
||||
[app.util.dom :as dom]
|
||||
[app.util.http :as http]
|
||||
[app.util.zip :as uz]
|
||||
[app.worker.impl :as impl]
|
||||
[beicon.core :as rx]))
|
||||
|
||||
(defn- handle-response
|
||||
[response]
|
||||
(cond
|
||||
(http/success? response)
|
||||
(rx/of (:body response))
|
||||
|
||||
(http/client-error? response)
|
||||
(rx/throw (:body response))
|
||||
|
||||
:else
|
||||
(rx/throw {:type :unexpected
|
||||
:code (:error response)})))
|
||||
|
||||
(defn get-page-data
|
||||
[{file-name :file-name {:keys [id name] :as data} :data}]
|
||||
(->> (r/render-page data)
|
||||
|
@ -35,13 +22,6 @@
|
|||
:file-name file-name
|
||||
:markup markup}))))
|
||||
|
||||
(defn query-file [file-id]
|
||||
(->> (http/send! {:uri "/api/rpc/query/file"
|
||||
:query {:id file-id}
|
||||
:method :get})
|
||||
(rx/map http/conditional-decode-transit)
|
||||
(rx/mapcat handle-response)))
|
||||
|
||||
(defn process-pages [file]
|
||||
(let [pages (get-in file [:data :pages])
|
||||
pages-index (get-in file [:data :pages-index])]
|
||||
|
@ -59,7 +39,7 @@
|
|||
|
||||
(let [render-stream
|
||||
(->> (rx/from (->> files (mapv :id)))
|
||||
(rx/merge-map query-file)
|
||||
(rx/merge-map #(rp/query :file {:id %}))
|
||||
(rx/flat-map process-pages)
|
||||
(rx/observe-on :async)
|
||||
(rx/flat-map get-page-data)
|
||||
|
@ -71,7 +51,6 @@
|
|||
:data (str "Render " (:file-name %) " - " (:name %)))))
|
||||
(->> render-stream
|
||||
(rx/reduce collect-page [])
|
||||
(rx/tap #(prn %))
|
||||
(rx/flat-map uz/compress-files)
|
||||
(rx/map #(hash-map :type :finish
|
||||
:data (dom/create-uri %)))))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue