From c0aa4a042f98aeeea7c297957e432a3a25646f95 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 21 Nov 2016 18:13:39 +0100 Subject: [PATCH] Add support for icon collection importation. --- backend/resources/sql/cli.sql | 15 ++++---- backend/src/uxbox/cli/collimp.clj | 48 +++++++++++++------------ backend/src/uxbox/services/svgparse.clj | 1 - 3 files changed, 33 insertions(+), 31 deletions(-) diff --git a/backend/resources/sql/cli.sql b/backend/resources/sql/cli.sql index 65e3e30c5..0952d5c40 100644 --- a/backend/resources/sql/cli.sql +++ b/backend/resources/sql/cli.sql @@ -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 :> (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]] diff --git a/backend/src/uxbox/services/svgparse.clj b/backend/src/uxbox/services/svgparse.clj index a41b6a2cf..eaf6555bd 100644 --- a/backend/src/uxbox/services/svgparse.clj +++ b/backend/src/uxbox/services/svgparse.clj @@ -86,7 +86,6 @@ (defn parse [data] - {:pre [(instance? InputStream data)]} (parse-string (slurp data))) (defmethod core/query :parse-svg