0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-09 08:20:45 -05:00

Merge remote-tracking branch 'origin/staging' into develop

This commit is contained in:
Andrey Antukh 2024-07-26 08:36:30 +02:00
commit 3eaa997145
8 changed files with 35 additions and 41 deletions

View file

@ -150,8 +150,8 @@
[["" {:middleware [[mw/server-timing] [["" {:middleware [[mw/server-timing]
[mw/params] [mw/params]
[mw/format-response] [mw/format-response]
[mw/errors errors/handle]
[mw/parse-request] [mw/parse-request]
[mw/errors errors/handle]
[session/soft-auth cfg] [session/soft-auth cfg]
[actoken/soft-auth cfg] [actoken/soft-auth cfg]
[mw/restrict-methods]]} [mw/restrict-methods]]}

View file

@ -14,32 +14,28 @@
[app.http :as-alias http] [app.http :as-alias http]
[app.http.access-token :as-alias actoken] [app.http.access-token :as-alias actoken]
[app.http.session :as-alias session] [app.http.session :as-alias session]
[app.util.inet :as inet]
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
[cuerdas.core :as str]
[ring.request :as rreq] [ring.request :as rreq]
[ring.response :as rres])) [ring.response :as rres]))
(defn- parse-client-ip
[request]
(or (some-> (rreq/get-header request "x-forwarded-for") (str/split ",") first)
(rreq/get-header request "x-real-ip")
(rreq/remote-addr request)))
(defn request->context (defn request->context
"Extracts error report relevant context data from request." "Extracts error report relevant context data from request."
[request] [request]
(let [claims (-> {} (let [claims (-> {}
(into (::session/token-claims request)) (into (::session/token-claims request))
(into (::actoken/token-claims request)))] (into (::actoken/token-claims request)))]
{:request/path (:path request) {:request/path (:path request)
:request/method (:method request) :request/method (:method request)
:request/params (:params request) :request/params (:params request)
:request/user-agent (rreq/get-header request "user-agent") :request/user-agent (rreq/get-header request "user-agent")
:request/ip-addr (parse-client-ip request) :request/ip-addr (inet/parse-request request)
:request/profile-id (:uid claims) :request/profile-id (:uid claims)
:version/frontend (or (rreq/get-header request "x-frontend-version") "unknown") :version/frontend (or (rreq/get-header request "x-frontend-version") "unknown")
:version/backend (:full cf/version)})) :version/backend (:full cf/version)}))
(defmulti handle-error (defmulti handle-error
(fn [cause _ _] (fn [cause _ _]
(-> cause ex-data :type))) (-> cause ex-data :type)))

View file

@ -10,6 +10,7 @@
[app.common.logging :as l] [app.common.logging :as l]
[app.common.transit :as t] [app.common.transit :as t]
[app.config :as cf] [app.config :as cf]
[app.http.errors :as errors]
[clojure.data.json :as json] [clojure.data.json :as json]
[cuerdas.core :as str] [cuerdas.core :as str]
[ring.request :as rreq] [ring.request :as rreq]
@ -70,12 +71,12 @@
:else :else
request))) request)))
(handle-error [cause] (handle-error [cause request]
(cond (cond
(instance? RuntimeException cause) (instance? RuntimeException cause)
(if-let [cause (ex-cause cause)] (if-let [cause (ex-cause cause)]
(handle-error cause) (handle-error cause request)
(throw cause)) (errors/handle cause request))
(instance? RequestTooBigException cause) (instance? RequestTooBigException cause)
(ex/raise :type :validation (ex/raise :type :validation
@ -89,14 +90,14 @@
:cause cause) :cause cause)
:else :else
(throw cause)))] (errors/handle cause request)))]
(fn [request] (fn [request]
(if (= (rreq/method request) :post) (if (= (rreq/method request) :post)
(let [request (ex/try! (process-request request))] (try
(if (ex/exception? request) (-> request process-request handler)
(handle-error request) (catch Throwable cause
(handler request))) (handle-error cause request)))
(handler request))))) (handler request)))))
(def parse-request (def parse-request

View file

@ -657,7 +657,7 @@
f.modified_at, f.modified_at,
f.name, f.name,
f.is_shared, f.is_shared,
ft.media_id, ft.media_id AS thumbnail_id,
row_number() over w as row_num row_number() over w as row_num
from file as f from file as f
inner join project as p on (p.id = f.project_id) inner join project as p on (p.id = f.project_id)
@ -676,10 +676,8 @@
[conn team-id] [conn team-id]
(->> (db/exec! conn [sql:team-recent-files team-id]) (->> (db/exec! conn [sql:team-recent-files team-id])
(mapv (fn [row] (mapv (fn [row]
(if-let [media-id (:media-id row)] (if-let [media-id (:thumbnail-id row)]
(-> row (assoc row :thumbnail-uri (resolve-public-uri media-id))
(dissoc :media-id)
(assoc :thumbnail-uri (resolve-public-uri media-id)))
(dissoc row :media-id)))))) (dissoc row :media-id))))))
(def ^:private schema:get-team-recent-files (def ^:private schema:get-team-recent-files

View file

@ -407,4 +407,5 @@
(when-not (db/read-only? conn) (when-not (db/read-only? conn)
(let [cfg (update cfg ::sto/storage media/configure-assets-storage) (let [cfg (update cfg ::sto/storage media/configure-assets-storage)
media (create-file-thumbnail! cfg params)] media (create-file-thumbnail! cfg params)]
{:uri (files/resolve-public-uri (:id media))}))))) {:uri (files/resolve-public-uri (:id media))
:id (:id media)})))))

View file

@ -898,8 +898,7 @@
(-> state (-> state
(d/update-in-when [:dashboard-files id :is-shared] (constantly is-shared)) (d/update-in-when [:dashboard-files id :is-shared] (constantly is-shared))
(d/update-in-when [:dashboard-recent-files id :is-shared] (constantly is-shared)) (d/update-in-when [:dashboard-recent-files id :is-shared] (constantly is-shared))
(cond-> (cond-> (not is-shared)
(not is-shared)
(d/update-when :dashboard-shared-files dissoc id)))) (d/update-when :dashboard-shared-files dissoc id))))
ptk/WatchEvent ptk/WatchEvent
@ -909,7 +908,7 @@
(rx/ignore)))))) (rx/ignore))))))
(defn set-file-thumbnail (defn set-file-thumbnail
[file-id thumbnail-uri] [file-id thumbnail-id]
(ptk/reify ::set-file-thumbnail (ptk/reify ::set-file-thumbnail
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
@ -917,10 +916,10 @@
(->> files (->> files
(mapv #(cond-> % (mapv #(cond-> %
(= file-id (:id %)) (= file-id (:id %))
(assoc :thumbnail-uri thumbnail-uri)))))] (assoc :thumbnail-id thumbnail-id)))))]
(-> state (-> state
(d/update-in-when [:dashboard-files file-id] assoc :thumbnail-uri thumbnail-uri) (d/update-in-when [:dashboard-files file-id] assoc :thumbnail-id thumbnail-id)
(d/update-in-when [:dashboard-recent-files file-id] assoc :thumbnail-uri thumbnail-uri) (d/update-in-when [:dashboard-recent-files file-id] assoc :thumbnail-id thumbnail-id)
(d/update-when :dashboard-search-result update-search-files)))))) (d/update-when :dashboard-search-result update-search-files))))))
;; --- EVENT: create-file ;; --- EVENT: create-file

View file

@ -12,7 +12,6 @@
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.main.data.changes :as dch] [app.main.data.changes :as dch]
[app.main.repo :as rp] [app.main.repo :as rp]
[app.util.router :as rt]
[beicon.v2.core :as rx] [beicon.v2.core :as rx]
[potok.v2.core :as ptk])) [potok.v2.core :as ptk]))
@ -131,8 +130,7 @@
(rx/concat (rx/concat
(if (= :authentication (:type cause)) (if (= :authentication (:type cause))
(rx/empty) (rx/empty)
(rx/of (rt/assign-exception cause) (rx/of (ptk/data-event ::error cause)
(ptk/data-event ::error cause)
(update-status :error))) (update-status :error)))
(rx/of (discard-persistence-state)) (rx/of (discard-persistence-state))
(rx/throw cause)))))))))) (rx/throw cause))))))))))

View file

@ -11,6 +11,7 @@
[app.common.data.macros :as dm] [app.common.data.macros :as dm]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.logging :as log] [app.common.logging :as log]
[app.config :as cf]
[app.main.data.dashboard :as dd] [app.main.data.dashboard :as dd]
[app.main.data.messages :as msg] [app.main.data.messages :as msg]
[app.main.features :as features] [app.main.features :as features]
@ -47,7 +48,7 @@
[file-id revn blob] [file-id revn blob]
(let [params {:file-id file-id :revn revn :media blob}] (let [params {:file-id file-id :revn revn :media blob}]
(->> (rp/cmd! :create-file-thumbnail params) (->> (rp/cmd! :create-file-thumbnail params)
(rx/map :uri)))) (rx/map :id))))
(defn render-thumbnail (defn render-thumbnail
[file-id revn] [file-id revn]
@ -71,15 +72,15 @@
(mf/defc grid-item-thumbnail (mf/defc grid-item-thumbnail
{::mf/wrap-props false} {::mf/wrap-props false}
[{:keys [file-id revn thumbnail-uri background-color]}] [{:keys [file-id revn thumbnail-id background-color]}]
(let [container (mf/use-ref) (let [container (mf/use-ref)
visible? (h/use-visible container :once? true)] visible? (h/use-visible container :once? true)]
(mf/with-effect [file-id revn visible? thumbnail-uri] (mf/with-effect [file-id revn visible? thumbnail-id]
(when (and visible? (not thumbnail-uri)) (when (and visible? (not thumbnail-id))
(->> (ask-for-thumbnail file-id revn) (->> (ask-for-thumbnail file-id revn)
(rx/subs! (fn [url] (rx/subs! (fn [thumbnail-id]
(st/emit! (dd/set-file-thumbnail file-id url))) (st/emit! (dd/set-file-thumbnail file-id thumbnail-id)))
(fn [cause] (fn [cause]
(log/error :hint "unable to render thumbnail" (log/error :hint "unable to render thumbnail"
:file-if file-id :file-if file-id
@ -90,9 +91,9 @@
:style {:background-color background-color} :style {:background-color background-color}
:ref container} :ref container}
(when visible? (when visible?
(if thumbnail-uri (if thumbnail-id
[:img {:class (stl/css :grid-item-thumbnail-image) [:img {:class (stl/css :grid-item-thumbnail-image)
:src thumbnail-uri :src (cf/resolve-media thumbnail-id)
:loading "lazy" :loading "lazy"
:decoding "async"}] :decoding "async"}]
i/loader-pencil))])) i/loader-pencil))]))
@ -365,7 +366,7 @@
[:& grid-item-thumbnail [:& grid-item-thumbnail
{:file-id (:id file) {:file-id (:id file)
:revn (:revn file) :revn (:revn file)
:thumbnail-uri (:thumbnail-uri file) :thumbnail-id (:thumbnail-id file)
:background-color (dm/get-in file [:data :options :background])}]) :background-color (dm/get-in file [:data :options :background])}])
(when (and (:is-shared file) (not library-view?)) (when (and (:is-shared file) (not library-view?))