From 65eb6d3380ed5a607100b2dfe44ff8c124489bcf Mon Sep 17 00:00:00 2001 From: Andelf Date: Thu, 20 Apr 2023 15:15:32 +0800 Subject: [PATCH] fix(fs): image renaming op when resizing pdf hl area (#9122) * fix(fs): image renaming op when resizing pdf hl area Fix #9120 --- src/main/frontend/extensions/pdf/assets.cljs | 12 +++++++----- src/main/frontend/fs.cljs | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/frontend/extensions/pdf/assets.cljs b/src/main/frontend/extensions/pdf/assets.cljs index 6e43a0130..41c4fd2b4 100644 --- a/src/main/frontend/extensions/pdf/assets.cljs +++ b/src/main/frontend/extensions/pdf/assets.cljs @@ -17,6 +17,7 @@ [frontend.util :as util] [frontend.extensions.pdf.utils :as pdf-utils] [frontend.extensions.pdf.windows :as pdf-windows] + [logseq.common.path :as path] [logseq.graph-parser.config :as gp-config] [logseq.graph-parser.util.block-ref :as block-ref] [medley.core :as medley] @@ -78,13 +79,14 @@ (and hl (not (nil? (get-in hl [:content :image]))))) (defn persist-hl-area-image$ + "Save pdf highlight area image" [^js viewer current new-hl old-hl {:keys [top left width height]}] (when-let [^js canvas (and (:key current) (.-canvas (.getPageView viewer (dec (:page new-hl)))))] (let [^js doc (.-ownerDocument canvas) ^js canvas' (.createElement doc "canvas") dpr js/window.devicePixelRatio - repo-cur (state/get-current-repo) - repo-dir (config/get-repo-dir repo-cur) + repo-url (state/get-current-repo) + repo-dir (config/get-repo-dir repo-url) dw (* dpr width) dh (* dpr height)] @@ -109,11 +111,11 @@ old-fstamp (and old-hl (get-in old-hl [:content :image])) fname (str (:page new-hl) "_" (:id new-hl)) fdir (str gp-config/local-assets-dir "/" key) - _ (fs/mkdir-if-not-exists (str repo-dir "/" fdir)) + _ (fs/mkdir-if-not-exists (path/path-join repo-dir fdir)) new-fpath (str fdir "/" fname "_" fstamp ".png") old-fpath (and old-fstamp (str fdir "/" fname "_" old-fstamp ".png")) - _ (and old-fpath (apply fs/rename! repo-cur (map #(util/node-path.join repo-dir %) [old-fpath new-fpath]))) - _ (fs/write-file! repo-cur repo-dir new-fpath png {:skip-compare? true})] + _ (and old-fpath (fs/rename! repo-url old-fpath new-fpath)) + _ (fs/write-file! repo-url repo-dir new-fpath png {:skip-compare? true})] (js/console.timeEnd :write-area-image)) diff --git a/src/main/frontend/fs.cljs b/src/main/frontend/fs.cljs index 902d36094..e836b6a3e 100644 --- a/src/main/frontend/fs.cljs +++ b/src/main/frontend/fs.cljs @@ -123,6 +123,7 @@ (protocol/read-file (get-fs dir) dir path options))) (defn rename! + "Rename files, incoming relative path, converted to absolute path" [repo old-path new-path] (let [new-path (gp-util/path-normalize new-path)] (cond