From 2d1158efa366820c20dd824302f62d122b0d418b Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 14 Nov 2024 09:21:43 +0100 Subject: [PATCH] :bug: Fix issue with encoding/decoding thumbnails on binfile-v3 format --- backend/src/app/binfile/v3.clj | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/backend/src/app/binfile/v3.clj b/backend/src/app/binfile/v3.clj index 5fcfa96e8..4c1f8e205 100644 --- a/backend/src/app/binfile/v3.clj +++ b/backend/src/app/binfile/v3.clj @@ -296,7 +296,7 @@ (doseq [thumbnail thumbnails] (let [data (cth/parse-object-id (:object-id thumbnail)) - path (str "files/" file-id "/thumbnails/" (:page-id data) + path (str "files/" file-id "/thumbnails/" (:tag data) "/" (:page-id data) "/" (:frame-id data) ".json") data (-> data (assoc :media-id (:media-id thumbnail)) @@ -459,11 +459,12 @@ (defn- match-thumbnail-entry-fn [file-id] - (let [pattern (str "^files/" file-id "/thumbnails/([^/]+)/([^/]+).json$") + (let [pattern (str "^files/" file-id "/thumbnails/([^/]+)/([^/]+)/([^/]+).json$") pattern (re-pattern pattern)] (fn [entry] - (when-let [[_ page-id frame-id] (re-matches pattern (zip-entry-name entry))] + (when-let [[_ tag page-id frame-id] (re-matches pattern (zip-entry-name entry))] {:entry entry + :tag tag :page-id (parse-uuid page-id) :frame-id (parse-uuid frame-id) :file-id file-id})))) @@ -603,12 +604,13 @@ (defn- read-file-thumbnails [{:keys [::input ::file-id ::entries] :as cfg}] (->> (keep (match-thumbnail-entry-fn file-id) entries) - (reduce (fn [result {:keys [page-id frame-id entry]}] + (reduce (fn [result {:keys [page-id frame-id tag entry]}] (let [object (->> (read-entry input entry) (decode-file-thumbnail) (validate-file-thumbnail))] (if (and (= frame-id (:frame-id object)) - (= page-id (:page-id object))) + (= page-id (:page-id object)) + (= tag (:tag object))) (conj result object) result))) []) @@ -788,7 +790,6 @@ media-id (bfc/lookup-index (:media-id item)) object-id (-> (assoc item :file-id file-id) (cth/fmt-object-id)) - params {:file-id file-id :object-id object-id :tag (:tag item) @@ -902,6 +903,11 @@ (export-files cfg) (export-storage-objects cfg))))) + (catch java.util.zip.ZipException cause + (vreset! cs cause) + (vreset! ab true) + (throw cause)) + (catch java.io.IOException _cause ;; Do nothing, EOF means client closes connection abruptly (vreset! ab true)