diff --git a/backend/src/app/rpc/commands/files_thumbnails.clj b/backend/src/app/rpc/commands/files_thumbnails.clj index da5511c65..ccd78687f 100644 --- a/backend/src/app/rpc/commands/files_thumbnails.clj +++ b/backend/src/app/rpc/commands/files_thumbnails.clj @@ -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 diff --git a/frontend/src/app/main/data/workspace/thumbnails.cljs b/frontend/src/app/main/data/workspace/thumbnails.cljs index a25addf60..568126fbf 100644 --- a/frontend/src/app/main/data/workspace/thumbnails.cljs +++ b/frontend/src/app/main/data/workspace/thumbnails.cljs @@ -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] diff --git a/frontend/src/app/main/repo.cljs b/frontend/src/app/main/repo.cljs index 348b606dc..44205ff74 100644 --- a/frontend/src/app/main/repo.cljs +++ b/frontend/src/app/main/repo.cljs @@ -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