mirror of
https://github.com/penpot/penpot.git
synced 2025-02-13 02:28:18 -05:00
✨ Add export method into API
This commit is contained in:
parent
7fd75336a5
commit
aa90232bf9
1 changed files with 49 additions and 3 deletions
|
@ -5,17 +5,23 @@
|
||||||
;; Copyright (c) KALEIDOS INC
|
;; Copyright (c) KALEIDOS INC
|
||||||
|
|
||||||
(ns app.plugins.file
|
(ns app.plugins.file
|
||||||
"RPC for plugins runtime."
|
|
||||||
(:require
|
(:require
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.record :as crc]
|
[app.common.record :as crc]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.main.data.workspace :as dw]
|
[app.main.data.workspace :as dw]
|
||||||
|
[app.main.features :as features]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
|
[app.main.ui.export :as mue]
|
||||||
|
[app.main.worker :as uw]
|
||||||
[app.plugins.page :as page]
|
[app.plugins.page :as page]
|
||||||
|
[app.plugins.parser :as parser]
|
||||||
[app.plugins.register :as r]
|
[app.plugins.register :as r]
|
||||||
[app.plugins.utils :as u]
|
[app.plugins.utils :as u]
|
||||||
[app.util.object :as obj]))
|
[app.util.http :as http]
|
||||||
|
[app.util.object :as obj]
|
||||||
|
[beicon.v2.core :as rx]
|
||||||
|
[promesa.core :as p]))
|
||||||
|
|
||||||
(deftype FileProxy [$plugin $id]
|
(deftype FileProxy [$plugin $id]
|
||||||
Object
|
Object
|
||||||
|
@ -105,7 +111,47 @@
|
||||||
:else
|
:else
|
||||||
(let [page-id (uuid/next)]
|
(let [page-id (uuid/next)]
|
||||||
(st/emit! (dw/create-page {:page-id page-id :file-id $id}))
|
(st/emit! (dw/create-page {:page-id page-id :file-id $id}))
|
||||||
(page/page-proxy $plugin $id page-id)))))
|
(page/page-proxy $plugin $id page-id))))
|
||||||
|
|
||||||
|
(export
|
||||||
|
[self type export-type]
|
||||||
|
(let [export-type (or (parser/parse-keyword export-type) :all)]
|
||||||
|
(cond
|
||||||
|
(not (contains? #{"penpot" "zip"} type))
|
||||||
|
(u/display-not-valid :export-type type)
|
||||||
|
|
||||||
|
(not (contains? (set mue/export-types) export-type))
|
||||||
|
(u/display-not-valid :export-exportType export-type)
|
||||||
|
|
||||||
|
:else
|
||||||
|
(let [export-cmd (if (= type "penpot") :export-binary-file :export-standard-file)
|
||||||
|
file (u/proxy->file self)
|
||||||
|
features (features/get-team-enabled-features @st/state)
|
||||||
|
team-id (:current-team-id @st/state)]
|
||||||
|
(p/create
|
||||||
|
(fn [resolve reject]
|
||||||
|
(->> (uw/ask-many!
|
||||||
|
{:cmd export-cmd
|
||||||
|
:team-id team-id
|
||||||
|
:features features
|
||||||
|
:export-type export-type
|
||||||
|
:files [file]})
|
||||||
|
(rx/mapcat #(->> (rx/of %) (rx/delay 1000)))
|
||||||
|
(rx/mapcat
|
||||||
|
(fn [msg]
|
||||||
|
(case (:type msg)
|
||||||
|
:error
|
||||||
|
(rx/throw (ex-info "cannot export file" {:type :export-file}))
|
||||||
|
|
||||||
|
:progress
|
||||||
|
(rx/empty)
|
||||||
|
|
||||||
|
:finish
|
||||||
|
(http/send! {:method :get :uri (:uri msg) :mode :no-cors :response-type :blob}))))
|
||||||
|
(rx/first)
|
||||||
|
(rx/mapcat (fn [{:keys [body]}] (.arrayBuffer ^js body)))
|
||||||
|
(rx/map (fn [data] (js/Uint8Array. data)))
|
||||||
|
(rx/subs! resolve reject)))))))))
|
||||||
|
|
||||||
(crc/define-properties!
|
(crc/define-properties!
|
||||||
FileProxy
|
FileProxy
|
||||||
|
|
Loading…
Add table
Reference in a new issue