0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-11 07:11:32 -05:00

Merge pull request #5250 from penpot/alotor-hotfix-plugins-api-problem

🐛 Fix problem with promises in plugins
This commit is contained in:
Andrey Antukh 2024-11-04 17:27:41 +01:00 committed by GitHub
commit ab4be85669
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 23 additions and 30 deletions

View file

@ -40,8 +40,7 @@
[app.plugins.viewport :as viewport] [app.plugins.viewport :as viewport]
[app.util.code-gen :as cg] [app.util.code-gen :as cg]
[app.util.object :as obj] [app.util.object :as obj]
[beicon.v2.core :as rx] [beicon.v2.core :as rx]))
[promesa.core :as p]))
;; ;;
;; PLUGINS PUBLIC API - The plugins will able to access this functions ;; PLUGINS PUBLIC API - The plugins will able to access this functions
@ -174,7 +173,7 @@
:else :else
(let [file-id (:current-file-id @st/state)] (let [file-id (:current-file-id @st/state)]
(p/create (js/Promise.
(fn [resolve reject] (fn [resolve reject]
(->> (dwm/upload-media-url name file-id url) (->> (dwm/upload-media-url name file-id url)
(rx/take 1) (rx/take 1)
@ -184,7 +183,7 @@
(uploadMediaData (uploadMediaData
[_ name data mime-type] [_ name data mime-type]
(let [file-id (:current-file-id @st/state)] (let [file-id (:current-file-id @st/state)]
(p/create (js/Promise.
(fn [resolve reject] (fn [resolve reject]
(->> (dwm/process-blobs (->> (dwm/process-blobs
{:file-id file-id {:file-id file-id

View file

@ -19,13 +19,12 @@
[app.plugins.shape :as shape] [app.plugins.shape :as shape]
[app.plugins.user :as user] [app.plugins.user :as user]
[app.plugins.utils :as u] [app.plugins.utils :as u]
[beicon.v2.core :as rx] [beicon.v2.core :as rx]))
[promesa.core :as p]))
(deftype CommentProxy [$plugin $file $page $thread $id] (deftype CommentProxy [$plugin $file $page $thread $id]
Object Object
(remove [_] (remove [_]
(p/create (js/Promise.
(fn [resolve reject] (fn [resolve reject]
(cond (cond
(not (r/check-permission $plugin "comment:write")) (not (r/check-permission $plugin "comment:write"))
@ -79,7 +78,7 @@
Object Object
(findComments (findComments
[_] [_]
(p/create (js/Promise.
(fn [resolve reject] (fn [resolve reject]
(cond (cond
(not (r/check-permission $plugin "comment:read")) (not (r/check-permission $plugin "comment:read"))
@ -106,7 +105,7 @@
(u/display-not-valid :reply "Not valid") (u/display-not-valid :reply "Not valid")
:else :else
(p/create (js/Promise.
(fn [resolve reject] (fn [resolve reject]
(->> (rp/cmd! :create-comment {:thread-id $id :content content}) (->> (rp/cmd! :create-comment {:thread-id $id :content content})
(rx/subs! #(resolve (comment-proxy $plugin $file $page $id $users %)) reject)))))) (rx/subs! #(resolve (comment-proxy $plugin $file $page $id $users %)) reject))))))
@ -121,9 +120,9 @@
(u/display-not-valid :remove "Cannot change content from another user's comments") (u/display-not-valid :remove "Cannot change content from another user's comments")
:else :else
(p/create (js/Promise.
(fn [resolve] (fn [resolve]
(p/create (js/Promise.
(st/emit! (dc/delete-comment-thread-on-workspace {:id $id} #(resolve)))))))))) (st/emit! (dc/delete-comment-thread-on-workspace {:id $id} #(resolve))))))))))
(defn comment-thread-proxy? [p] (defn comment-thread-proxy? [p]

View file

@ -20,8 +20,7 @@
[app.plugins.utils :as u] [app.plugins.utils :as u]
[app.util.http :as http] [app.util.http :as http]
[app.util.object :as obj] [app.util.object :as obj]
[beicon.v2.core :as rx] [beicon.v2.core :as rx]))
[promesa.core :as p]))
(deftype FileProxy [$plugin $id] (deftype FileProxy [$plugin $id]
Object Object
@ -128,7 +127,7 @@
file (u/proxy->file self) file (u/proxy->file self)
features (features/get-team-enabled-features @st/state) features (features/get-team-enabled-features @st/state)
team-id (:current-team-id @st/state)] team-id (:current-team-id @st/state)]
(p/create (js/Promise.
(fn [resolve reject] (fn [resolve reject]
(->> (uw/ask-many! (->> (uw/ask-many!
{:cmd export-cmd {:cmd export-cmd

View file

@ -30,8 +30,7 @@
[app.plugins.utils :as u] [app.plugins.utils :as u]
[app.util.object :as obj] [app.util.object :as obj]
[beicon.v2.core :as rx] [beicon.v2.core :as rx]
[potok.v2.core :as ptk] [potok.v2.core :as ptk]))
[promesa.core :as p]))
(declare lib-color-proxy) (declare lib-color-proxy)
(declare lib-typography-proxy) (declare lib-typography-proxy)
@ -915,7 +914,7 @@
(availableLibraries (availableLibraries
[_] [_]
(let [team-id (:current-team-id @st/state)] (let [team-id (:current-team-id @st/state)]
(p/create (js/Promise.
(fn [resolve reject] (fn [resolve reject]
(let [current-libs (into #{} (map first) (get @st/state :workspace-libraries))] (let [current-libs (into #{} (map first) (get @st/state :workspace-libraries))]
(->> (rp/cmd! :get-team-shared-files {:team-id team-id}) (->> (rp/cmd! :get-team-shared-files {:team-id team-id})
@ -939,7 +938,7 @@
(u/display-not-valid :connectLibrary "Plugin doesn't have 'library:write' permission") (u/display-not-valid :connectLibrary "Plugin doesn't have 'library:write' permission")
:else :else
(p/create (js/Promise.
(fn [resolve reject] (fn [resolve reject]
(cond (cond
(not (string? library-id)) (not (string? library-id))

View file

@ -29,8 +29,7 @@
[app.plugins.utils :as u] [app.plugins.utils :as u]
[app.util.object :as obj] [app.util.object :as obj]
[beicon.v2.core :as rx] [beicon.v2.core :as rx]
[cuerdas.core :as str] [cuerdas.core :as str]))
[promesa.core :as p]))
(deftype FlowProxy [$plugin $file $page $id] (deftype FlowProxy [$plugin $file $page $id]
Object Object
@ -288,7 +287,7 @@
(some? board) (some? board)
(-> (update :x - (:x board)) (-> (update :x - (:x board))
(update :y - (:y board))))] (update :y - (:y board))))]
(p/create (js/Promise.
(fn [resolve] (fn [resolve]
(st/emit! (st/emit!
(dc/create-thread-on-workspace (dc/create-thread-on-workspace
@ -315,10 +314,10 @@
(u/display-not-valid :removeCommentThread "Plugin doesn't have 'content:write' permission") (u/display-not-valid :removeCommentThread "Plugin doesn't have 'content:write' permission")
:else :else
(p/create (js/Promise.
(fn [resolve] (fn [resolve]
(let [thread-id (obj/get thread "$id")] (let [thread-id (obj/get thread "$id")]
(p/create (js/Promise.
(st/emit! (dc/delete-comment-thread-on-workspace {:id thread-id} #(resolve))))))))) (st/emit! (dc/delete-comment-thread-on-workspace {:id thread-id} #(resolve)))))))))
(findCommentThreads (findCommentThreads
@ -326,7 +325,7 @@
(let [only-yours (boolean (obj/get criteria "onlyYours" false)) (let [only-yours (boolean (obj/get criteria "onlyYours" false))
show-resolved (boolean (obj/get criteria "showResolved" true)) show-resolved (boolean (obj/get criteria "showResolved" true))
user-id (-> @st/state :profile :id)] user-id (-> @st/state :profile :id)]
(p/create (js/Promise.
(fn [resolve reject] (fn [resolve reject]
(cond (cond
(not (r/check-permission $plugin "comment:read")) (not (r/check-permission $plugin "comment:read"))

View file

@ -52,8 +52,7 @@
[app.util.object :as obj] [app.util.object :as obj]
[app.util.path.format :as upf] [app.util.path.format :as upf]
[beicon.v2.core :as rx] [beicon.v2.core :as rx]
[cuerdas.core :as str] [cuerdas.core :as str]))
[promesa.core :as p]))
(declare shape-proxy) (declare shape-proxy)
(declare shape-proxy?) (declare shape-proxy?)
@ -542,7 +541,7 @@
:type (:type value :png) :type (:type value :png)
:suffix (:suffix value "") :suffix (:suffix value "")
:scale (:scale value 1)}]}] :scale (:scale value 1)}]}]
(p/create (js/Promise.
(fn [resolve reject] (fn [resolve reject]
(->> (rp/cmd! :export payload) (->> (rp/cmd! :export payload)
(rx/mapcat #(rp/cmd! :export {:cmd :get-resource :wait true :id (:id %) :blob? true})) (rx/mapcat #(rp/cmd! :export {:cmd :get-resource :wait true :id (:id %) :blob? true}))

View file

@ -12,8 +12,7 @@
[app.common.types.container :as ctn] [app.common.types.container :as ctn]
[app.common.types.file :as ctf] [app.common.types.file :as ctf]
[app.main.store :as st] [app.main.store :as st]
[app.util.object :as obj] [app.util.object :as obj]))
[promesa.core :as p]))
(defn locate-file (defn locate-file
[id] [id]
@ -175,7 +174,7 @@
[] []
(let [ret-v (atom nil) (let [ret-v (atom nil)
ret-p ret-p
(p/create (js/Promise.
(fn [resolve _] (fn [resolve _]
(add-watch (add-watch
ret-v ret-v