0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-14 19:19:09 -05:00

Enable exporte multiple files in binfile format

This commit is contained in:
Andrey Antukh 2022-07-06 15:58:32 +02:00
parent f4f58bc163
commit d032953121
4 changed files with 35 additions and 18 deletions

View file

@ -50,8 +50,11 @@ Debug Main Page
file.</desc> file.</desc>
<form method="get" action="/dbg/file/export"> <form method="get" action="/dbg/file/export">
<div class="row"> <div class="row set-of-inputs">
<input type="text" style="width:300px" name="file-id" placeholder="file-id" /> <input type="text" style="width:300px" name="file-ids" placeholder="file-id" />
<input type="text" style="width:300px" name="file-ids" placeholder="file-id" />
<input type="text" style="width:300px" name="file-ids" placeholder="file-id" />
<input type="text" style="width:300px" name="file-ids" placeholder="file-id" />
</div> </div>
<div class="row"> <div class="row">

View file

@ -168,3 +168,12 @@ form .row {
padding: 5px 0; padding: 5px 0;
} }
.set-of-inputs {
flex-direction: column;
display: flex;
}
.set-of-inputs input:not(:last-child) {
margin-bottom: 3px;
}

View file

@ -265,17 +265,20 @@
(defn export-handler (defn export-handler
[{:keys [pool] :as cfg} {:keys [params profile-id] :as request}] [{:keys [pool] :as cfg} {:keys [params profile-id] :as request}]
(let [file-id (some-> params :file-id parse-uuid)
libs? (contains? params :includelibs)
clone? (contains? params :clone)
embed? (contains? params :embedassets)]
(when-not file-id (let [file-ids (->> (:file-ids params)
(remove empty?)
(map parse-uuid))
libs? (contains? params :includelibs)
clone? (contains? params :clone)
embed? (contains? params :embedassets)]
(when-not (seq file-ids)
(ex/raise :type :validation (ex/raise :type :validation
:code :missing-arguments)) :code :missing-arguments))
(let [path (-> cfg (let [path (-> cfg
(assoc ::binf/file-id file-id) (assoc ::binf/file-ids file-ids)
(assoc ::binf/embed-assets? embed?) (assoc ::binf/embed-assets? embed?)
(assoc ::binf/include-libraries? libs?) (assoc ::binf/include-libraries? libs?)
(binf/export!))] (binf/export!))]
@ -297,7 +300,7 @@
(yrs/response (yrs/response
:status 200 :status 200
:headers {"content-type" "application/octet-stream" :headers {"content-type" "application/octet-stream"
"content-disposition" (str "attachmen; filename=" file-id ".penpot")} "content-disposition" (str "attachmen; filename=" (first file-ids) ".penpot")}
:body (io/input-stream path)))))) :body (io/input-stream path))))))

View file

@ -306,7 +306,7 @@
SELECT fl.id, fl.deleted_at SELECT fl.id, fl.deleted_at
FROM file AS fl FROM file AS fl
JOIN file_library_rel AS flr ON (flr.library_file_id = fl.id) JOIN file_library_rel AS flr ON (flr.library_file_id = fl.id)
WHERE flr.file_id = ?::uuid WHERE flr.file_id = ANY(?)
UNION UNION
SELECT fl.id, fl.deleted_at SELECT fl.id, fl.deleted_at
FROM file AS fl FROM file AS fl
@ -318,8 +318,10 @@
WHERE l.deleted_at IS NULL OR l.deleted_at > now();") WHERE l.deleted_at IS NULL OR l.deleted_at > now();")
(defn- retrieve-libraries (defn- retrieve-libraries
[pool file-id] [pool ids]
(map :id (db/exec! pool [sql:file-libraries file-id]))) (with-open [^AutoCloseable conn (db/open pool)]
(let [ids (db/create-array conn "uuid" ids)]
(map :id (db/exec! pool [sql:file-libraries ids])))))
(def ^:private sql:file-library-rels (def ^:private sql:file-library-rels
"SELECT * FROM file_library_rel "SELECT * FROM file_library_rel
@ -394,14 +396,14 @@
same file library all assets used from external libraries. same file library all assets used from external libraries.
" "
[{:keys [pool storage ::output ::file-id ::include-libraries? ::embed-assets?] :as options}] [{:keys [pool storage ::output ::file-ids ::include-libraries? ::embed-assets?] :as options}]
(us/assert! :spec ::db/pool :val pool) (us/assert! :spec ::db/pool :val pool)
(us/assert! :spec ::sto/storage :val storage) (us/assert! :spec ::sto/storage :val storage)
(us/assert! (us/assert!
:expr (uuid? file-id) :expr (every? uuid? file-ids)
:hint "`file-id` should be an uuid") :hint "`files` should be a vector of uuid")
(us/assert! (us/assert!
:expr (bs/data-output-stream? output) :expr (bs/data-output-stream? output)
@ -420,9 +422,9 @@
:expr (not (and include-libraries? embed-assets?)) :expr (not (and include-libraries? embed-assets?))
:hint "the `include-libraries?` and `embed-assets?` are mutally excluding options") :hint "the `include-libraries?` and `embed-assets?` are mutally excluding options")
(let [libs (when include-libraries? (retrieve-libraries pool file-id)) (let [libs (when include-libraries? (retrieve-libraries pool file-ids))
rels (when include-libraries? (retrieve-library-relations pool (cons file-id libs))) files (into file-ids libs)
files (into [file-id] libs) rels (when include-libraries? (retrieve-library-relations pool file-ids))
sids (volatile! #{})] sids (volatile! #{})]
;; Write header with metadata ;; Write header with metadata