From 36518e0e6e8d69466b0810a01b4f352da5d7ba5c Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 11 Feb 2025 13:51:59 +0100 Subject: [PATCH 1/7] :sparkles: Fix linter issues --- backend/src/app/binfile/v3.clj | 2 +- backend/src/app/srepl/fixes.clj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/app/binfile/v3.clj b/backend/src/app/binfile/v3.clj index d60345169..006fc5ff0 100644 --- a/backend/src/app/binfile/v3.clj +++ b/backend/src/app/binfile/v3.clj @@ -530,7 +530,7 @@ (defn- match-storage-entry-fn [] - (let [pattern (str "^objects/([^/]+).json$") + (let [pattern "^objects/([^/]+).json$" pattern (re-pattern pattern)] (fn [entry] (when-let [[_ id] (re-matches pattern (zip-entry-name entry))] diff --git a/backend/src/app/srepl/fixes.clj b/backend/src/app/srepl/fixes.clj index fa76631ea..117030397 100644 --- a/backend/src/app/srepl/fixes.clj +++ b/backend/src/app/srepl/fixes.clj @@ -55,7 +55,7 @@ (let [conn (db/get-connection h/*system*) used (cfh/collect-used-media data) ids (db/create-array conn "uuid" used) - sql (str "SELECT * FROM file_media_object WHERE id = ANY(?)") + sql "SELECT * FROM file_media_object WHERE id = ANY(?)" rows (db/exec! conn [sql ids]) index (reduce (fn [index media] (if (not= (:file-id media) id) From 895450c9d55c1498d0ed976443e9cb3b044f2061 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 11 Feb 2025 13:51:50 +0100 Subject: [PATCH 2/7] :sparkles: Report restriction errors to logger --- backend/src/app/http/errors.clj | 9 ++++++--- backend/src/app/loggers/database.clj | 7 +++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/backend/src/app/http/errors.clj b/backend/src/app/http/errors.clj index aa82cb354..35e58bbca 100644 --- a/backend/src/app/http/errors.clj +++ b/backend/src/app/http/errors.clj @@ -55,13 +55,16 @@ ::yres/body (ex-data err)}) (defmethod handle-error :restriction - [err _ _] + [err request _] (let [{:keys [code] :as data} (ex-data err)] (if (= code :method-not-allowed) {::yres/status 405 ::yres/body data} - {::yres/status 400 - ::yres/body data}))) + + (binding [l/*context* (request->context request)] + (l/err :hint "restriction error" :data data) + {::yres/status 400 + ::yres/body data})))) (defmethod handle-error :rate-limit [err _ _] diff --git a/backend/src/app/loggers/database.clj b/backend/src/app/loggers/database.clj index 476180be0..41584eddc 100644 --- a/backend/src/app/loggers/database.clj +++ b/backend/src/app/loggers/database.clj @@ -59,7 +59,7 @@ :props (pp/pprint-str props :length 50) :hint (or (ex-message cause) @message) :trace (or (::trace record) - (ex/format-throwable cause :data? false :explain? false :header? false :summary? false))} + (some-> cause (ex/format-throwable :data? false :explain? false :header? false :summary? false)))} (when-let [params (or (:request/params context) (:params context))] {:params (pp/pprint-str params :length 30 :level 13)}) @@ -74,9 +74,8 @@ {:explain explain}))))) (defn error-record? - [{:keys [::l/level ::l/cause]}] - (and (= :error level) - (ex/exception? cause))) + [{:keys [::l/level]}] + (= :error level)) (defn- handle-event [{:keys [::db/pool]} {:keys [::l/id] :as record}] From 35f44a6eb4155f917878fc1fdceb3edc19cae244 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 11 Feb 2025 14:44:37 +0100 Subject: [PATCH 3/7] :bug: Remove duplicate decoding on srepl helper get-file --- backend/src/app/srepl/helpers.clj | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/backend/src/app/srepl/helpers.clj b/backend/src/app/srepl/helpers.clj index 126a3db51..8aba532b3 100644 --- a/backend/src/app/srepl/helpers.clj +++ b/backend/src/app/srepl/helpers.clj @@ -39,10 +39,7 @@ ([id] (get-file (or *system* main/system) id)) ([system id] - (db/run! system - (fn [system] - (->> (bfc/get-file system id ::db/for-update true) - (bfc/decode-file system)))))) + (db/run! system bfc/get-file id))) (defn get-raw-file "Get the migrated data of one file." From 8dbf6adfda913f24eaf2de8772ef18c13a2acce3 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 11 Feb 2025 15:42:21 +0100 Subject: [PATCH 4/7] :bug: Pass correct media-ref object on fixing media ref script --- backend/src/app/srepl/fixes/media_refs.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/app/srepl/fixes/media_refs.clj b/backend/src/app/srepl/fixes/media_refs.clj index 497dde358..44d3cc6e0 100644 --- a/backend/src/app/srepl/fixes/media_refs.clj +++ b/backend/src/app/srepl/fixes/media_refs.clj @@ -20,7 +20,7 @@ (mapcat (fn [object] (->> (cfh/collect-shape-media-refs object) (map (fn [id] - {:object-id (:id object) + {:shape-id (:id object) :id id})))))) process-page (fn [result page-id container] From df7dd157055ad25a4af25af4d3c22386cedfc817 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 11 Feb 2025 15:42:55 +0100 Subject: [PATCH 5/7] :bug: Make the absorb library aware that file can be nil --- backend/src/app/binfile/common.clj | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/src/app/binfile/common.clj b/backend/src/app/binfile/common.clj index d4d1bf3b7..a0b256660 100644 --- a/backend/src/app/binfile/common.clj +++ b/backend/src/app/binfile/common.clj @@ -409,8 +409,9 @@ [cfg data file-id] (let [library-ids (get-libraries cfg [file-id])] (reduce (fn [data library-id] - (let [library (get-file cfg library-id)] - (ctf/absorb-assets data (:data library)))) + (if-let [library (get-file cfg library-id)] + (ctf/absorb-assets data (:data library)) + data)) data library-ids))) From a3bc4ff9f3f5202eae3d4bf8b70b297662c34637 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 11 Feb 2025 15:43:35 +0100 Subject: [PATCH 6/7] :bug: Prevent exception when no file is found on process file srepl helper --- backend/src/app/srepl/helpers.clj | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/src/app/srepl/helpers.clj b/backend/src/app/srepl/helpers.clj index 8aba532b3..2ea26e3bb 100644 --- a/backend/src/app/srepl/helpers.clj +++ b/backend/src/app/srepl/helpers.clj @@ -132,9 +132,10 @@ (bfc/get-file system id)))) (d/index-by :id))) - file' (if with-libraries? - (update-fn file libs opts) - (update-fn file opts))] + file' (when file + (if with-libraries? + (update-fn file libs opts) + (update-fn file opts)))] (when (and (some? file') (not (identical? file file'))) From 6feae7f359734cf064b304b89ef4ca327abedfff Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 11 Feb 2025 15:44:12 +0100 Subject: [PATCH 7/7] :bug: Register media-refs on mod-obj --- common/src/app/common/files/changes.cljc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index 501fd24f4..0d48d5daa 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -685,7 +685,7 @@ (d/update-in-when data [:components component-id] update-container)))) (defn- process-operations - [objects {:keys [id operations] :as change}] + [objects {:keys [page-id id operations] :as change}] (if-let [shape (get objects id)] (let [shape (reduce process-operation shape operations) touched? (-> shape meta ::ctn/touched)] @@ -694,6 +694,10 @@ ;; need to report them for to be used in the second ;; phase of changes procesing (when touched? (some-> *touched-changes* (vswap! conj change))) + + (when (and *state* page-id) + (swap! *state* collect-shape-media-refs shape page-id)) + (assoc objects id shape)) objects))