mirror of
https://github.com/penpot/penpot.git
synced 2025-08-03 06:28:31 +02:00
🔥 Remove a lot of obsolete code
This commit is contained in:
parent
b1b3ad61a5
commit
d349e46cd8
43 changed files with 174 additions and 3689 deletions
|
@ -40,8 +40,7 @@
|
|||
|
||||
;; --- Constants & Helpers
|
||||
|
||||
(def ^:const +images-uuid-ns+ #uuid "3642a582-565f-4070-beba-af797ab27a6a")
|
||||
(def ^:const +icons-uuid-ns+ #uuid "3642a582-565f-4070-beba-af797ab27a6b")
|
||||
(def ^:const +graphics-uuid-ns+ #uuid "3642a582-565f-4070-beba-af797ab27a6a")
|
||||
(def ^:const +colors-uuid-ns+ #uuid "3642a582-565f-4070-beba-af797ab27a6c")
|
||||
|
||||
(s/def ::id ::us/uuid)
|
||||
|
@ -49,16 +48,7 @@
|
|||
(s/def ::path ::us/string)
|
||||
(s/def ::regex #(instance? java.util.regex.Pattern %))
|
||||
|
||||
;; (s/def ::colors
|
||||
;; (s/* (s/cat :name ::us/string :color ::us/color)))
|
||||
;;
|
||||
;; (s/def ::import-item-media
|
||||
;; (s/keys :req-un [::name ::path ::regex]))
|
||||
;;
|
||||
;; (s/def ::import-item-color
|
||||
;; (s/keys :req-un [::name ::id ::colors]))
|
||||
|
||||
(s/def ::import-images
|
||||
(s/def ::import-graphics
|
||||
(s/keys :req-un [::path ::regex]))
|
||||
|
||||
(s/def ::import-color
|
||||
|
@ -68,225 +58,23 @@
|
|||
|
||||
(s/def ::import-library
|
||||
(s/keys :req-un [::name]
|
||||
:opt-un [::import-images ::import-colors]))
|
||||
:opt-un [::import-graphics ::import-colors]))
|
||||
|
||||
(defn exit!
|
||||
([] (exit! 0))
|
||||
([code]
|
||||
(System/exit code)))
|
||||
|
||||
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; ;; Icons Libraries Importer
|
||||
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;
|
||||
;; (defn- icon-library-exists?
|
||||
;; [conn id]
|
||||
;; (s/assert ::us/uuid id)
|
||||
;; (let [row (db/get-by-id conn :icon-library id)]
|
||||
;; (if row true false)))
|
||||
;;
|
||||
;; (defn- create-icons-library
|
||||
;; [conn {:keys [name] :as item}]
|
||||
;; (let [id (uuid/namespaced +icons-uuid-ns+ name)]
|
||||
;; (log/info "Creating icons library:" name)
|
||||
;; (icons/create-library conn {:team-id uuid/zero
|
||||
;; :id id
|
||||
;; :name name})))
|
||||
;;
|
||||
;; (defn- create-icons-library-if-not-exists
|
||||
;; [conn {:keys [name] :as item}]
|
||||
;; (let [id (uuid/namespaced +icons-uuid-ns+ name)]
|
||||
;; (when-not (icon-library-exists? conn id)
|
||||
;; (create-icons-library conn item))
|
||||
;; id))
|
||||
;;
|
||||
;; (defn- create-icon
|
||||
;; [conn library-id icon-id localpath]
|
||||
;; (s/assert fs/path? localpath)
|
||||
;; (s/assert ::us/uuid library-id)
|
||||
;; (s/assert ::us/uuid icon-id)
|
||||
;; (let [filename (fs/name localpath)
|
||||
;; extension (second (fs/split-ext filename))
|
||||
;; data (svg/parse localpath)
|
||||
;; mdata (select-keys data [:width :height :view-box])]
|
||||
;;
|
||||
;; (log/info "Creating or updating icon" filename icon-id)
|
||||
;; (icons/create-icon conn {:id icon-id
|
||||
;; :library-id library-id
|
||||
;; :name (:name data filename)
|
||||
;; :content (:content data)
|
||||
;; :metadata mdata})))
|
||||
;;
|
||||
;; (defn- icon-exists?
|
||||
;; [conn id]
|
||||
;; (s/assert ::us/uuid id)
|
||||
;; (let [row (db/get-by-id conn :icon id)]
|
||||
;; (if row true false)))
|
||||
;;
|
||||
;; (defn- import-icon-if-not-exists
|
||||
;; [conn library-id fpath]
|
||||
;; (s/assert ::us/uuid library-id)
|
||||
;; (s/assert fs/path? fpath)
|
||||
;; (let [icon-id (uuid/namespaced +icons-uuid-ns+ (str library-id (fs/name fpath)))]
|
||||
;; (when-not (icon-exists? conn icon-id)
|
||||
;; (create-icon conn library-id icon-id fpath))
|
||||
;; icon-id))
|
||||
;;
|
||||
;; (defn- import-icons
|
||||
;; [conn library-id {:keys [path regex] :as item}]
|
||||
;; (run! (fn [fpath]
|
||||
;; (when (re-matches regex (str fpath))
|
||||
;; (import-icon-if-not-exists conn library-id fpath)))
|
||||
;; (->> (fs/list-dir path)
|
||||
;; (filter fs/regular-file?))))
|
||||
;;
|
||||
;; (defn- process-icons-library
|
||||
;; [conn basedir {:keys [path regex] :as item}]
|
||||
;; (s/assert ::import-item-media item)
|
||||
;; (let [library-id (create-icons-library-if-not-exists conn item)]
|
||||
;; (->> (assoc item :path (fs/join basedir path))
|
||||
;; (import-icons conn library-id))))
|
||||
;;
|
||||
;;
|
||||
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; ;; --- Images Libraries Importer
|
||||
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;
|
||||
;; (defn- image-library-exists?
|
||||
;; [conn id]
|
||||
;; (s/assert ::us/uuid id)
|
||||
;; (let [row (db/get-by-id conn :image-library id)]
|
||||
;; (if row true false)))
|
||||
;;
|
||||
;; (defn- create-images-library
|
||||
;; [conn {:keys [name] :as item}]
|
||||
;; (let [id (uuid/namespaced +images-uuid-ns+ name)]
|
||||
;; (log/info "Creating image library:" name)
|
||||
;; (media/create-library conn {:id id
|
||||
;; :team-id uuid/zero
|
||||
;; :name name})))
|
||||
;;
|
||||
;; (defn- create-images-library-if-not-exists
|
||||
;; [conn {:keys [name] :as item}]
|
||||
;; (let [id (uuid/namespaced +images-uuid-ns+ name)]
|
||||
;; (when-not (image-library-exists? conn id)
|
||||
;; (create-images-library conn item)
|
||||
;; id)))
|
||||
;;
|
||||
;; (defn- create-image
|
||||
;; [conn library-id image-id localpath]
|
||||
;; (s/assert fs/path? localpath)
|
||||
;; (s/assert ::us/uuid library-id)
|
||||
;; (s/assert ::us/uuid image-id)
|
||||
;; (let [filename (fs/name localpath)
|
||||
;; extension (second (fs/split-ext filename))
|
||||
;; file (io/as-file localpath)
|
||||
;; mtype (case extension
|
||||
;; ".jpg" "image/jpeg"
|
||||
;; ".png" "image/png"
|
||||
;; ".webp" "image/webp")]
|
||||
;; (log/info "Creating image" filename image-id)
|
||||
;; (media/create-image conn {:content {:tempfile localpath
|
||||
;; :filename filename
|
||||
;; :content-type mtype
|
||||
;; :size (.length file)}
|
||||
;; :id image-id
|
||||
;; :library-id library-id
|
||||
;; :user uuid/zero
|
||||
;; :name filename})))
|
||||
;;
|
||||
;; (defn- image-exists?
|
||||
;; [conn id]
|
||||
;; (s/assert ::us/uuid id)
|
||||
;; (let [row (db/get-by-id conn :image id)]
|
||||
;; (if row true false)))
|
||||
;;
|
||||
;; (defn- import-image-if-not-exists
|
||||
;; [conn library-id fpath]
|
||||
;; (s/assert ::us/uuid library-id)
|
||||
;; (s/assert fs/path? fpath)
|
||||
;; (let [image-id (uuid/namespaced +images-uuid-ns+ (str library-id (fs/name fpath)))]
|
||||
;; (when-not (image-exists? conn image-id)
|
||||
;; (create-image conn library-id image-id fpath))
|
||||
;; image-id))
|
||||
;;
|
||||
;; (defn- import-images
|
||||
;; [conn library-id {:keys [path regex] :as item}]
|
||||
;; (run! (fn [fpath]
|
||||
;; (when (re-matches regex (str fpath))
|
||||
;; (import-image-if-not-exists conn library-id fpath)))
|
||||
;; (->> (fs/list-dir path)
|
||||
;; (filter fs/regular-file?))))
|
||||
;;
|
||||
;; (defn- process-images-library
|
||||
;; [conn basedir {:keys [path regex] :as item}]
|
||||
;; (s/assert ::import-item-media item)
|
||||
;; (let [library-id (create-images-library-if-not-exists conn item)]
|
||||
;; (->> (assoc item :path (fs/join basedir path))
|
||||
;; (import-images conn library-id))))
|
||||
;;
|
||||
;;
|
||||
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; ;; Colors Libraries Importer
|
||||
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;
|
||||
;; (defn- color-library-exists?
|
||||
;; [conn id]
|
||||
;; (s/assert ::us/uuid id)
|
||||
;; (let [row (db/get-by-id conn :file id)]
|
||||
;; (if row true false)))
|
||||
;;
|
||||
;; (defn- create-colors-library
|
||||
;; [conn {:keys [name] :as item}]
|
||||
;; (let [id (uuid/namespaced +colors-uuid-ns+ name)]
|
||||
;; (log/info "Creating color library:" name)
|
||||
;; (colors/create-library conn {:id id
|
||||
;; :team-id uuid/zero
|
||||
;; :name name})))
|
||||
;;
|
||||
;;
|
||||
;; (defn- create-colors-library-if-not-exists
|
||||
;; [conn {:keys [name] :as item}]
|
||||
;; (let [id (uuid/namespaced +colors-uuid-ns+ name)]
|
||||
;; (when-not (color-library-exists? conn id)
|
||||
;; (create-colors-library conn item))
|
||||
;; id))
|
||||
;;
|
||||
;; (defn- create-color
|
||||
;; [conn library-id name content]
|
||||
;; (s/assert ::us/uuid library-id)
|
||||
;; (s/assert ::us/color content)
|
||||
;; (let [color-id (uuid/namespaced +colors-uuid-ns+ (str library-id content))]
|
||||
;; (log/info "Creating color" color-id "-" name content)
|
||||
;; (colors/create-color conn {:id color-id
|
||||
;; :library-id library-id
|
||||
;; :name name
|
||||
;; :content content})
|
||||
;; color-id))
|
||||
;;
|
||||
;; (defn- import-colors
|
||||
;; [conn library-id {:keys [colors] :as item}]
|
||||
;; (db/delete! conn :color {:library-id library-id})
|
||||
;; (run! (fn [[name content]]
|
||||
;; (create-color conn library-id name content))
|
||||
;; (partition-all 2 colors)))
|
||||
;;
|
||||
;; (defn- process-colors-library
|
||||
;; [conn {:keys [name id colors] :as item}]
|
||||
;; (us/verify ::import-item-color item)
|
||||
;; (let [library-id (create-colors-library-if-not-exists conn item)]
|
||||
;; (import-colors conn library-id item)))
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Images Importer
|
||||
;; Graphics Importer
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defn- create-image
|
||||
[conn file-id image-id localpath]
|
||||
(defn- create-media-object
|
||||
[conn file-id media-object-id localpath]
|
||||
(s/assert fs/path? localpath)
|
||||
(s/assert ::us/uuid file-id)
|
||||
(s/assert ::us/uuid image-id)
|
||||
(s/assert ::us/uuid media-object-id)
|
||||
(let [filename (fs/name localpath)
|
||||
extension (second (fs/split-ext filename))
|
||||
file (io/as-file localpath)
|
||||
|
@ -295,36 +83,36 @@
|
|||
".png" "image/png"
|
||||
".webp" "image/webp"
|
||||
".svg" "image/svg+xml")]
|
||||
(log/info "Creating image" filename image-id)
|
||||
(log/info "Creating image" filename media-object-id)
|
||||
(media/create-media-object conn {:content {:tempfile localpath
|
||||
:filename filename
|
||||
:content-type mtype
|
||||
:size (.length file)}
|
||||
:id image-id
|
||||
:id media-object-id
|
||||
:file-id file-id
|
||||
:name filename
|
||||
:is-local false})))
|
||||
|
||||
(defn- image-exists?
|
||||
(defn- media-object-exists?
|
||||
[conn id]
|
||||
(s/assert ::us/uuid id)
|
||||
(let [row (db/get-by-id conn :media-object id)]
|
||||
(if row true false)))
|
||||
|
||||
(defn- import-image-if-not-exists
|
||||
(defn- import-media-object-if-not-exists
|
||||
[conn file-id fpath]
|
||||
(s/assert ::us/uuid file-id)
|
||||
(s/assert fs/path? fpath)
|
||||
(let [image-id (uuid/namespaced +images-uuid-ns+ (str file-id (fs/name fpath)))]
|
||||
(when-not (image-exists? conn image-id)
|
||||
(create-image conn file-id image-id fpath))
|
||||
image-id))
|
||||
(let [media-object-id (uuid/namespaced +graphics-uuid-ns+ (str file-id (fs/name fpath)))]
|
||||
(when-not (media-object-exists? conn media-object-id)
|
||||
(create-media-object conn file-id media-object-id fpath))
|
||||
media-object-id))
|
||||
|
||||
(defn- import-images
|
||||
[conn file-id {:keys [path regex] :as images}]
|
||||
(defn- import-graphics
|
||||
[conn file-id {:keys [path regex] :as graphics}]
|
||||
(run! (fn [fpath]
|
||||
(when (re-matches regex (str fpath))
|
||||
(import-image-if-not-exists conn file-id fpath)))
|
||||
(import-media-object-if-not-exists conn file-id fpath)))
|
||||
(->> (fs/list-dir path)
|
||||
(filter fs/regular-file?))))
|
||||
|
||||
|
@ -371,17 +159,17 @@
|
|||
:profile-id uuid/zero
|
||||
:project-id project-id
|
||||
:name name
|
||||
:shared? true})
|
||||
:is-shared true})
|
||||
(files/create-page conn {:file-id id}))
|
||||
id))
|
||||
|
||||
(defn- process-library
|
||||
[conn basedir project-id {:keys [name images colors] :as library}]
|
||||
[conn basedir project-id {:keys [name graphics colors] :as library}]
|
||||
(us/verify ::import-library library)
|
||||
(let [library-file-id (create-library-file-if-not-exists conn project-id library)]
|
||||
(when images
|
||||
(->> (assoc images :path (fs/join basedir (:path images)))
|
||||
(import-images conn library-file-id)))
|
||||
(when graphics
|
||||
(->> (assoc graphics :path (fs/join basedir (:path graphics)))
|
||||
(import-graphics conn library-file-id)))
|
||||
(when colors
|
||||
(import-colors conn library-file-id colors))))
|
||||
|
||||
|
@ -435,15 +223,6 @@
|
|||
[]
|
||||
(mount/stop))
|
||||
|
||||
;; (defn- importer
|
||||
;; [conn basedir data]
|
||||
;; (let [images (:images data)
|
||||
;; icons (:icons data)
|
||||
;; colors (:colors data)]
|
||||
;; (run! #(process-images-library conn basedir %) images)
|
||||
;; (run! #(process-icons-library conn basedir %) icons)
|
||||
;; (run! #(process-colors-library conn %) colors)))
|
||||
|
||||
(defn run
|
||||
[path]
|
||||
(let [[basedir libraries] (read-file path)]
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
(defn- load-query-services
|
||||
[]
|
||||
;; (require 'uxbox.services.queries.icons)
|
||||
(require 'uxbox.services.queries.media)
|
||||
(require 'uxbox.services.queries.colors)
|
||||
(require 'uxbox.services.queries.projects)
|
||||
|
@ -22,20 +21,17 @@
|
|||
(require 'uxbox.services.queries.pages)
|
||||
(require 'uxbox.services.queries.profile)
|
||||
(require 'uxbox.services.queries.recent-files)
|
||||
(require 'uxbox.services.queries.viewer)
|
||||
)
|
||||
(require 'uxbox.services.queries.viewer))
|
||||
|
||||
(defn- load-mutation-services
|
||||
[]
|
||||
(require 'uxbox.services.mutations.demo)
|
||||
;; (require 'uxbox.services.mutations.icons)
|
||||
(require 'uxbox.services.mutations.media)
|
||||
(require 'uxbox.services.mutations.colors)
|
||||
(require 'uxbox.services.mutations.projects)
|
||||
(require 'uxbox.services.mutations.files)
|
||||
(require 'uxbox.services.mutations.pages)
|
||||
(require 'uxbox.services.mutations.profile)
|
||||
)
|
||||
(require 'uxbox.services.mutations.profile))
|
||||
|
||||
(defstate query-services
|
||||
:start (load-query-services))
|
||||
|
|
|
@ -29,91 +29,6 @@
|
|||
(s/def ::library-id ::us/uuid)
|
||||
(s/def ::content ::us/string)
|
||||
|
||||
|
||||
;; ;; --- Mutation: Create Library
|
||||
;;
|
||||
;; (declare create-library)
|
||||
;;
|
||||
;; (s/def ::create-color-library
|
||||
;; (s/keys :req-un [::profile-id ::team-id ::name]
|
||||
;; :opt-un [::id]))
|
||||
;;
|
||||
;; (sm/defmutation ::create-color-library
|
||||
;; [{:keys [profile-id team-id] :as params}]
|
||||
;; (db/with-atomic [conn db/pool]
|
||||
;; (teams/check-edition-permissions! conn profile-id team-id)
|
||||
;; (create-library conn params)))
|
||||
;;
|
||||
;; (defn create-library
|
||||
;; [conn {:keys [id team-id name]}]
|
||||
;; (let [id (or id (uuid/next))]
|
||||
;; (db/insert! conn :color-library
|
||||
;; {:id id
|
||||
;; :team-id team-id
|
||||
;; :name name})))
|
||||
;;
|
||||
|
||||
;; ;; --- Mutation: Rename Library
|
||||
;;
|
||||
;; (declare select-library-for-update)
|
||||
;; (declare rename-library)
|
||||
;;
|
||||
;; (s/def ::rename-color-library
|
||||
;; (s/keys :req-un [::profile-id ::name ::id]))
|
||||
;;
|
||||
;; (sm/defmutation ::rename-color-library
|
||||
;; [{:keys [id profile-id name] :as params}]
|
||||
;; (db/with-atomic [conn db/pool]
|
||||
;; (let [lib (select-library-for-update conn id)]
|
||||
;; (teams/check-edition-permissions! conn profile-id (:team-id lib))
|
||||
;; (rename-library conn id name))))
|
||||
;;
|
||||
;; (def ^:private sql:select-library-for-update
|
||||
;; "select l.*
|
||||
;; from color_library as l
|
||||
;; where l.id = $1
|
||||
;; for update")
|
||||
;;
|
||||
;; (def ^:private sql:rename-library
|
||||
;; "update color_library
|
||||
;; set name = $2
|
||||
;; where id = $1")
|
||||
;;
|
||||
;; (defn- select-library-for-update
|
||||
;; [conn id]
|
||||
;; (db/get-by-id conn :color-library id {:for-update true}))
|
||||
;;
|
||||
;; (defn- rename-library
|
||||
;; [conn id name]
|
||||
;; (db/update! conn :color-library
|
||||
;; {:name name}
|
||||
;; {:id id}))
|
||||
|
||||
|
||||
;; ;; --- Delete Library
|
||||
;;
|
||||
;; (declare delete-library)
|
||||
;;
|
||||
;; (s/def ::delete-color-library
|
||||
;; (s/keys :req-un [::profile-id ::id]))
|
||||
;;
|
||||
;; (sm/defmutation ::delete-color-library
|
||||
;; [{:keys [id profile-id] :as params}]
|
||||
;; (db/with-atomic [conn db/pool]
|
||||
;; (let [lib (select-library-for-update conn id)]
|
||||
;; (teams/check-edition-permissions! conn profile-id (:team-id lib))
|
||||
;;
|
||||
;; ;; Schedule object deletion
|
||||
;; (tasks/submit! conn {:name "delete-object"
|
||||
;; :delay cfg/default-deletion-delay
|
||||
;; :props {:id id :type :color-library}})
|
||||
;;
|
||||
;; (db/update! conn :color-library
|
||||
;; {:deleted-at (dt/now)}
|
||||
;; {:id id})
|
||||
;; nil)))
|
||||
|
||||
|
||||
;; --- Mutation: Create Color
|
||||
|
||||
(declare select-file-for-update)
|
||||
|
|
|
@ -18,10 +18,7 @@
|
|||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.config :as cfg]
|
||||
[uxbox.db :as db]
|
||||
;; [uxbox.images :as images]
|
||||
;; [uxbox.media :as media]
|
||||
[uxbox.services.mutations :as sm]
|
||||
;; [uxbox.services.mutations.images :as imgs]
|
||||
[uxbox.services.mutations.projects :as proj]
|
||||
[uxbox.services.queries.files :as files]
|
||||
[uxbox.tasks :as tasks]
|
||||
|
@ -152,136 +149,3 @@
|
|||
{:id id})
|
||||
nil)
|
||||
|
||||
|
||||
;; ;; --- Mutations: Create File Image (Upload and create from url)
|
||||
;;
|
||||
;; (declare create-file-image)
|
||||
;;
|
||||
;; (s/def ::file-id ::us/uuid)
|
||||
;; (s/def ::image-id ::us/uuid)
|
||||
;; (s/def ::content ::imgs/upload)
|
||||
;;
|
||||
;; (s/def ::add-file-image-from-url
|
||||
;; (s/keys :req-un [::profile-id ::file-id ::url]
|
||||
;; :opt-un [::id]))
|
||||
;;
|
||||
;; (s/def ::upload-file-image
|
||||
;; (s/keys :req-un [::profile-id ::file-id ::name ::content]
|
||||
;; :opt-un [::id]))
|
||||
;;
|
||||
;; (sm/defmutation ::add-file-image-from-url
|
||||
;; [{:keys [profile-id file-id url] :as params}]
|
||||
;; (db/with-atomic [conn db/pool]
|
||||
;; (files/check-edition-permissions! conn profile-id file-id)
|
||||
;; (let [content (images/download-image url)
|
||||
;; params' (merge params {:content content
|
||||
;; :name (:filename content)})]
|
||||
;; (create-file-image conn params'))))
|
||||
;;
|
||||
;; (sm/defmutation ::upload-file-image
|
||||
;; [{:keys [profile-id file-id] :as params}]
|
||||
;; (db/with-atomic [conn db/pool]
|
||||
;; (files/check-edition-permissions! conn profile-id file-id)
|
||||
;; (create-file-image conn params)))
|
||||
;;
|
||||
;; (defn- create-file-image
|
||||
;; [conn {:keys [content file-id name] :as params}]
|
||||
;; (when-not (imgs/valid-image-types? (:content-type content))
|
||||
;; (ex/raise :type :validation
|
||||
;; :code :media-type-not-allowed
|
||||
;; :hint "Seems like you are uploading an invalid image."))
|
||||
;;
|
||||
;; (let [info (images/run {:cmd :info :input {:path (:tempfile content)
|
||||
;; :mtype (:content-type content)}})
|
||||
;; path (imgs/persist-image-on-fs content)
|
||||
;; opts (assoc imgs/thumbnail-options
|
||||
;; :input {:mtype (:mtype info)
|
||||
;; :path path})
|
||||
;; thumb (if-not (= (:mtype info) "image/svg+xml")
|
||||
;; (imgs/persist-image-thumbnail-on-fs opts)
|
||||
;; (assoc info
|
||||
;; :path path
|
||||
;; :quality 0))]
|
||||
;;
|
||||
;; (-> (db/insert! conn :file-image
|
||||
;; {:file-id file-id
|
||||
;; :name name
|
||||
;; :path (str path)
|
||||
;; :width (:width info)
|
||||
;; :height (:height info)
|
||||
;; :mtype (:mtype info)
|
||||
;; :thumb-path (str (:path thumb))
|
||||
;; :thumb-width (:width thumb)
|
||||
;; :thumb-height (:height thumb)
|
||||
;; :thumb-quality (:quality thumb)
|
||||
;; :thumb-mtype (:mtype thumb)})
|
||||
;; (images/resolve-urls :path :uri)
|
||||
;; (images/resolve-urls :thumb-path :thumb-uri))))
|
||||
;;
|
||||
;;
|
||||
;; ;; --- Mutation: Delete File Image
|
||||
;;
|
||||
;; (declare mark-file-image-deleted)
|
||||
;;
|
||||
;; (s/def ::delete-file-image
|
||||
;; (s/keys :req-un [::file-id ::image-id ::profile-id]))
|
||||
;;
|
||||
;; (sm/defmutation ::delete-file-image
|
||||
;; [{:keys [file-id image-id profile-id] :as params}]
|
||||
;; (db/with-atomic [conn db/pool]
|
||||
;; (files/check-edition-permissions! conn profile-id file-id)
|
||||
;;
|
||||
;; ;; Schedule object deletion
|
||||
;; (tasks/submit! conn {:name "delete-object"
|
||||
;; :delay cfg/default-deletion-delay
|
||||
;; :props {:id image-id :type :file-image}})
|
||||
;;
|
||||
;; (mark-file-image-deleted conn params)))
|
||||
;;
|
||||
;; (defn mark-file-image-deleted
|
||||
;; [conn {:keys [image-id] :as params}]
|
||||
;; (db/update! conn :file-image
|
||||
;; {:deleted-at (dt/now)}
|
||||
;; {:id image-id})
|
||||
;; nil)
|
||||
;;
|
||||
;;
|
||||
;; ;; --- Mutation: Import from collection
|
||||
;;
|
||||
;; (declare copy-image)
|
||||
;; (declare import-image-to-file)
|
||||
;;
|
||||
;; (s/def ::import-image-to-file
|
||||
;; (s/keys :req-un [::image-id ::file-id ::profile-id]))
|
||||
;;
|
||||
;; (sm/defmutation ::import-image-to-file
|
||||
;; [{:keys [image-id file-id profile-id] :as params}]
|
||||
;; (db/with-atomic [conn db/pool]
|
||||
;; (files/check-edition-permissions! conn profile-id file-id)
|
||||
;; (import-image-to-file conn params)))
|
||||
;;
|
||||
;; (defn- import-image-to-file
|
||||
;; [conn {:keys [image-id file-id] :as params}]
|
||||
;; (let [image (db/get-by-id conn :image image-id)
|
||||
;; image-path (copy-image (:path image))
|
||||
;; thumb-path (copy-image (:thumb-path image))]
|
||||
;;
|
||||
;; (-> (db/insert! conn :file-image
|
||||
;; {:file-id file-id
|
||||
;; :name (:name image)
|
||||
;; :path (str image-path)
|
||||
;; :width (:width image)
|
||||
;; :height (:height image)
|
||||
;; :mtype (:mtype image)
|
||||
;; :thumb-path (str thumb-path)
|
||||
;; :thumb-width (:thumb-width image)
|
||||
;; :thumb-height (:thumb-height image)
|
||||
;; :thumb-quality (:thumb-quality image)
|
||||
;; :thumb-mtype (:thumb-mtype image)})
|
||||
;; (images/resolve-urls :path :uri)
|
||||
;; (images/resolve-urls :thumb-path :thumb-uri))))
|
||||
;;
|
||||
;; (defn- copy-image
|
||||
;; [path]
|
||||
;; (let [image-path (ust/lookup media/media-storage path)]
|
||||
;; (ust/save! media/media-storage (fs/name image-path) image-path)))
|
||||
|
|
|
@ -1,206 +0,0 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
;; defined by the Mozilla Public License, v. 2.0.
|
||||
;;
|
||||
;; Copyright (c) 2019-2020 Andrey Antukh <niwi@niwi.nz>
|
||||
|
||||
;; (ns uxbox.services.mutations.icons
|
||||
;; (:require
|
||||
;; [clojure.spec.alpha :as s]
|
||||
;; [uxbox.common.exceptions :as ex]
|
||||
;; [uxbox.common.spec :as us]
|
||||
;; [uxbox.common.uuid :as uuid]
|
||||
;; [uxbox.config :as cfg]
|
||||
;; [uxbox.db :as db]
|
||||
;; [uxbox.services.mutations :as sm]
|
||||
;; [uxbox.services.queries.icons :refer [decode-row]]
|
||||
;; [uxbox.services.queries.teams :as teams]
|
||||
;; [uxbox.tasks :as tasks]
|
||||
;; [uxbox.util.blob :as blob]
|
||||
;; [uxbox.util.time :as dt]))
|
||||
;;
|
||||
;; ;; --- Helpers & Specs
|
||||
;;
|
||||
;; (s/def ::height ::us/integer)
|
||||
;; (s/def ::id ::us/uuid)
|
||||
;; (s/def ::library-id ::us/uuid)
|
||||
;; (s/def ::name ::us/string)
|
||||
;; (s/def ::profile-id ::us/uuid)
|
||||
;; (s/def ::team-id ::us/uuid)
|
||||
;; (s/def ::width ::us/integer)
|
||||
;;
|
||||
;; (s/def ::view-box
|
||||
;; (s/and (s/coll-of number?)
|
||||
;; #(= 4 (count %))
|
||||
;; vector?))
|
||||
;;
|
||||
;; (s/def ::content ::us/string)
|
||||
;; (s/def ::mimetype ::us/string)
|
||||
;;
|
||||
;; (s/def ::metadata
|
||||
;; (s/keys :opt-un [::width ::height ::view-box ::mimetype]))
|
||||
;;
|
||||
;;
|
||||
;; ;; --- Mutation: Create Library
|
||||
;;
|
||||
;; (declare create-library)
|
||||
;;
|
||||
;; (s/def ::create-icon-library
|
||||
;; (s/keys :req-un [::profile-id ::team-id ::name]
|
||||
;; :opt-un [::id]))
|
||||
;;
|
||||
;; (sm/defmutation ::create-icon-library
|
||||
;; [{:keys [profile-id team-id id name] :as params}]
|
||||
;; (db/with-atomic [conn db/pool]
|
||||
;; (teams/check-edition-permissions! conn profile-id team-id)
|
||||
;; (create-library conn params)))
|
||||
;;
|
||||
;; (def ^:private sql:create-library
|
||||
;; "insert into icon_library (id, team_id, name)
|
||||
;; values ($1, $2, $3)
|
||||
;; returning *;")
|
||||
;;
|
||||
;; (defn create-library
|
||||
;; [conn {:keys [team-id id name] :as params}]
|
||||
;; (let [id (or id (uuid/next))]
|
||||
;; (db/insert! conn :icon-library
|
||||
;; {:id id
|
||||
;; :team-id team-id
|
||||
;; :name name})))
|
||||
;;
|
||||
;;
|
||||
;; ;; --- Mutation: Rename Library
|
||||
;;
|
||||
;; (declare select-library-for-update)
|
||||
;; (declare rename-library)
|
||||
;;
|
||||
;; (s/def ::rename-icon-library
|
||||
;; (s/keys :req-un [::profile-id ::name ::id]))
|
||||
;;
|
||||
;; (sm/defmutation ::rename-icon-library
|
||||
;; [{:keys [id profile-id name] :as params}]
|
||||
;; (db/with-atomic [conn db/pool]
|
||||
;; (let [lib (select-library-for-update conn id)]
|
||||
;; (teams/check-edition-permissions! conn profile-id (:team-id lib))
|
||||
;; (rename-library conn id name))))
|
||||
;;
|
||||
;; (defn- select-library-for-update
|
||||
;; [conn id]
|
||||
;; (db/get-by-id conn :icon-library id {:for-update true}))
|
||||
;;
|
||||
;; (defn- rename-library
|
||||
;; [conn id name]
|
||||
;; (db/update! conn :icon-library
|
||||
;; {:name name}
|
||||
;; {:id id}))
|
||||
;;
|
||||
;; ;; --- Mutation: Delete Library
|
||||
;;
|
||||
;; (declare delete-library)
|
||||
;;
|
||||
;; (s/def ::delete-icon-library
|
||||
;; (s/keys :req-un [::profile-id ::id]))
|
||||
;;
|
||||
;; (sm/defmutation ::delete-icon-library
|
||||
;; [{:keys [profile-id id] :as params}]
|
||||
;; (db/with-atomic [conn db/pool]
|
||||
;; (let [lib (select-library-for-update conn id)]
|
||||
;; (teams/check-edition-permissions! conn profile-id (:team-id lib))
|
||||
;;
|
||||
;; ;; Schedule object deletion
|
||||
;; (tasks/submit! conn {:name "delete-object"
|
||||
;; :delay cfg/default-deletion-delay
|
||||
;; :props {:id id :type :icon-library}})
|
||||
;;
|
||||
;; (db/update! conn :icon-library
|
||||
;; {:deleted-at (dt/now)}
|
||||
;; {:id id})
|
||||
;; nil)))
|
||||
;;
|
||||
;;
|
||||
;; ;; --- Mutation: Create Icon (Upload)
|
||||
;;
|
||||
;; (declare create-icon)
|
||||
;;
|
||||
;; (s/def ::create-icon
|
||||
;; (s/keys :req-un [::profile-id ::name ::metadata ::content ::library-id]
|
||||
;; :opt-un [::id]))
|
||||
;;
|
||||
;; (sm/defmutation ::create-icon
|
||||
;; [{:keys [profile-id library-id] :as params}]
|
||||
;; (db/with-atomic [conn db/pool]
|
||||
;; (let [lib (select-library-for-update conn library-id)]
|
||||
;; (teams/check-edition-permissions! conn profile-id (:team-id lib))
|
||||
;; (create-icon conn params))))
|
||||
;;
|
||||
;; (defn create-icon
|
||||
;; [conn {:keys [id name library-id metadata content]}]
|
||||
;; (let [id (or id (uuid/next))]
|
||||
;; (-> (db/insert! conn :icon
|
||||
;; {:id id
|
||||
;; :name name
|
||||
;; :library-id library-id
|
||||
;; :content content
|
||||
;; :metadata (blob/encode metadata)})
|
||||
;; (decode-row))))
|
||||
;;
|
||||
;;
|
||||
;; ;; --- Mutation: Rename Icon
|
||||
;;
|
||||
;; (declare select-icon-for-update)
|
||||
;; (declare rename-icon)
|
||||
;;
|
||||
;; (s/def ::rename-icon
|
||||
;; (s/keys :req-un [::id ::profile-id ::name]))
|
||||
;;
|
||||
;; (sm/defmutation ::rename-icon
|
||||
;; [{:keys [id profile-id name] :as params}]
|
||||
;; (db/with-atomic [conn db/pool]
|
||||
;; (let [icon (select-icon-for-update conn id)]
|
||||
;; (teams/check-edition-permissions! conn profile-id (:team-id icon))
|
||||
;; (db/update! conn :icon
|
||||
;; {:name name}
|
||||
;; {:id id}))))
|
||||
;;
|
||||
;; (def ^:private
|
||||
;; sql:select-icon-for-update
|
||||
;; "select i.*,
|
||||
;; lib.team_id as team_id
|
||||
;; from icon as i
|
||||
;; inner join icon_library as lib on (lib.id = i.library_id)
|
||||
;; where i.id = ?
|
||||
;; for update")
|
||||
;;
|
||||
;; (defn- select-icon-for-update
|
||||
;; [conn id]
|
||||
;; (let [row (db/exec-one! conn [sql:select-icon-for-update id])]
|
||||
;; (when-not row
|
||||
;; (ex/raise :type :not-found))
|
||||
;; row))
|
||||
;;
|
||||
;;
|
||||
;; ;; --- Mutation: Delete Icon
|
||||
;;
|
||||
;; (declare delete-icon)
|
||||
;;
|
||||
;; (s/def ::delete-icon
|
||||
;; (s/keys :req-un [::profile-id ::id]))
|
||||
;;
|
||||
;; (sm/defmutation ::delete-icon
|
||||
;; [{:keys [id profile-id] :as params}]
|
||||
;; (db/with-atomic [conn db/pool]
|
||||
;; (let [icn (select-icon-for-update conn id)]
|
||||
;; (teams/check-edition-permissions! conn profile-id (:team-id icn))
|
||||
;;
|
||||
;; ;; Schedule object deletion
|
||||
;; (tasks/submit! conn {:name "delete-object"
|
||||
;; :delay cfg/default-deletion-delay
|
||||
;; :props {:id id :type :icon}})
|
||||
;;
|
||||
;; (db/update! conn :icon
|
||||
;; {:deleted-at (dt/now)}
|
||||
;; {:id id})
|
||||
;; nil)))
|
|
@ -37,67 +37,6 @@
|
|||
(s/def ::team-id ::us/uuid)
|
||||
(s/def ::url ::us/url)
|
||||
|
||||
;; ;; --- Create Library
|
||||
;;
|
||||
;; (declare create-library)
|
||||
;;
|
||||
;; (s/def ::create-media-object-library
|
||||
;; (s/keys :req-un [::profile-id ::team-id ::name]
|
||||
;; :opt-un [::id]))
|
||||
;;
|
||||
;; (sm/defmutation ::create-media-object-library
|
||||
;; [{:keys [profile-id team-id] :as params}]
|
||||
;; (db/with-atomic [conn db/pool]
|
||||
;; (teams/check-edition-permissions! conn profile-id team-id)
|
||||
;; (create-library conn params)))
|
||||
;;
|
||||
;; (defn create-library
|
||||
;; [conn {:keys [id team-id name]}]
|
||||
;; (let [id (or id (uuid/next))]
|
||||
;; (db/insert! conn :media-object-library
|
||||
;; {:id id
|
||||
;; :team-id team-id
|
||||
;; :name name})))
|
||||
;;
|
||||
;;
|
||||
;; ;; --- Rename Library
|
||||
;;
|
||||
;; (s/def ::rename-media-object-library
|
||||
;; (s/keys :req-un [::id ::profile-id ::name]))
|
||||
;;
|
||||
;; (sm/defmutation ::rename-media-object-library
|
||||
;; [{:keys [profile-id id name] :as params}]
|
||||
;; (db/with-atomic [conn db/pool]
|
||||
;; (let [lib (select-file-for-update conn id)]
|
||||
;; (teams/check-edition-permissions! conn profile-id (:team-id lib))
|
||||
;; (db/update! conn :media-object-library
|
||||
;; {:name name}
|
||||
;; {:id id}))))
|
||||
;;
|
||||
;;
|
||||
;; ;; --- Delete Library
|
||||
;;
|
||||
;; (declare delete-library)
|
||||
;;
|
||||
;; (s/def ::delete-media-object-library
|
||||
;; (s/keys :req-un [::profile-id ::id]))
|
||||
;;
|
||||
;; (sm/defmutation ::delete-media-object-library
|
||||
;; [{:keys [id profile-id] :as params}]
|
||||
;; (db/with-atomic [conn db/pool]
|
||||
;; (let [lib (select-file-for-update conn id)]
|
||||
;; (teams/check-edition-permissions! conn profile-id (:team-id lib))
|
||||
;;
|
||||
;; ;; Schedule object deletion
|
||||
;; (tasks/submit! conn {:name "delete-object"
|
||||
;; :delay cfg/default-deletion-delay
|
||||
;; :props {:id id :type :media-object-library}})
|
||||
;;
|
||||
;; (db/update! conn :media-object-library
|
||||
;; {:deleted-at (dt/now)}
|
||||
;; {:id id})
|
||||
;; nil)))
|
||||
|
||||
|
||||
;; --- Create Media object (Upload and create from url)
|
||||
|
||||
|
|
|
@ -27,55 +27,7 @@
|
|||
(s/def ::profile-id ::us/uuid)
|
||||
(s/def ::team-id ::us/uuid)
|
||||
(s/def ::file-id ::us/uuid)
|
||||
;; (s/def ::library-id (s/nilable ::us/uuid))
|
||||
|
||||
;; ;; --- Query: Colors Libraries
|
||||
;;
|
||||
;; (def ^:private sql:libraries
|
||||
;; "select lib.*,
|
||||
;; (select count(*) from color where library_id = lib.id) as num_colors
|
||||
;; from color_library as lib
|
||||
;; where lib.team_id = ?
|
||||
;; and lib.deleted_at is null
|
||||
;; order by lib.created_at desc")
|
||||
;;
|
||||
;; (s/def ::color-libraries
|
||||
;; (s/keys :req-un [::profile-id ::team-id]))
|
||||
;;
|
||||
;; (sq/defquery ::color-libraries
|
||||
;; [{:keys [profile-id team-id]}]
|
||||
;; (db/with-atomic [conn db/pool]
|
||||
;; (teams/check-read-permissions! conn profile-id team-id)
|
||||
;; (db/exec! conn [sql:libraries team-id])))
|
||||
;;
|
||||
;;
|
||||
;; ;; --- Query: Color Library
|
||||
;;
|
||||
;; (declare retrieve-library)
|
||||
;;
|
||||
;; (s/def ::color-library
|
||||
;; (s/keys :req-un [::profile-id ::id]))
|
||||
;;
|
||||
;; (sq/defquery ::color-library
|
||||
;; [{:keys [profile-id id]}]
|
||||
;; (db/with-atomic [conn db/pool]
|
||||
;; (let [lib (retrieve-library conn id)]
|
||||
;; (teams/check-read-permissions! conn profile-id (:team-id lib))
|
||||
;; lib)))
|
||||
;;
|
||||
;; (def ^:private sql:single-library
|
||||
;; "select lib.*,
|
||||
;; (select count(*) from color where library_id = lib.id) as num_colors
|
||||
;; from color_library as lib
|
||||
;; where lib.deleted_at is null
|
||||
;; and lib.id = ?")
|
||||
;;
|
||||
;; (defn- retrieve-library
|
||||
;; [conn id]
|
||||
;; (let [row (db/exec-one! conn [sql:single-library id])]
|
||||
;; (when-not row
|
||||
;; (ex/raise :type :not-found))
|
||||
;; row))
|
||||
|
||||
;; --- Query: Colors (by file)
|
||||
|
||||
|
|
|
@ -173,6 +173,7 @@
|
|||
(->> (db/exec! db/pool [sql:shared-files])
|
||||
(mapv decode-row)))
|
||||
|
||||
|
||||
;; --- Query: File Permissions
|
||||
|
||||
(def ^:private sql:file-permissions
|
||||
|
@ -220,32 +221,6 @@
|
|||
(ex/raise :type :validation
|
||||
:code :not-authorized))))
|
||||
|
||||
;; ;; --- Query: Images of the File
|
||||
;;
|
||||
;; (declare retrieve-file-images)
|
||||
;;
|
||||
;; (s/def ::file-images
|
||||
;; (s/keys :req-un [::profile-id ::file-id]))
|
||||
;;
|
||||
;; (sq/defquery ::file-images
|
||||
;; [{:keys [profile-id file-id] :as params}]
|
||||
;; (db/with-atomic [conn db/pool]
|
||||
;; (check-edition-permissions! conn profile-id file-id)
|
||||
;; (retrieve-file-images conn params)))
|
||||
;;
|
||||
;; (def ^:private sql:file-images
|
||||
;; "select fi.*
|
||||
;; from file_image as fi
|
||||
;; where fi.file_id = ?
|
||||
;; and fi.deleted_at is null")
|
||||
;;
|
||||
;; (defn retrieve-file-images
|
||||
;; [conn {:keys [file-id] :as params}]
|
||||
;; (let [sqlv [sql:file-images file-id]
|
||||
;; xf (comp (map #(media/resolve-urls % :path :uri))
|
||||
;; (map #(media/resolve-urls % :thumb-path :thumb-uri)))]
|
||||
;; (->> (db/exec! conn sqlv)
|
||||
;; (into [] xf))))
|
||||
|
||||
;; --- Query: File (By ID)
|
||||
|
||||
|
@ -304,6 +279,7 @@
|
|||
(check-edition-permissions! conn profile-id id)
|
||||
(retrieve-file conn id)))
|
||||
|
||||
|
||||
;; --- Helpers
|
||||
|
||||
(defn decode-row
|
||||
|
|
|
@ -1,148 +0,0 @@
|
|||
;; ;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; ;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; ;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;; ;;
|
||||
;; ;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
;; ;; defined by the Mozilla Public License, v. 2.0.
|
||||
;; ;;
|
||||
;; ;; Copyright (c) 2019 Andrey Antukh <niwi@niwi.nz>
|
||||
;;
|
||||
;; (ns uxbox.services.queries.icons
|
||||
;; (:require
|
||||
;; [clojure.spec.alpha :as s]
|
||||
;; [uxbox.common.exceptions :as ex]
|
||||
;; [uxbox.common.spec :as us]
|
||||
;; [uxbox.common.uuid :as uuid]
|
||||
;; [uxbox.db :as db]
|
||||
;; [uxbox.images :as images]
|
||||
;; [uxbox.media :as media]
|
||||
;; [uxbox.services.queries :as sq]
|
||||
;; [uxbox.services.queries.teams :as teams]
|
||||
;; [uxbox.util.blob :as blob]
|
||||
;; [uxbox.util.data :as data]))
|
||||
;;
|
||||
;; ;; --- Helpers & Specs
|
||||
;;
|
||||
;; (s/def ::id ::us/uuid)
|
||||
;; (s/def ::name ::us/string)
|
||||
;; (s/def ::profile-id ::us/uuid)
|
||||
;; (s/def ::library-id ::us/uuid)
|
||||
;; (s/def ::team-id ::us/uuid)
|
||||
;;
|
||||
;; (defn decode-row
|
||||
;; [{:keys [metadata] :as row}]
|
||||
;; (when row
|
||||
;; (cond-> row
|
||||
;; metadata (assoc :metadata (blob/decode metadata)))))
|
||||
;;
|
||||
;; ;; --- Query: Icons Librarys
|
||||
;;
|
||||
;; (def ^:private sql:libraries
|
||||
;; "select lib.*,
|
||||
;; (select count(*) from icon where library_id = lib.id) as num_icons
|
||||
;; from icon_library as lib
|
||||
;; where lib.team_id = ?
|
||||
;; and lib.deleted_at is null
|
||||
;; order by lib.created_at desc")
|
||||
;;
|
||||
;; (s/def ::icon-libraries
|
||||
;; (s/keys :req-un [::profile-id ::team-id]))
|
||||
;;
|
||||
;; (sq/defquery ::icon-libraries
|
||||
;; [{:keys [profile-id team-id]}]
|
||||
;; (db/with-atomic [conn db/pool]
|
||||
;; (teams/check-read-permissions! conn profile-id team-id)
|
||||
;; (db/exec! conn [sql:libraries team-id])))
|
||||
;;
|
||||
;;
|
||||
;;
|
||||
;; ;; --- Query: Icon Library
|
||||
;;
|
||||
;; (declare retrieve-library)
|
||||
;;
|
||||
;; (s/def ::icon-library
|
||||
;; (s/keys :req-un [::profile-id ::id]))
|
||||
;;
|
||||
;; (sq/defquery ::icon-library
|
||||
;; [{:keys [profile-id id]}]
|
||||
;; (db/with-atomic [conn db/pool]
|
||||
;; (let [lib (retrieve-library conn id)]
|
||||
;; (teams/check-read-permissions! conn profile-id (:team-id lib))
|
||||
;; lib)))
|
||||
;;
|
||||
;; (def ^:private sql:single-library
|
||||
;; "select lib.*,
|
||||
;; (select count(*) from icon where library_id = lib.id) as num_icons
|
||||
;; from icon_library as lib
|
||||
;; where lib.deleted_at is null
|
||||
;; and lib.id = ?")
|
||||
;;
|
||||
;; (defn- retrieve-library
|
||||
;; [conn id]
|
||||
;; (let [row (db/exec-one! conn [sql:single-library id])]
|
||||
;; (when-not row
|
||||
;; (ex/raise :type :not-found))
|
||||
;; row))
|
||||
;;
|
||||
;;
|
||||
;;
|
||||
;; ;; --- Query: Icons (by library)
|
||||
;;
|
||||
;; (declare retrieve-icons)
|
||||
;;
|
||||
;; (s/def ::icons
|
||||
;; (s/keys :req-un [::profile-id ::library-id]))
|
||||
;;
|
||||
;; (sq/defquery ::icons
|
||||
;; [{:keys [profile-id library-id] :as params}]
|
||||
;; (db/with-atomic [conn db/pool]
|
||||
;; (let [lib (retrieve-library conn library-id)]
|
||||
;; (teams/check-read-permissions! conn profile-id (:team-id lib))
|
||||
;; (->> (retrieve-icons conn library-id)
|
||||
;; (mapv decode-row)))))
|
||||
;;
|
||||
;; (def ^:private sql:icons
|
||||
;; "select icon.*
|
||||
;; from icon as icon
|
||||
;; inner join icon_library as lib on (lib.id = icon.library_id)
|
||||
;; where icon.deleted_at is null
|
||||
;; and icon.library_id = ?
|
||||
;; order by created_at desc")
|
||||
;;
|
||||
;; (defn- retrieve-icons
|
||||
;; [conn library-id]
|
||||
;; (db/exec! conn [sql:icons library-id]))
|
||||
;;
|
||||
;;
|
||||
;;
|
||||
;; ;; --- Query: Icon (by ID)
|
||||
;;
|
||||
;; (declare retrieve-icon)
|
||||
;;
|
||||
;; (s/def ::id ::us/uuid)
|
||||
;; (s/def ::icon
|
||||
;; (s/keys :req-un [::profile-id ::id]))
|
||||
;;
|
||||
;; (sq/defquery ::icon
|
||||
;; [{:keys [profile-id id] :as params}]
|
||||
;; (db/with-atomic [conn db/pool]
|
||||
;; (let [icon (retrieve-icon conn id)]
|
||||
;; (teams/check-read-permissions! conn profile-id (:team-id icon))
|
||||
;; (decode-row icon))))
|
||||
;;
|
||||
;; (def ^:private sql:single-icon
|
||||
;; "select icon.*,
|
||||
;; lib.team_id as team_id
|
||||
;; from icon as icon
|
||||
;; inner join icon_library as lib on (lib.id = icon.library_id)
|
||||
;; where icon.deleted_at is null
|
||||
;; and icon.id = ?
|
||||
;; order by created_at desc")
|
||||
;;
|
||||
;; (defn retrieve-icon
|
||||
;; [conn id]
|
||||
;; (let [row (db/exec-one! conn [sql:single-icon id])]
|
||||
;; (when-not row
|
||||
;; (ex/raise :type :not-found))
|
||||
;; row))
|
||||
;;
|
|
@ -23,54 +23,6 @@
|
|||
(s/def ::team-id ::us/uuid)
|
||||
(s/def ::file-id ::us/uuid)
|
||||
|
||||
;; ;; --- Query: Media Libraries
|
||||
;;
|
||||
;; (def ^:private sql:libraries
|
||||
;; "select lib.*,
|
||||
;; (select count(*) from media where library_id = lib.id) as num_media
|
||||
;; from media_library as lib
|
||||
;; where lib.team_id = ?
|
||||
;; and lib.deleted_at is null
|
||||
;; order by lib.created_at desc")
|
||||
;;
|
||||
;; (s/def ::media-libraries
|
||||
;; (s/keys :req-un [::profile-id ::team-id]))
|
||||
;;
|
||||
;; (sq/defquery ::media-libraries
|
||||
;; [{:keys [profile-id team-id]}]
|
||||
;; (db/with-atomic [conn db/pool]
|
||||
;; (teams/check-read-permissions! conn profile-id team-id)
|
||||
;; (db/exec! conn [sql:libraries team-id])))
|
||||
;;
|
||||
;;
|
||||
;; ;; --- Query: Media Library
|
||||
;;
|
||||
;; (declare retrieve-library)
|
||||
;;
|
||||
;; (s/def ::media-library
|
||||
;; (s/keys :req-un [::profile-id ::id]))
|
||||
;;
|
||||
;; (sq/defquery ::media-library
|
||||
;; [{:keys [profile-id id]}]
|
||||
;; (db/with-atomic [conn db/pool]
|
||||
;; (let [lib (retrieve-library conn id)]
|
||||
;; (teams/check-read-permissions! conn profile-id (:team-id lib))
|
||||
;; lib)))
|
||||
;;
|
||||
;; (def ^:private sql:single-library
|
||||
;; "select lib.*,
|
||||
;; (select count(*) from media where library_id = lib.id) as num_media
|
||||
;; from media_library as lib
|
||||
;; where lib.deleted_at is null
|
||||
;; and lib.id = ?")
|
||||
;;
|
||||
;; (defn- retrieve-library
|
||||
;; [conn id]
|
||||
;; (let [row (db/exec-one! conn [sql:single-library id])]
|
||||
;; (when-not row
|
||||
;; (ex/raise :type :not-found))
|
||||
;; row))
|
||||
|
||||
|
||||
;; --- Query: Media objects (by file)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue