0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-23 23:18:48 -05:00

Add support for icon collection importation.

This commit is contained in:
Andrey Antukh 2016-11-21 18:13:39 +01:00
parent 8ec32ad130
commit c0aa4a042f
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
3 changed files with 33 additions and 31 deletions

View file

@ -22,6 +22,11 @@ values (:id, '00000000-0000-0000-0000-000000000000'::uuid, :name)
do update set name = :name
returning *;
-- :name get-image
select * from images as i
where i.id = :id
and i."user" = '00000000-0000-0000-0000-000000000000'::uuid;
-- :name create-icons-collection
insert into icons_collections (id, "user", name)
values (:id, '00000000-0000-0000-0000-000000000000'::uuid, :name)
@ -29,11 +34,6 @@ values (:id, '00000000-0000-0000-0000-000000000000'::uuid, :name)
do update set name = :name
returning *;
-- :name get-image
select * from images as i
where i.id = :id
and i."user" = '00000000-0000-0000-0000-000000000000'::uuid;
-- :name get-icon
select * from icons as i
where i.id = :id
@ -41,12 +41,13 @@ select * from icons as i
-- :name create-icon :<! :1
insert into icons ("user", name, collection, metadata, content)
values (:user, :name, :collection, :metadata, :content)
values ('00000000-0000-0000-0000-000000000000'::uuid,
:name, :collection, :metadata, :content)
on conflict (id)
do update set name = :name,
content = :content,
metadata = :metadata,
collection = :collection
collection = :collection,
"user" = '00000000-0000-0000-0000-000000000000'::uuid
returning *;

View file

@ -19,8 +19,11 @@
[uxbox.migrations]
[uxbox.media :as media]
[uxbox.cli.sql :as sql]
[uxbox.services.svgparse :as svg]
[uxbox.util.transit :as t]
[uxbox.util.spec :as us]
[uxbox.util.cli :as cli]
[uxbox.util.blob :as blob]
[uxbox.util.uuid :as uuid]
[uxbox.util.data :as data])
(:import [java.io Reader PushbackReader]
@ -60,27 +63,24 @@
(some->> (sc/fetch-one conn sqlv)
(data/normalize-attrs))))
;; (defn- create-icon
;; [conn collid iconid localpath]
;; {:pre [(fs/path? localpath)
;; (uuid? collid)
;; (uuid? imageid)]}
;; (let [filename (fs/base-name localpath)
;; storage media/images-storage
;; [width height] (time (retrieve-image-size localpath))
;; extension (second (fs/split-ext filename))
;; path @(st/save storage filename localpath)
;; params {:name filename
;; :path (str path)
;; :mimetype (case extension
;; ".jpg" "image/jpeg"
;; ".png" "image/png")
;; :width width
;; :height height
;; :collection collid
;; :id imageid}
;; sqlv (sql/create-image params)]
;; (sc/execute conn sqlv)))
(defn- create-icon
[conn collid iconid localpath]
{:pre [(fs/path? localpath)
(uuid? collid)
(uuid? iconid)]}
(let [filename (fs/base-name localpath)
extension (second (fs/split-ext filename))
data (svg/parse localpath)
params {:name (:name data filename)
:content (:content data)
:metadata (-> {:width (:width data)
:height (:height data)
:view-box (:view-box data)}
t/encode blob/encode)
:collection collid
:id iconid}
sqlv (sql/create-icon params)]
(sc/execute conn sqlv)))
(defn- import-icon
[conn id fpath]
@ -88,7 +88,7 @@
(println "Importing icon:" (str fpath))
(let [filename (fs/base-name fpath)
iconid (uuid/namespaced +imates-uuid-ns+ (str id filename))]
#_(create-icon conn id iconid fpath)))
(create-icon conn id iconid fpath)))
(defn- process-icons-entry
[conn basedir {:keys [path regex] :as entry}]
@ -208,7 +208,9 @@
[conn basedir data]
(let [images (:images data)
icons (:icons data)]
(run! #(process-images-entry conn basedir %) images)))
(run! #(process-images-entry conn basedir %) images)
(run! #(process-icons-entry conn basedir %) icons)
#_(throw (ex-info "" {}))))
(defn -main
[& [path]]

View file

@ -86,7 +86,6 @@
(defn parse
[data]
{:pre [(instance? InputStream data)]}
(parse-string (slurp data)))
(defmethod core/query :parse-svg