💄 Cosmetic refactor of binfile internal API impl

This commit is contained in:
Andrey Antukh 2022-07-07 12:26:46 +02:00
parent 98190ed92d
commit d60f849089
4 changed files with 206 additions and 189 deletions

View file

@ -76,12 +76,12 @@
(defn- send-command!
"A simple helper for a common case of sending and receiving transit
data to the penpot mutation api."
[id {:keys [blob? form-data?] :as params}]
[id params {:keys [response-type form-data?]}]
(->> (http/send! {:method :post
:uri (u/join base-uri "api/rpc/command/" (name id))
:credentials "include"
:body (if form-data? (http/form-data params) (http/transit-data params))
:response-type (if blob? :blob :text)})
:response-type (or response-type :text)})
(rx/map http/conditional-decode-transit)
(rx/mapcat handle-response)))
@ -105,7 +105,15 @@
(defmethod command :default
[id params]
(send-command! id params))
(send-command! id params nil))
(defmethod command :export-binfile
[id params]
(send-command! id params {:response-type :blob}))
(defmethod command :import-binfile
[id params]
(send-command! id params {:form-data? true}))
(defn query!
([id] (query id {}))

View file

@ -457,8 +457,7 @@
(fn [file]
(->> (rp/command! :export-binfile {:file-id (:id file)
:include-libraries? (= export-type :all)
:embed-assets? (= export-type :merge)
:blob? true})
:embed-assets? (= export-type :merge)})
(rx/map #(hash-map :type :finish
:file-id (:id file)
:filename (:name file)

View file

@ -604,8 +604,7 @@
:response-type :blob
:method :get})
(rx/map :body)
(rx/mapcat #(rp/command! :import-binfile {:input %
:form-data? true}))
(rx/mapcat #(rp/command! :import-binfile {:file %}))
(rx/map
(fn [_]
{:status :import-finish