0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-08 07:50:43 -05:00

♻️ Refactor thumbnails persistence

This commit is contained in:
Aitor 2023-11-08 16:27:23 +01:00 committed by Andrey Antukh
parent a19f5fd305
commit e24309b883
3 changed files with 42 additions and 13 deletions

View file

@ -320,6 +320,41 @@
(delete-file-object-thumbnail! file-id object-id))
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
(def ^:private sql:create-file-thumbnail

View file

@ -91,8 +91,8 @@
(defn clear-thumbnail
([file-id page-id frame-id tag]
(clear-thumbnail file-id (thc/fmt-object-id file-id page-id frame-id tag)))
([file-id object-id]
(clear-thumbnail (thc/fmt-object-id file-id page-id frame-id tag)))
([object-id]
(let [emit-rpc? (volatile! false)]
(ptk/reify ::clear-thumbnail
cljs.core/IDeref
@ -108,14 +108,7 @@
(tm/schedule-on-idle (partial wapi/revoke-uri uri))
(update state :workspace-thumbnails dissoc object-id))
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))))))))
state)))))))
(defn- assoc-thumbnail
[object-id uri]
@ -171,7 +164,7 @@
:object-id object-id
:media blob
:tag (or tag "frame")}]
(rp/cmd! :create-file-object-thumbnail params))))
(rp/cmd! :upsert-file-object-thumbnail params))))
(rx/catch rx/empty)
(rx/ignore)))))
(rx/catch (fn [cause]

View file

@ -47,8 +47,9 @@
(def default-options
{:update-file {:query-params [:id]}
:get-raw-file {:rename-to :get-file :raw-transit? true}
:upsert-file-object-thumbnail {:query-params [:file-id :object-id]}
:create-file-object-thumbnail {:query-params [:file-id :object-id]
:upsert-file-object-thumbnail {:query-params [:file-id :object-id :tag]
:form-data? true}
:create-file-object-thumbnail {:query-params [:file-id :object-id :tag]
:form-data? true}
:create-file-thumbnail