Browse Source

fix: can't remove local assets on Web

charlie 4 years ago
parent
commit
91c1c4aea5

+ 1 - 0
src/main/frontend/components/block.cljs

@@ -218,6 +218,7 @@
                                                     (editor-handler/delete-asset-of-block!
                                                      {:block-id    block-id
                                                       :local?      local?
+                                                      :delete-local? (first sub-selected)
                                                       :repo        (state/get-current-repo)
                                                       :href        src
                                                       :title       title

+ 1 - 1
src/main/frontend/config.cljs

@@ -335,7 +335,7 @@
   [repo-url path]
   (if (and (util/electron?) (local-db? repo-url))
     path
-    (str (get-repo-dir repo-url) "/" path)))
+    (util/node-path.join (get-repo-dir repo-url) path)))
 
 (defn get-file-path
   [repo-url relative-path]

+ 7 - 6
src/main/frontend/handler/editor.cljs

@@ -1377,19 +1377,20 @@
                 url))))))))
 
 (defn delete-asset-of-block!
-  [{:keys [repo href title full-text block-id local?] :as opts}]
+  [{:keys [repo href title full-text block-id local? delete-local?] :as opts}]
   (let [block (db-model/query-block-by-uuid block-id)
         _ (or block (throw (str block-id " not exists")))
         format (:block/format block)
         text (:block/content block)
         content (string/replace text full-text "")]
     (save-block! repo block content)
-    (when local?
+    (when (and local? delete-local?)
       ;; FIXME: should be relative to current block page path
-      (fs/unlink! (config/get-repo-path
-                   repo (-> href
-                            (string/replace #"^../" "/")
-                            (string/replace #"^assets://" ""))) nil))))
+      (when-let [href (if (util/electron?) href (second (re-find #"\((.+)\)$" full-text)))]
+        (fs/unlink! (config/get-repo-path
+                      repo (-> href
+                               (string/replace #"^../" "/")
+                               (string/replace #"^assets://" ""))) nil)))))
 
 ;; assets/journals_2021_02_03_1612350230540_0.png
 (defn resolve-relative-path