mirror of
https://github.com/penpot/penpot.git
synced 2025-01-09 00:10:11 -05:00
♻️ Refactor thumbnails persistence
This commit is contained in:
parent
a19f5fd305
commit
e24309b883
3 changed files with 42 additions and 13 deletions
|
@ -320,6 +320,41 @@
|
||||||
(delete-file-object-thumbnail! file-id object-id))
|
(delete-file-object-thumbnail! file-id object-id))
|
||||||
nil)))
|
nil)))
|
||||||
|
|
||||||
|
;; --- MUTATION COMMAND: upsert-file-object-thumbnail
|
||||||
|
|
||||||
|
(def ^:private schema:upsert-file-object-thumbnail
|
||||||
|
[:map {:title "upsert-file-object-thumbnail"}
|
||||||
|
[:file-id ::sm/uuid]
|
||||||
|
[:object-id :string]
|
||||||
|
[:media ::media/upload]
|
||||||
|
[:tag {:optional true} :string]])
|
||||||
|
|
||||||
|
(defn- upsert-file-object-thumbnail!
|
||||||
|
[cfg file-id object-id media tag]
|
||||||
|
(delete-file-object-thumbnail! cfg file-id object-id)
|
||||||
|
(create-file-object-thumbnail! cfg file-id object-id media (or tag "frame")))
|
||||||
|
|
||||||
|
(sv/defmethod ::upsert-file-object-thumbnail
|
||||||
|
{::doc/added "1.20"
|
||||||
|
::doc/module :files
|
||||||
|
::climit/id :file-thumbnail-ops
|
||||||
|
::climit/key-fn ::rpc/profile-id
|
||||||
|
::audit/skip true
|
||||||
|
::sm/params schema:upsert-file-object-thumbnail}
|
||||||
|
[{:keys [::db/pool] :as cfg} {:keys [::rpc/profile-id file-id object-id media tag]}]
|
||||||
|
|
||||||
|
(db/with-atomic [conn pool]
|
||||||
|
(files/check-edition-permissions! conn profile-id file-id)
|
||||||
|
(media/validate-media-type! media)
|
||||||
|
(media/validate-media-size! media)
|
||||||
|
|
||||||
|
(when-not (db/read-only? conn)
|
||||||
|
(-> cfg
|
||||||
|
(update ::sto/storage media/configure-assets-storage)
|
||||||
|
(assoc ::db/conn conn)
|
||||||
|
(upsert-file-object-thumbnail! file-id object-id media tag))
|
||||||
|
nil)))
|
||||||
|
|
||||||
;; --- MUTATION COMMAND: create-file-thumbnail
|
;; --- MUTATION COMMAND: create-file-thumbnail
|
||||||
|
|
||||||
(def ^:private sql:create-file-thumbnail
|
(def ^:private sql:create-file-thumbnail
|
||||||
|
|
|
@ -91,8 +91,8 @@
|
||||||
|
|
||||||
(defn clear-thumbnail
|
(defn clear-thumbnail
|
||||||
([file-id page-id frame-id tag]
|
([file-id page-id frame-id tag]
|
||||||
(clear-thumbnail file-id (thc/fmt-object-id file-id page-id frame-id tag)))
|
(clear-thumbnail (thc/fmt-object-id file-id page-id frame-id tag)))
|
||||||
([file-id object-id]
|
([object-id]
|
||||||
(let [emit-rpc? (volatile! false)]
|
(let [emit-rpc? (volatile! false)]
|
||||||
(ptk/reify ::clear-thumbnail
|
(ptk/reify ::clear-thumbnail
|
||||||
cljs.core/IDeref
|
cljs.core/IDeref
|
||||||
|
@ -108,14 +108,7 @@
|
||||||
(tm/schedule-on-idle (partial wapi/revoke-uri uri))
|
(tm/schedule-on-idle (partial wapi/revoke-uri uri))
|
||||||
(update state :workspace-thumbnails dissoc object-id))
|
(update state :workspace-thumbnails dissoc object-id))
|
||||||
|
|
||||||
state)))
|
state)))))))
|
||||||
|
|
||||||
ptk/WatchEvent
|
|
||||||
(watch [_ _ _]
|
|
||||||
(when ^boolean @emit-rpc?
|
|
||||||
(->> (rp/cmd! :delete-file-object-thumbnail {:file-id file-id :object-id object-id})
|
|
||||||
(rx/catch rx/empty)
|
|
||||||
(rx/ignore))))))))
|
|
||||||
|
|
||||||
(defn- assoc-thumbnail
|
(defn- assoc-thumbnail
|
||||||
[object-id uri]
|
[object-id uri]
|
||||||
|
@ -171,7 +164,7 @@
|
||||||
:object-id object-id
|
:object-id object-id
|
||||||
:media blob
|
:media blob
|
||||||
:tag (or tag "frame")}]
|
:tag (or tag "frame")}]
|
||||||
(rp/cmd! :create-file-object-thumbnail params))))
|
(rp/cmd! :upsert-file-object-thumbnail params))))
|
||||||
(rx/catch rx/empty)
|
(rx/catch rx/empty)
|
||||||
(rx/ignore)))))
|
(rx/ignore)))))
|
||||||
(rx/catch (fn [cause]
|
(rx/catch (fn [cause]
|
||||||
|
|
|
@ -47,8 +47,9 @@
|
||||||
(def default-options
|
(def default-options
|
||||||
{:update-file {:query-params [:id]}
|
{:update-file {:query-params [:id]}
|
||||||
:get-raw-file {:rename-to :get-file :raw-transit? true}
|
:get-raw-file {:rename-to :get-file :raw-transit? true}
|
||||||
:upsert-file-object-thumbnail {:query-params [:file-id :object-id]}
|
:upsert-file-object-thumbnail {:query-params [:file-id :object-id :tag]
|
||||||
:create-file-object-thumbnail {:query-params [:file-id :object-id]
|
:form-data? true}
|
||||||
|
:create-file-object-thumbnail {:query-params [:file-id :object-id :tag]
|
||||||
:form-data? true}
|
:form-data? true}
|
||||||
|
|
||||||
:create-file-thumbnail
|
:create-file-thumbnail
|
||||||
|
|
Loading…
Reference in a new issue