0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-12 18:18:24 -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>
<form method="get" action="/dbg/file/export">
<div class="row">
<input type="text" style="width:300px" name="file-id" placeholder="file-id" />
<div class="row set-of-inputs">
<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 class="row">

View file

@ -168,3 +168,12 @@ form .row {
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
[{: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
:code :missing-arguments))
(let [path (-> cfg
(assoc ::binf/file-id file-id)
(assoc ::binf/file-ids file-ids)
(assoc ::binf/embed-assets? embed?)
(assoc ::binf/include-libraries? libs?)
(binf/export!))]
@ -297,7 +300,7 @@
(yrs/response
:status 200
: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))))))

View file

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