mirror of
https://github.com/penpot/penpot.git
synced 2025-06-07 04:21:39 +02:00
🔥 Remove legacy-zip exportation support
This commit is contained in:
parent
1a01c9ee4a
commit
dc7e53881a
5 changed files with 47 additions and 494 deletions
|
@ -8,49 +8,11 @@
|
|||
"Helpers for make zip file (using jszip)."
|
||||
(:require
|
||||
["jszip" :as zip]
|
||||
[app.util.http :as http]
|
||||
[beicon.v2.core :as rx]
|
||||
[promesa.core :as p]))
|
||||
|
||||
(defn compress-files
|
||||
[files]
|
||||
(letfn [(attach-file [zobj [name content]]
|
||||
(.file zobj name content))]
|
||||
(let [zobj (zip.)]
|
||||
(run! (partial attach-file zobj) files)
|
||||
(->> (.generateAsync zobj #js {:type "blob"})
|
||||
(rx/from)))))
|
||||
|
||||
(defn load-from-url
|
||||
"Loads the data from a blob url"
|
||||
[url]
|
||||
(->> (http/send!
|
||||
{:uri url
|
||||
:response-type :blob
|
||||
:method :get})
|
||||
(rx/map :body)
|
||||
(rx/merge-map zip/loadAsync)))
|
||||
|
||||
(defn- process-file
|
||||
[entry path type]
|
||||
;; (js/console.log "zip:process-file" entry path type)
|
||||
(cond
|
||||
(nil? entry)
|
||||
(p/rejected (str "File not found: " path))
|
||||
|
||||
(.-dir ^js entry)
|
||||
(p/resolved {:dir path})
|
||||
|
||||
:else
|
||||
(->> (.async ^js entry type)
|
||||
(p/fmap (fn [content]
|
||||
;; (js/console.log "zip:process-file" 2 content)
|
||||
{:path path
|
||||
:content content})))))
|
||||
|
||||
(defn load
|
||||
[data]
|
||||
(rx/from (zip/loadAsync data)))
|
||||
(zip/loadAsync data))
|
||||
|
||||
(defn get-file
|
||||
"Gets a single file from the zip archive"
|
||||
|
@ -58,19 +20,17 @@
|
|||
(get-file zip path "text"))
|
||||
|
||||
([zip path type]
|
||||
(-> (.file zip path)
|
||||
(process-file path type)
|
||||
(rx/from))))
|
||||
(let [entry (.file zip path)]
|
||||
(cond
|
||||
(nil? entry)
|
||||
(p/rejected (str "File not found: " path))
|
||||
|
||||
(defn extract-files
|
||||
"Creates a stream that will emit values for every file in the zip"
|
||||
[zip]
|
||||
(let [promises (atom [])
|
||||
get-file
|
||||
(fn [path entry]
|
||||
(let [current (process-file entry path "text")]
|
||||
(swap! promises conj current)))]
|
||||
(.forEach zip get-file)
|
||||
(.-dir ^js entry)
|
||||
(p/resolved {:dir path})
|
||||
|
||||
(->> (rx/from (p/all @promises))
|
||||
(rx/merge-map identity))))
|
||||
:else
|
||||
(->> (.async ^js entry type)
|
||||
(p/fmap (fn [content]
|
||||
;; (js/console.log "zip:process-file" 2 content)
|
||||
{:path path
|
||||
:content content})))))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue