From 4af76f9a9ac1a032d8f534c496ee8fbef1dd8afc Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 7 Nov 2023 16:31:56 +0100 Subject: [PATCH 1/3] :sparkles: Add backward compatibility layer for features handling --- backend/scripts/repl | 2 -- backend/scripts/start-dev | 2 -- backend/src/app/rpc/commands/files.clj | 35 +++++++------------ backend/src/app/rpc/commands/files_update.clj | 27 +++++++------- backend/src/app/rpc/commands/teams.clj | 9 +++-- 5 files changed, 31 insertions(+), 44 deletions(-) diff --git a/backend/scripts/repl b/backend/scripts/repl index 4eb6680a0..0503d03d6 100755 --- a/backend/scripts/repl +++ b/backend/scripts/repl @@ -11,8 +11,6 @@ export PENPOT_FLAGS="\ enable-login-with-github \ enable-login-with-gitlab \ enable-backend-asserts \ - enable-fdata-storage-pointer-map \ - enable-fdata-storage-objets-map \ enable-audit-log \ enable-transit-readable-response \ enable-demo-users \ diff --git a/backend/scripts/start-dev b/backend/scripts/start-dev index d9ba4b1ce..3e525dfc7 100755 --- a/backend/scripts/start-dev +++ b/backend/scripts/start-dev @@ -11,8 +11,6 @@ export PENPOT_FLAGS="\ enable-audit-log \ enable-transit-readable-response \ enable-demo-users \ - enable-fdata-storage-pointer-map \ - enable-fdata-storage-objets-map \ disable-secure-session-cookies \ enable-smtp \ enable-access-tokens"; diff --git a/backend/src/app/rpc/commands/files.clj b/backend/src/app/rpc/commands/files.clj index 54fb909ad..d3514cdd4 100644 --- a/backend/src/app/rpc/commands/files.clj +++ b/backend/src/app/rpc/commands/files.clj @@ -46,6 +46,11 @@ (def supported-features #{"storage/objects-map" "storage/pointer-map" + "internal/geom-record" + "internal/shape-record" + "fdata/pointer-map" + "fdata/objects-map" + "fdata/shape-data-type" "components/v2"}) (defn get-default-features @@ -250,17 +255,6 @@ (into #{} (comp (filter pmap/pointer-map?) (map pmap/get-id))))) -;; FIXME: file locking -(defn- process-components-v2-feature - "A special case handling of the components/v2 feature." - [{:keys [features data] :as file}] - (let [data (ctf/migrate-to-components-v2 data) - features (conj features "components/v2")] - (-> file - (assoc ::pmg/migrated true) - (assoc :features features) - (assoc :data data)))) - (defn handle-file-features! [{:keys [features] :as file} client-features] @@ -277,22 +271,18 @@ :hint "file has 'components/v2' feature enabled but frontend didn't specifies it" :file-id (:id file))) - ;; This operation is needed because the components migration generates a new - ;; page with random id which is returned to the client; without persisting - ;; the migration this can cause that two simultaneous clients can have a - ;; different view of the file data and end persisting two pages with main - ;; components and breaking the whole file." - (and (contains? client-features "components/v2") - (not (contains? features "components/v2"))) - (as-> file (process-components-v2-feature file)) - ;; This operation is needed for backward comapatibility with frontends that ;; does not support pointer-map resolution mechanism; this just resolves the ;; pointers on backend and return a complete file. (and (contains? features "storage/pointer-map") (not (contains? client-features "storage/pointer-map"))) + (process-pointers deref) + + (and (contains? features "fdata/pointer-map") + (not (contains? client-features "fdata/pointer-map"))) (process-pointers deref))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; QUERY COMMANDS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -350,9 +340,8 @@ file (-> (db/get conn :file params) (decode-row) - (pmg/migrate-file)) - - file (handle-file-features! file client-features)] + (pmg/migrate-file) + (handle-file-features! client-features))] ;; NOTE: when file is migrated, we break the rule of no perform ;; mutations on get operations and update the file with all diff --git a/backend/src/app/rpc/commands/files_update.clj b/backend/src/app/rpc/commands/files_update.clj index 0accca0a3..5cc49366d 100644 --- a/backend/src/app/rpc/commands/files_update.clj +++ b/backend/src/app/rpc/commands/files_update.clj @@ -15,7 +15,6 @@ [app.common.schema :as sm] [app.common.schema.generators :as smg] [app.common.spec :as us] - [app.common.types.file :as ctf] [app.common.uuid :as uuid] [app.config :as cf] [app.db :as db] @@ -201,7 +200,13 @@ (contains? features "storage/pointer-map") (wrap-with-pointer-map-context) + (contains? features "fdata/pointer-map") + (wrap-with-pointer-map-context) + (contains? features "storage/objects-map") + (wrap-with-objects-map-context) + + (contains? features "fdata/objects-map") (wrap-with-objects-map-context)) file (assoc file :features features) @@ -243,20 +248,12 @@ (-> file (update :revn inc) (update :data (fn [data] - (cond-> data - :always - (-> (blob/decode) - (assoc :id (:id file)) - (pmg/migrate-data)) - - (and (contains? ffeat/*current* "components/v2") - (not (contains? ffeat/*previous* "components/v2"))) - (ctf/migrate-to-components-v2) - - :always - (-> (cp/process-changes changes) - (blob/encode))))))) - + (-> data + (blob/decode) + (assoc :id (:id file)) + (pmg/migrate-data) + (cp/process-changes changes) + (blob/encode)))))) (defn- update-file* [{:keys [::db/conn] :as cfg} {:keys [profile-id file changes session-id ::created-at] :as params}] diff --git a/backend/src/app/rpc/commands/teams.clj b/backend/src/app/rpc/commands/teams.clj index e846f0b34..e2e88e620 100644 --- a/backend/src/app/rpc/commands/teams.clj +++ b/backend/src/app/rpc/commands/teams.clj @@ -79,6 +79,11 @@ (def check-read-permissions! (perms/make-check-fn has-read-permissions?)) +(defn decode-row + [{:keys [features] :as row}] + (cond-> row + features (assoc :features (db/decode-pgarray features #{})))) + ;; --- Query: Teams (declare retrieve-teams) @@ -123,6 +128,7 @@ [conn profile-id] (let [profile (profile/get-profile conn profile-id)] (->> (db/exec! conn [sql:teams (:default-team-id profile) profile-id]) + (map decode-row) (mapv process-permissions)))) ;; --- Query: Team (by ID) @@ -148,8 +154,7 @@ (when-not result (ex/raise :type :not-found :code :team-does-not-exist)) - - (process-permissions result))) + (-> result decode-row process-permissions))) ;; --- Query: Team Members From b37acf75ce8ba04338ca0eccb3b0c9a60486e5d0 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 13 Nov 2023 18:27:51 +0100 Subject: [PATCH 2/3] :sparkles: Add the ability to setup custom tempdir on exporter --- exporter/src/app/config.cljs | 1 + exporter/src/app/util/shell.cljs | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/exporter/src/app/config.cljs b/exporter/src/app/config.cljs index 6b9b46925..404a99977 100644 --- a/exporter/src/app/config.cljs +++ b/exporter/src/app/config.cljs @@ -22,6 +22,7 @@ :host "localhost" :http-server-port 6061 :http-server-host "0.0.0.0" + :tempdir "/tmp/penpot-exporter" :redis-uri "redis://redis/0"}) (s/def ::http-server-port ::us/integer) diff --git a/exporter/src/app/util/shell.cljs b/exporter/src/app/util/shell.cljs index 698efbc06..3a7440217 100644 --- a/exporter/src/app/util/shell.cljs +++ b/exporter/src/app/util/shell.cljs @@ -14,6 +14,7 @@ [app.common.exceptions :as ex] [app.common.logging :as l] [app.common.uuid :as uuid] + [app.config :as cf] [cuerdas.core :as str] [promesa.core :as p])) @@ -22,12 +23,12 @@ (def tempfile-minage (* 1000 60 60 1)) ;; 1h (def tmpdir - (let [path (path/join (os/tmpdir) "penpot")] + (let [path (cf/get :tempdir)] + (l/inf :hint "tmptdir setup" :path path) (when-not (fs/existsSync path) (fs/mkdirSync path #js {:recursive true})) path)) - (defn- schedule-deletion! [path] (letfn [(remote-tempfile [] From 5375fbf59ee1be74d1f6d92ec8202c5cf7defb28 Mon Sep 17 00:00:00 2001 From: Aitor Date: Fri, 17 Nov 2023 12:16:27 +0100 Subject: [PATCH 3/3] :bug: Fix color picker --- .../ui/workspace/viewport/pixel_overlay.cljs | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/viewport/pixel_overlay.cljs b/frontend/src/app/main/ui/workspace/viewport/pixel_overlay.cljs index c7129b3a1..ec83437d9 100644 --- a/frontend/src/app/main/ui/workspace/viewport/pixel_overlay.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/pixel_overlay.cljs @@ -32,16 +32,18 @@ [svg-node] (let [image-nodes (dom/query-all svg-node "image:not([href^=data])") noop-fn (constantly nil)] - (->> (rx/from image-nodes) - (rx/mapcat - (fn [image] - (let [href (dom/get-attribute image "href")] - (->> (http/fetch {:method :get :uri href}) - (rx/mapcat (fn [response] (.blob ^js response))) - (rx/mapcat wapi/read-file-as-data-url) - (rx/tap (fn [data] - (dom/set-attribute! image "href" data))) - (rx/reduce noop-fn)))))))) + (if (empty? image-nodes) + (rx/of nil) + (->> (rx/from image-nodes) + (rx/mapcat + (fn [image] + (let [href (dom/get-attribute image "href")] + (->> (http/fetch {:method :get :uri href}) + (rx/mapcat (fn [response] (.blob ^js response))) + (rx/mapcat wapi/read-file-as-data-url) + (rx/tap (fn [data] + (dom/set-attribute! image "href" data))) + (rx/reduce noop-fn))))))))) (defn- svg-as-data-url "Transforms SVG as data-url resolving any blob, http or https url to @@ -95,7 +97,7 @@ canvas-ref (mf/use-ref nil) img-ref (mf/use-ref nil) - update-str (rx/subject) + update-str (rx/subject) handle-keydown (mf/use-callback