mirror of https://github.com/logseq/logseq
fix(fs): image renaming op when resizing pdf hl area (#9122)
* fix(fs): image renaming op when resizing pdf hl area Fix #9120pull/8421/head
parent
67fe5dc5a7
commit
65eb6d3380
|
@ -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))
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue