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 do update set name = :name
returning *; 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 -- :name create-icons-collection
insert into icons_collections (id, "user", name) insert into icons_collections (id, "user", name)
values (:id, '00000000-0000-0000-0000-000000000000'::uuid, :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 do update set name = :name
returning *; 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 -- :name get-icon
select * from icons as i select * from icons as i
where i.id = :id where i.id = :id
@ -41,12 +41,13 @@ select * from icons as i
-- :name create-icon :<! :1 -- :name create-icon :<! :1
insert into icons ("user", name, collection, metadata, content) 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) on conflict (id)
do update set name = :name, do update set name = :name,
content = :content, content = :content,
metadata = :metadata, metadata = :metadata,
collection = :collection collection = :collection,
"user" = '00000000-0000-0000-0000-000000000000'::uuid "user" = '00000000-0000-0000-0000-000000000000'::uuid
returning *; returning *;

View file

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

View file

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