Parcourir la source

enhance: rename fs/write-file! to fs/write-plain-text-file!

Tienson Qin il y a 9 mois
Parent
commit
cf8947da04

+ 3 - 4
src/main/frontend/extensions/pdf/assets.cljs

@@ -67,7 +67,7 @@
     (let [repo-cur (state/get-current-repo)
     (let [repo-cur (state/get-current-repo)
           repo-dir (config/get-repo-dir repo-cur)
           repo-dir (config/get-repo-dir repo-cur)
           data     (with-out-str (pprint {:highlights highlights :extra extra}))]
           data     (with-out-str (pprint {:highlights highlights :extra extra}))]
-      (fs/write-file! repo-cur repo-dir hls-file data {:skip-compare? true}))))
+      (fs/write-plain-text-file! repo-cur repo-dir hls-file data {:skip-compare? true}))))
 
 
 (defn resolve-hls-data-by-key$
 (defn resolve-hls-data-by-key$
   [target-key]
   [target-key]
@@ -116,15 +116,14 @@
                                   new-fpath  (str fdir "/" fname "_" fstamp ".png")
                                   new-fpath  (str fdir "/" fname "_" fstamp ".png")
                                   old-fpath  (and old-fstamp (str fdir "/" fname "_" old-fstamp ".png"))
                                   old-fpath  (and old-fstamp (str fdir "/" fname "_" old-fstamp ".png"))
                                   _          (and old-fpath (fs/rename! repo-url old-fpath new-fpath))
                                   _          (and old-fpath (fs/rename! repo-url old-fpath new-fpath))
-                                  _          (fs/write-file! repo-url repo-dir new-fpath png {:skip-compare? true})]
+                                  _          (fs/write-plain-text-file! repo-url repo-dir new-fpath png {:skip-compare? true})]
 
 
                             (js/console.timeEnd :write-area-image))
                             (js/console.timeEnd :write-area-image))
 
 
                           (fn [err]
                           (fn [err]
                             (js/console.error "[write area image Error]" err))))]
                             (js/console.error "[write area image Error]" err))))]
 
 
-          (.toBlob canvas' callback))
-        ))))
+          (.toBlob canvas' callback))))))
 
 
 (defn update-hl-block!
 (defn update-hl-block!
   [highlight]
   [highlight]

+ 2 - 2
src/main/frontend/fs.cljs

@@ -89,7 +89,7 @@
       (protocol/rmdir! fs dir))))
       (protocol/rmdir! fs dir))))
 
 
 ;; TODO(andelf): distinguish from graph file writing and global file write
 ;; TODO(andelf): distinguish from graph file writing and global file write
-(defn write-file!
+(defn write-plain-text-file!
   "Use it only for plain-text files, not binary"
   "Use it only for plain-text files, not binary"
   [repo dir rpath content opts]
   [repo dir rpath content opts]
   (when content
   (when content
@@ -215,7 +215,7 @@
          true)
          true)
        (p/catch
        (p/catch
         (fn [_error]
         (fn [_error]
-          (p/let [_ (write-file! repo dir path initial-content nil)]
+          (p/let [_ (write-plain-text-file! repo dir path initial-content nil)]
             false))))))
             false))))))
 
 
 (defn file-exists?
 (defn file-exists?

+ 72 - 105
src/main/frontend/fs/sync.cljs

@@ -163,8 +163,7 @@
                  :remote->local-full-sync-failed
                  :remote->local-full-sync-failed
                  :local->remote-full-sync-failed
                  :local->remote-full-sync-failed
                  :get-remote-graph-failed
                  :get-remote-graph-failed
-                 :get-deletion-logs-failed
-                 })
+                 :get-deletion-logs-failed})
 
 
 (s/def ::sync-event (s/keys :req-un [::event ::data]))
 (s/def ::sync-event (s/keys :req-un [::event ::data]))
 
 
@@ -197,7 +196,6 @@
   [x]
   [x]
   (when (instance? ExceptionInfo x) x))
   (when (instance? ExceptionInfo x) x))
 
 
-
 (def ws-addr config/WS-URL)
 (def ws-addr config/WS-URL)
 
 
 ;; Warning: make sure to `persist-var/-load` graphs-txid before using it.
 ;; Warning: make sure to `persist-var/-load` graphs-txid before using it.
@@ -325,9 +323,9 @@
 (defn <request [api-name & args]
 (defn <request [api-name & args]
   (let [name (str api-name (.now js/Date))]
   (let [name (str api-name (.now js/Date))]
     (go (swap! *on-flying-request conj name)
     (go (swap! *on-flying-request conj name)
-      (let [r (<! (apply <request* api-name args))]
-        (swap! *on-flying-request disj name)
-        r))))
+        (let [r (<! (apply <request* api-name args))]
+          (swap! *on-flying-request disj name)
+          r))))
 
 
 (defn- remove-dir-prefix [dir path]
 (defn- remove-dir-prefix [dir path]
   (let [r (string/replace path (js/RegExp. (str "^" (gstring/regExpEscape dir))) "")]
   (let [r (string/replace path (js/RegExp. (str "^" (gstring/regExpEscape dir))) "")]
@@ -416,19 +414,19 @@
   (let [update? (= "update_files" TXType)
   (let [update? (= "update_files" TXType)
         delete? (= "delete_files" TXType)
         delete? (= "delete_files" TXType)
         update-xf
         update-xf
-                (comp
-                 (remove #(or (empty? (first %))
-                              (empty? (last %))))
-                 (map #(->FileTxn (first %) (first %) update? delete? TXId (last %))))
+        (comp
+         (remove #(or (empty? (first %))
+                      (empty? (last %))))
+         (map #(->FileTxn (first %) (first %) update? delete? TXId (last %))))
         delete-xf
         delete-xf
-                (comp
-                 (remove #(empty? (first %)))
-                 (map #(->FileTxn (first %) (first %) update? delete? TXId nil)))
+        (comp
+         (remove #(empty? (first %)))
+         (map #(->FileTxn (first %) (first %) update? delete? TXId nil)))
         rename-xf
         rename-xf
-                (comp
-                 (remove #(or (empty? (first %))
-                              (empty? (second %))))
-                 (map #(->FileTxn (second %) (first %) false false TXId nil)))
+        (comp
+         (remove #(or (empty? (first %))
+                      (empty? (second %))))
+         (map #(->FileTxn (second %) (first %) false false TXId nil)))
         xf (case TXType
         xf (case TXType
              "delete_files" delete-xf
              "delete_files" delete-xf
              "update_files" update-xf
              "update_files" update-xf
@@ -565,7 +563,6 @@
    (map-indexed filepath+checksum->diff)
    (map-indexed filepath+checksum->diff)
    (diffs->partitioned-filetxns n)))
    (diffs->partitioned-filetxns n)))
 
 
-
 (deftype FileMetadata [size etag path encrypted-path last-modified remote? txid ^:mutable normalized-path]
 (deftype FileMetadata [size etag path encrypted-path last-modified remote? txid ^:mutable normalized-path]
   Object
   Object
   (get-normalized-path [_]
   (get-normalized-path [_]
@@ -601,13 +598,10 @@
       :txid txid
       :txid txid
       not-found))
       not-found))
 
 
-
   IPrintWithWriter
   IPrintWithWriter
   (-pr-writer [_ w _opts]
   (-pr-writer [_ w _opts]
     (write-all w (str {:size size :etag etag :path path :remote? remote? :txid txid :last-modified last-modified}))))
     (write-all w (str {:size size :etag etag :path path :remote? remote? :txid txid :last-modified last-modified}))))
 
 
-
-
 (def ^:private higher-priority-remote-files
 (def ^:private higher-priority-remote-files
   "when diff all remote files and local files, following remote files always need to download(when checksum not matched),
   "when diff all remote files and local files, following remote files always need to download(when checksum not matched),
   even local-file's last-modified > remote-file's last-modified.
   even local-file's last-modified > remote-file's last-modified.
@@ -664,21 +658,21 @@
    #{} s1))
    #{} s1))
 
 
 (comment
 (comment
- (defn map->FileMetadata [m]
-   (apply ->FileMetadata ((juxt :size :etag :path :encrypted-path :last-modified :remote? (constantly nil)) m)))
-
- (assert
-  (=
-   #{(map->FileMetadata {:size 1 :etag 2 :path 2 :encrypted-path 2 :last-modified 2})}
-   (diff-file-metadata-sets
-    (into #{}
-          (map map->FileMetadata)
-          [{:size 1 :etag 1 :path 1 :encrypted-path 1 :last-modified 1}
-           {:size 1 :etag 2 :path 2 :encrypted-path 2 :last-modified 2}])
-    (into #{}
-          (map map->FileMetadata)
-          [{:size 1 :etag 1 :path 1 :encrypted-path 1 :last-modified 1}
-           {:size 1 :etag 1 :path 2 :encrypted-path 2 :last-modified 1}])))))
+  (defn map->FileMetadata [m]
+    (apply ->FileMetadata ((juxt :size :etag :path :encrypted-path :last-modified :remote? (constantly nil)) m)))
+
+  (assert
+   (=
+    #{(map->FileMetadata {:size 1 :etag 2 :path 2 :encrypted-path 2 :last-modified 2})}
+    (diff-file-metadata-sets
+     (into #{}
+           (map map->FileMetadata)
+           [{:size 1 :etag 1 :path 1 :encrypted-path 1 :last-modified 1}
+            {:size 1 :etag 2 :path 2 :encrypted-path 2 :last-modified 2}])
+     (into #{}
+           (map map->FileMetadata)
+           [{:size 1 :etag 1 :path 1 :encrypted-path 1 :last-modified 1}
+            {:size 1 :etag 1 :path 2 :encrypted-path 2 :last-modified 1}])))))
 
 
 (extend-protocol IChecksum
 (extend-protocol IChecksum
   FileMetadata
   FileMetadata
@@ -731,7 +725,6 @@
 
 
   gp-util/path-normalize)
   gp-util/path-normalize)
 
 
-
 ;;; ### APIs
 ;;; ### APIs
 ;; `RSAPI` call apis through rsapi package, supports operations on files
 ;; `RSAPI` call apis through rsapi package, supports operations on files
 
 
@@ -770,16 +763,13 @@
   (<get-graph-encrypt-keys [this graph-uuid])
   (<get-graph-encrypt-keys [this graph-uuid])
   (<upload-graph-encrypt-keys [this graph-uuid public-key encrypted-private-key]))
   (<upload-graph-encrypt-keys [this graph-uuid public-key encrypted-private-key]))
 
 
-
 (defprotocol IRemoteControlAPI
 (defprotocol IRemoteControlAPI
   "api functions provided for outside the sync process"
   "api functions provided for outside the sync process"
-  (<delete-remote-files-control [this graph-uuid filepaths])
-  )
+  (<delete-remote-files-control [this graph-uuid filepaths]))
 
 
 (defprotocol IToken
 (defprotocol IToken
   (<get-token [this]))
   (<get-token [this]))
 
 
-
 (defn <case-different-local-file-exist?
 (defn <case-different-local-file-exist?
   "e.g. filepath=\"pages/Foo.md\"
   "e.g. filepath=\"pages/Foo.md\"
   found-filepath=\"pages/foo.md\"
   found-filepath=\"pages/foo.md\"
@@ -1133,8 +1123,8 @@
      (go-loop []
      (go-loop []
        (let [{:keys [val stop]}
        (let [{:keys [val stop]}
              (async/alt!
              (async/alt!
-              debug-print-sync-events-loop-stop-chan {:stop true}
-              out-ch ([v] {:val v}))]
+               debug-print-sync-events-loop-stop-chan {:stop true}
+               out-ch ([v] {:val v}))]
          (cond
          (cond
            stop (do (async/unmix-all out-mix)
            stop (do (async/unmix-all out-mix)
                     (doseq [[topic ch] topic&chs]
                     (doseq [[topic ch] topic&chs]
@@ -1143,12 +1133,10 @@
            val (do (pp/pprint [:debug :sync-event val])
            val (do (pp/pprint [:debug :sync-event val])
                    (recur))))))))
                    (recur))))))))
 
 
-
 (defn stop-debug-print-sync-events-loop
 (defn stop-debug-print-sync-events-loop
   []
   []
   (offer! debug-print-sync-events-loop-stop-chan true))
   (offer! debug-print-sync-events-loop-stop-chan true))
 
 
-
 ;;; sync events ends
 ;;; sync events ends
 
 
 (defn- fire-file-sync-storage-exceed-limit-event!
 (defn- fire-file-sync-storage-exceed-limit-event!
@@ -1237,7 +1225,6 @@
                 (recur result-file-meta-list others))))
                 (recur result-file-meta-list others))))
         (vals (persistent! result-file-meta-list))))))
         (vals (persistent! result-file-meta-list))))))
 
 
-
 (extend-type RemoteAPI
 (extend-type RemoteAPI
   IRemoteAPI
   IRemoteAPI
   (<user-info [this]
   (<user-info [this]
@@ -1443,13 +1430,10 @@
 
 
 (comment
 (comment
   (declare remoteapi)
   (declare remoteapi)
-  (<delete-remote-files-control remoteapi (second @graphs-txid) ["pages/aa.md"])
-
-  )
+  (<delete-remote-files-control remoteapi (second @graphs-txid) ["pages/aa.md"]))
 
 
 (def remoteapi (->RemoteAPI nil))
 (def remoteapi (->RemoteAPI nil))
 
 
-
 (def ^:private *get-graph-salt-memoize-cache (atom {}))
 (def ^:private *get-graph-salt-memoize-cache (atom {}))
 (defn update-graph-salt-cache [graph-uuid v]
 (defn update-graph-salt-cache [graph-uuid v]
   {:pre [(map? v)
   {:pre [(map? v)
@@ -1526,9 +1510,6 @@
           val val
           val val
           timeout (recur))))))
           timeout (recur))))))
 
 
-
-
-
 (defn- assert-local-txid<=remote-txid
 (defn- assert-local-txid<=remote-txid
   []
   []
   (when-let [local-txid (last @graphs-txid)]
   (when-let [local-txid (last @graphs-txid)]
@@ -1553,7 +1534,6 @@
          sync-state--remove-recent-remote->local-files
          sync-state--remove-recent-remote->local-files
          sync-state--stopped?)
          sync-state--stopped?)
 
 
-
 (defn- filetxns=>recent-remote->local-files
 (defn- filetxns=>recent-remote->local-files
   [filetxns]
   [filetxns]
   (let [{:keys [update-filetxns delete-filetxns rename-filetxns]}
   (let [{:keys [update-filetxns delete-filetxns rename-filetxns]}
@@ -1615,7 +1595,7 @@
                                       (fs/unlink! repo (path/path-join repo-dir base-file) {}))
                                       (fs/unlink! repo (path/path-join repo-dir base-file) {}))
                                      ;; base-content != current-content, merge, do not delete
                                      ;; base-content != current-content, merge, do not delete
                                      (p/let [merged-content (diff-merge/three-way-merge base-content "" current-content format)]
                                      (p/let [merged-content (diff-merge/three-way-merge base-content "" current-content format)]
-                                       (fs/write-file! repo repo-dir current-change-file merged-content {:skip-compare? true})
+                                       (fs/write-plain-text-file! repo repo-dir current-change-file merged-content {:skip-compare? true})
                                        (file-handler/alter-file repo current-change-file merged-content {:re-render-root? true
                                        (file-handler/alter-file repo current-change-file merged-content {:re-render-root? true
                                                                                                          :from-disk? true
                                                                                                          :from-disk? true
                                                                                                          :fs/event :fs/remote-file-change}))))
                                                                                                          :fs/event :fs/remote-file-change}))))
@@ -1665,7 +1645,7 @@
                                                     merged-content (diff-merge/three-way-merge base-content incoming-content current-content format)]
                                                     merged-content (diff-merge/three-way-merge base-content incoming-content current-content format)]
                                               (when (seq merged-content)
                                               (when (seq merged-content)
                                                 (p/do!
                                                 (p/do!
-                                                 (fs/write-file! repo repo-dir current-change-file merged-content {:skip-compare? true})
+                                                 (fs/write-plain-text-file! repo repo-dir current-change-file merged-content {:skip-compare? true})
                                                  (file-handler/alter-file repo current-change-file merged-content {:re-render-root? true
                                                  (file-handler/alter-file repo current-change-file merged-content {:re-render-root? true
                                                                                                                    :from-disk? true
                                                                                                                    :from-disk? true
                                                                                                                    :fs/event :fs/remote-file-change})))))))
                                                                                                                    :fs/event :fs/remote-file-change})))))))
@@ -1692,7 +1672,7 @@
 
 
                                           ;; else
                                           ;; else
                                             (p/do!
                                             (p/do!
-                                             (fs/write-file! repo repo-dir current-change-file merged-content {:skip-compare? true})
+                                             (fs/write-plain-text-file! repo repo-dir current-change-file merged-content {:skip-compare? true})
                                              (file-handler/alter-file repo current-change-file merged-content {:re-render-root? true
                                              (file-handler/alter-file repo current-change-file merged-content {:re-render-root? true
                                                                                                                :from-disk? true
                                                                                                                :from-disk? true
                                                                                                                :fs/event :fs/remote-file-change})))))))))))))))))
                                                                                                                :fs/event :fs/remote-file-change})))))))))))))))))
@@ -1729,8 +1709,8 @@
                      [recent-remote->local-file-item])
                      [recent-remote->local-file-item])
               (<! (<delete-local-files rsapi graph-uuid base-path [relative-p*]))
               (<! (<delete-local-files rsapi graph-uuid base-path [relative-p*]))
               (go (<! (timeout 5000))
               (go (<! (timeout 5000))
-                (swap! *sync-state sync-state--remove-recent-remote->local-files
-                       [recent-remote->local-file-item])))))
+                  (swap! *sync-state sync-state--remove-recent-remote->local-files
+                         [recent-remote->local-file-item])))))
 
 
         (let [update-local-files-ch (if (state/enable-sync-diff-merge?)
         (let [update-local-files-ch (if (state/enable-sync-diff-merge?)
                                       (<fetch-remote-and-update-local-files graph-uuid base-path (map relative-path filetxns))
                                       (<fetch-remote-and-update-local-files graph-uuid base-path (map relative-path filetxns))
@@ -1786,8 +1766,8 @@
                                                      (not (instance? ExceptionInfo r)))]
                                                      (not (instance? ExceptionInfo r)))]
           ;; remove these recent-remote->local-file-items 5s later
           ;; remove these recent-remote->local-file-items 5s later
           (go (<! (timeout 5000))
           (go (<! (timeout 5000))
-            (swap! *sync-state sync-state--remove-recent-remote->local-files
-                   recent-remote->local-file-items))
+              (swap! *sync-state sync-state--remove-recent-remote->local-files
+                     recent-remote->local-file-items))
           (cond
           (cond
             (instance? ExceptionInfo r) r
             (instance? ExceptionInfo r) r
             @*paused                    {:pause true}
             @*paused                    {:pause true}
@@ -1846,7 +1826,6 @@
   [r]
   [r]
   (some->> (ex-cause r) str (re-find #"Request is not yet valid")))
   (some->> (ex-cause r) str (re-find #"Request is not yet valid")))
 
 
-
 ;; type = "change" | "add" | "unlink"
 ;; type = "change" | "add" | "unlink"
 (deftype FileChangeEvent [type dir path stat checksum]
 (deftype FileChangeEvent [type dir path stat checksum]
   IRelativePath
   IRelativePath
@@ -1881,7 +1860,6 @@
   (-pr-writer [_ w _opts]
   (-pr-writer [_ w _opts]
     (write-all w (str {:type type :base-path dir :path path :size (:size stat) :checksum checksum}))))
     (write-all w (str {:type type :base-path dir :path path :size (:size stat) :checksum checksum}))))
 
 
-
 (defn- <file-change-event=>recent-remote->local-file-item
 (defn- <file-change-event=>recent-remote->local-file-item
   "return nil when related local files not found"
   "return nil when related local files not found"
   [graph-uuid ^FileChangeEvent e]
   [graph-uuid ^FileChangeEvent e]
@@ -1954,8 +1932,8 @@
     (go-loop []
     (go-loop []
       (let [{:keys [rename-event local-change]}
       (let [{:keys [rename-event local-change]}
             (async/alt!
             (async/alt!
-             rename-page-event-chan ([v] {:rename-event v}) ;; {:repo X :old-path X :new-path}
-             local-changes-chan ([v] {:local-change v}))]
+              rename-page-event-chan ([v] {:rename-event v}) ;; {:repo X :old-path X :new-path}
+              local-changes-chan ([v] {:local-change v}))]
         (cond
         (cond
           rename-event
           rename-event
           (let [repo-dir (config/get-repo-dir (:repo rename-event))
           (let [repo-dir (config/get-repo-dir (:repo rename-event))
@@ -1968,13 +1946,13 @@
             (swap! *rename-events conj k1 k2)
             (swap! *rename-events conj k1 k2)
             ;; remove rename-events after 2s
             ;; remove rename-events after 2s
             (go (<! (timeout 3000))
             (go (<! (timeout 3000))
-              (swap! *rename-events disj k1 k2))
+                (swap! *rename-events disj k1 k2))
             ;; add 2 simulated file-watcher events
             ;; add 2 simulated file-watcher events
             (>! ch (->FileChangeEvent "unlink" repo-dir (:old-path rename-event*) nil nil))
             (>! ch (->FileChangeEvent "unlink" repo-dir (:old-path rename-event*) nil nil))
             (>! ch (->FileChangeEvent "add" repo-dir (:new-path rename-event*)
             (>! ch (->FileChangeEvent "add" repo-dir (:new-path rename-event*)
                                       {:mtime (tc/to-long (t/now))
                                       {:mtime (tc/to-long (t/now))
                                        :size 1 ; add a fake size
                                        :size 1 ; add a fake size
-                                       } "fake-checksum"))
+                                       }"fake-checksum"))
             (recur))
             (recur))
           local-change
           local-change
           (cond
           (cond
@@ -2051,7 +2029,6 @@
     (js/localStorage.removeItem k))
     (js/localStorage.removeItem k))
   (reset! pwd-map {}))
   (reset! pwd-map {}))
 
 
-
 (defn encrypt+persist-pwd!
 (defn encrypt+persist-pwd!
   "- persist encrypted pwd at local-storage"
   "- persist encrypted pwd at local-storage"
   [pwd graph-uuid]
   [pwd graph-uuid]
@@ -2099,7 +2076,6 @@
       (when (and private-key (string/starts-with? private-key "AGE-SECRET-KEY"))
       (when (and private-key (string/starts-with? private-key "AGE-SECRET-KEY"))
         (set-keys&notify graph-uuid public-key private-key)))))
         (set-keys&notify graph-uuid public-key private-key)))))
 
 
-
 (def <restored-pwd (chan (async/sliding-buffer 1)))
 (def <restored-pwd (chan (async/sliding-buffer 1)))
 (def <restored-pwd-pub (async/pub <restored-pwd :graph-uuid))
 (def <restored-pwd-pub (async/pub <restored-pwd :graph-uuid))
 
 
@@ -2129,7 +2105,6 @@
   (swap! pwd-map dissoc graph-uuid)
   (swap! pwd-map dissoc graph-uuid)
   (remove-pwd! graph-uuid))
   (remove-pwd! graph-uuid))
 
 
-
 (defn- <loop-ensure-pwd&keys
 (defn- <loop-ensure-pwd&keys
   [graph-uuid repo *stopped?]
   [graph-uuid repo *stopped?]
   (let [<restored-pwd-sub-chan (chan 1)]
   (let [<restored-pwd-sub-chan (chan 1)]
@@ -2191,7 +2166,6 @@
                       (clear-pwd! graph-uuid)
                       (clear-pwd! graph-uuid)
                       (recur))))))))))
                       (recur))))))))))
 
 
-
 (defn- <set-env&keys
 (defn- <set-env&keys
   [prod? graph-uuid]
   [prod? graph-uuid]
   (let [{:keys [private-key public-key]} (get @pwd-map graph-uuid)]
   (let [{:keys [private-key public-key]} (get @pwd-map graph-uuid)]
@@ -2246,7 +2220,6 @@
            (fn [_ _ _ _]
            (fn [_ _ _ _]
              (offer! recent-edited-chan true)))
              (offer! recent-edited-chan true)))
 
 
-
 ;;; ### sync state
 ;;; ### sync state
 
 
 (def *resume-state
 (def *resume-state
@@ -2390,7 +2363,6 @@
   (contains? #{::idle ::local->remote ::remote->local ::local->remote-full-sync ::remote->local-full-sync}
   (contains? #{::idle ::local->remote ::remote->local ::local->remote-full-sync ::remote->local-full-sync}
              (:state sync-state)))
              (:state sync-state)))
 
 
-
 ;;; ### remote->local syncer & local->remote syncer
 ;;; ### remote->local syncer & local->remote syncer
 
 
 (defprotocol IRemote->LocalSync
 (defprotocol IRemote->LocalSync
@@ -2646,11 +2618,11 @@
          local-files-meta-map))))
          local-files-meta-map))))
 
 
 (defrecord ^:large-vars/cleanup-todo
 (defrecord ^:large-vars/cleanup-todo
-  Local->RemoteSyncer [user-uuid graph-uuid base-path repo *sync-state remoteapi
-                       ^:mutable rate *txid *txid-for-get-deletion-log
-                       ^:mutable remote->local-syncer stop-chan *stopped *paused
+ Local->RemoteSyncer [user-uuid graph-uuid base-path repo *sync-state remoteapi
+                      ^:mutable rate *txid *txid-for-get-deletion-log
+                      ^:mutable remote->local-syncer stop-chan *stopped *paused
                        ;; control chans
                        ;; control chans
-                       private-immediately-local->remote-chan private-recent-edited-chan]
+                      private-immediately-local->remote-chan private-recent-edited-chan]
   Object
   Object
   (filter-file-change-events-fn [_]
   (filter-file-change-events-fn [_]
     (fn [^FileChangeEvent e]
     (fn [^FileChangeEvent e]
@@ -2817,21 +2789,21 @@
                                             <!
                                             <!
                                             (sort-by (sort-file-metadata-fn :recent-days-range recent-10-days-range) >))
                                             (sort-by (sort-file-metadata-fn :recent-days-range recent-10-days-range) >))
                 change-events
                 change-events
-                                       (sequence
-                                        (comp
+                (sequence
+                 (comp
                                          ;; convert to FileChangeEvent
                                          ;; convert to FileChangeEvent
-                                         (map #(->FileChangeEvent "change" base-path (.get-normalized-path ^FileMetadata %)
-                                                                  {:size (:size %)} (:etag %)))
-                                         (remove ignored?))
-                                        diff-local-files)
+                  (map #(->FileChangeEvent "change" base-path (.get-normalized-path ^FileMetadata %)
+                                           {:size (:size %)} (:etag %)))
+                  (remove ignored?))
+                 diff-local-files)
                 distinct-change-events (-> (distinct-file-change-events change-events)
                 distinct-change-events (-> (distinct-file-change-events change-events)
                                            filter-upload-files-with-reserved-chars)
                                            filter-upload-files-with-reserved-chars)
                 _                      (swap! *sync-state #(sync-state-reset-full-local->remote-files % distinct-change-events))
                 _                      (swap! *sync-state #(sync-state-reset-full-local->remote-files % distinct-change-events))
                 change-events-partitions
                 change-events-partitions
-                                       (sequence
+                (sequence
                                         ;; partition FileChangeEvents
                                         ;; partition FileChangeEvents
-                                        (partition-file-change-events upload-batch-size)
-                                        distinct-change-events)]
+                 (partition-file-change-events upload-batch-size)
+                 distinct-change-events)]
             (println "[full-sync(local->remote)]"
             (println "[full-sync(local->remote)]"
                      (count (flatten change-events-partitions)) "files need to sync and"
                      (count (flatten change-events-partitions)) "files need to sync and"
                      (count delete-local-files) "local files need to delete")
                      (count delete-local-files) "local files need to delete")
@@ -2852,8 +2824,8 @@
                              [fake-recent-remote->local-file-item])
                              [fake-recent-remote->local-file-item])
                       (<! (<delete-local-files rsapi graph-uuid base-path [(relative-path f)]))
                       (<! (<delete-local-files rsapi graph-uuid base-path [(relative-path f)]))
                       (go (<! (timeout 5000))
                       (go (<! (timeout 5000))
-                        (swap! *sync-state sync-state--remove-recent-remote->local-files
-                               [fake-recent-remote->local-file-item])))))
+                          (swap! *sync-state sync-state--remove-recent-remote->local-files
+                                 [fake-recent-remote->local-file-item])))))
                 (recur fs)))
                 (recur fs)))
 
 
             ;; 2. upload local files
             ;; 2. upload local files
@@ -2871,13 +2843,12 @@
                               (or need-sync-remote graph-has-been-deleted unknown stop) r)))))]
                               (or need-sync-remote graph-has-been-deleted unknown stop) r)))))]
               ;; update *txid-for-get-deletion-log
               ;; update *txid-for-get-deletion-log
               (reset! *txid-for-get-deletion-log @*txid)
               (reset! *txid-for-get-deletion-log @*txid)
-              r
-              )))))))
+              r)))))))
 
 
 ;;; ### put all stuff together
 ;;; ### put all stuff together
 
 
 (defrecord ^:large-vars/cleanup-todo
 (defrecord ^:large-vars/cleanup-todo
-    SyncManager [user-uuid graph-uuid base-path *sync-state
+ SyncManager [user-uuid graph-uuid base-path *sync-state
               ^Local->RemoteSyncer local->remote-syncer ^Remote->LocalSyncer remote->local-syncer remoteapi
               ^Local->RemoteSyncer local->remote-syncer ^Remote->LocalSyncer remote->local-syncer remoteapi
               ^:mutable ratelimit-local-changes-chan
               ^:mutable ratelimit-local-changes-chan
               *txid *txid-for-get-deletion-log
               *txid *txid-for-get-deletion-log
@@ -3281,7 +3252,6 @@
     (reset! current-sm-graph-uuid graph-uuid)
     (reset! current-sm-graph-uuid graph-uuid)
     (sync-manager user-uuid graph-uuid base-path repo txid *sync-state)))
     (sync-manager user-uuid graph-uuid base-path repo txid *sync-state)))
 
 
-
 (defn <sync-stop []
 (defn <sync-stop []
   (go
   (go
     (when-let [sm ^SyncManager (state/get-file-sync-manager (state/get-current-file-sync-graph-uuid))]
     (when-let [sm ^SyncManager (state/get-file-sync-manager (state/get-current-file-sync-graph-uuid))]
@@ -3324,15 +3294,15 @@
   (go
   (go
     (let [r (<! (<list-remote-graphs remoteapi))
     (let [r (<! (<list-remote-graphs remoteapi))
           result
           result
-            (or
+          (or
              ;; if api call failed, assume this remote graph still exists
              ;; if api call failed, assume this remote graph still exists
-             (instance? ExceptionInfo r)
-             (and
-              (contains? r :Graphs)
-              (->> (:Graphs r)
-                   (mapv :GraphUUID)
-                   set
-                   (#(contains? % local-graph-uuid)))))]
+           (instance? ExceptionInfo r)
+           (and
+            (contains? r :Graphs)
+            (->> (:Graphs r)
+                 (mapv :GraphUUID)
+                 set
+                 (#(contains? % local-graph-uuid)))))]
 
 
       (when-not result
       (when-not result
         (notification/show! (t :file-sync/graph-deleted) :warning false))
         (notification/show! (t :file-sync/graph-deleted) :warning false))
@@ -3352,7 +3322,6 @@
   (when-let [graph-uuid (second @graphs-txid)]
   (when-let [graph-uuid (second @graphs-txid)]
     (get-pwd graph-uuid)))
     (get-pwd graph-uuid)))
 
 
-
 (defn- <connectivity-testing
 (defn- <connectivity-testing
   []
   []
   (go
   (go
@@ -3522,7 +3491,6 @@
     (<sync-start))
     (<sync-start))
   (recur))
   (recur))
 
 
-
 ;;; ### some sync events handler
 ;;; ### some sync events handler
 
 
 ;; re-exec remote->local-full-sync when it failed before
 ;; re-exec remote->local-full-sync when it failed before
@@ -3548,6 +3516,5 @@
 
 
 ;;; add-tap
 ;;; add-tap
 (comment
 (comment
- (def *x (atom nil))
- (add-tap (fn [v] (reset! *x v)))
- )
+  (def *x (atom nil))
+  (add-tap (fn [v] (reset! *x v))))

+ 1 - 1
src/main/frontend/handler/draw.cljs

@@ -29,7 +29,7 @@
         (->
         (->
          (p/do!
          (p/do!
           (create-draws-directory! repo)
           (create-draws-directory! repo)
-          (fs/write-file! repo repo-dir path data nil)
+          (fs/write-plain-text-file! repo repo-dir path data nil)
           (db/transact! repo
           (db/transact! repo
                         [{:file/path path
                         [{:file/path path
                           :block/name (util/page-name-sanity-lc file)
                           :block/name (util/page-name-sanity-lc file)

+ 14 - 16
src/main/frontend/handler/events.cljs

@@ -343,13 +343,13 @@
 (defmethod handle :modal/toggle-accent-colors-modal [_]
 (defmethod handle :modal/toggle-accent-colors-modal [_]
   (let [label "accent-colors-picker"]
   (let [label "accent-colors-picker"]
     (if (or (= label (state/get-modal-id))
     (if (or (= label (state/get-modal-id))
-          (= label (some-> (state/get-sub-modals) (first) :modal/id)))
+            (= label (some-> (state/get-sub-modals) (first) :modal/id)))
       (state/close-sub-modal! label)
       (state/close-sub-modal! label)
       (state/set-sub-modal!
       (state/set-sub-modal!
-        #(settings/modal-accent-colors-inner)
-        {:center? true
-         :id      label
-         :label   label}))))
+       #(settings/modal-accent-colors-inner)
+       {:center? true
+        :id      label
+        :label   label}))))
 
 
 (rum/defc modal-output
 (rum/defc modal-output
   [content]
   [content]
@@ -379,7 +379,6 @@
       (state/set-modal! #(diff/local-file repo path disk-content db-content)
       (state/set-modal! #(diff/local-file repo path disk-content db-content)
                         {:label "diff__cp"}))))
                         {:label "diff__cp"}))))
 
 
-
 (defmethod handle :modal/display-file-version-selector  [[_ versions path  get-content]]
 (defmethod handle :modal/display-file-version-selector  [[_ versions path  get-content]]
   (state/set-modal! #(git-component/file-version-selector versions path get-content)))
   (state/set-modal! #(git-component/file-version-selector versions path get-content)))
 
 
@@ -437,7 +436,6 @@
    (fn [_] (plugin/user-proxy-settings-panel agent-opts))
    (fn [_] (plugin/user-proxy-settings-panel agent-opts))
    {:id :https-proxy-panel :center? true}))
    {:id :https-proxy-panel :center? true}))
 
 
-
 (defmethod handle :redirect-to-home [_]
 (defmethod handle :redirect-to-home [_]
   (page-handler/create-today-journal!))
   (page-handler/create-today-journal!))
 
 
@@ -682,10 +680,10 @@
               (ipc/ipc "clearCache"))
               (ipc/ipc "clearCache"))
           _ (idb/clear-local-storage-and-idb!)]
           _ (idb/clear-local-storage-and-idb!)]
     (js/setTimeout
     (js/setTimeout
-      (fn [] (if (util/electron?)
-               (ipc/ipc :reloadWindowPage)
-               (js/window.location.reload)))
-      2000)))
+     (fn [] (if (util/electron?)
+              (ipc/ipc :reloadWindowPage)
+              (js/window.location.reload)))
+     2000)))
 
 
 (defmethod handle :graph/clear-cache! [[_]]
 (defmethod handle :graph/clear-cache! [[_]]
   (clear-cache!))
   (clear-cache!))
@@ -900,11 +898,11 @@
                                  (let [dir (config/get-repo-dir repo)]
                                  (let [dir (config/get-repo-dir repo)]
                                    (p/let [content (fs/read-file dir file)]
                                    (p/let [content (fs/read-file dir file)]
                                      (let [new-content (string/replace content (str id) (str (random-uuid)))]
                                      (let [new-content (string/replace content (str id) (str (random-uuid)))]
-                                       (p/let [_ (fs/write-file! repo
-                                                                 dir
-                                                                 file
-                                                                 new-content
-                                                                 {})]
+                                       (p/let [_ (fs/write-plain-text-file! repo
+                                                                            dir
+                                                                            file
+                                                                            new-content
+                                                                            {})]
                                          (reset! resolved? true))))))
                                          (reset! resolved? true))))))
                      :class "inline mx-1")
                      :class "inline mx-1")
           "it."]])]]))
           "it."]])]]))

+ 34 - 34
src/main/frontend/handler/file.cljs

@@ -31,9 +31,9 @@
    (p/let [content (fs/read-file (config/get-repo-dir repo-url) path)]
    (p/let [content (fs/read-file (config/get-repo-dir repo-url) path)]
      content)
      content)
    (p/catch
    (p/catch
-       (fn [e]
-         (println "Load file failed: " path)
-         (js/console.error e)))))
+    (fn [e]
+      (println "Load file failed: " path)
+      (js/console.error e)))))
 
 
 (defn load-multiple-files
 (defn load-multiple-files
   [repo-url paths]
   [repo-url paths]
@@ -63,7 +63,7 @@
     (-> (p/all (load-multiple-files repo-url files))
     (-> (p/all (load-multiple-files repo-url files))
         (p/then (fn [contents]
         (p/then (fn [contents]
                   (let [file-contents (cond->
                   (let [file-contents (cond->
-                                        (zipmap files contents)
+                                       (zipmap files contents)
 
 
                                         (seq images)
                                         (seq images)
                                         (merge (zipmap images (repeat (count images) ""))))
                                         (merge (zipmap images (repeat (count images) ""))))
@@ -114,7 +114,7 @@
         path-dir (config/get-repo-dir repo)
         path-dir (config/get-repo-dir repo)
         write-file-options' (merge write-file-options
         write-file-options' (merge write-file-options
                                    (when original-content {:old-content original-content}))]
                                    (when original-content {:old-content original-content}))]
-    (fs/write-file! repo path-dir path content write-file-options')))
+    (fs/write-plain-text-file! repo path-dir path content write-file-options')))
 
 
 (defn alter-global-file
 (defn alter-global-file
   "Does pre-checks on a global file, writes if it's not already written
   "Does pre-checks on a global file, writes if it's not already written
@@ -125,18 +125,18 @@
     (do
     (do
       (detect-deprecations path content)
       (detect-deprecations path content)
       (when (validate-file path content)
       (when (validate-file path content)
-       (-> (p/let [_ (when-not from-disk?
-                       (fs/write-file! "" nil path content {:skip-compare? true}))]
-                  (p/do! (global-config-handler/restore-global-config!)
-                         (state/pub-event! [:shortcut/refresh])))
-           (p/catch (fn [error]
-                      (state/pub-event! [:notification/show
-                                         {:content (str "Failed to write to file " path ", error: " error)
-                                          :status :error}])
-                      (log/error :write/failed error)
-                      (state/pub-event! [:capture-error
-                                         {:error error
-                                          :payload {:type :write-file/failed-for-alter-file}}]))))))
+        (-> (p/let [_ (when-not from-disk?
+                        (fs/write-plain-text-file! "" nil path content {:skip-compare? true}))]
+              (p/do! (global-config-handler/restore-global-config!)
+                     (state/pub-event! [:shortcut/refresh])))
+            (p/catch (fn [error]
+                       (state/pub-event! [:notification/show
+                                          {:content (str "Failed to write to file " path ", error: " error)
+                                           :status :error}])
+                       (log/error :write/failed error)
+                       (state/pub-event! [:capture-error
+                                          {:error error
+                                           :payload {:type :write-file/failed-for-alter-file}}]))))))
     (log/error :msg "alter-global-file does not support this file" :file path)))
     (log/error :msg "alter-global-file does not support this file" :file path)))
 
 
 (defn alter-file
 (defn alter-file
@@ -206,23 +206,23 @@
                        (when path
                        (when path
                          (let [path (gp-util/path-normalize path)
                          (let [path (gp-util/path-normalize path)
                                original-content (get file->content path)]
                                original-content (get file->content path)]
-                          (-> (p/let [_ (or
-                                         (util/electron?)
-                                         (nfs/check-directory-permission! repo))]
-                                (fs/write-file! repo (config/get-repo-dir repo) path content
-                                                {:old-content original-content}))
-                              (p/catch (fn [error]
-                                         (state/pub-event! [:notification/show
-                                                            {:content (str "Failed to save the file " path ". Error: "
-                                                                           (str error))
-                                                             :status :error
-                                                             :clear? false}])
-                                         (state/pub-event! [:capture-error
-                                                            {:error error
-                                                             :payload {:type :write-file/failed}}])
-                                         (log/error :write-file/failed {:path path
-                                                                        :content content
-                                                                        :error error})))))))
+                           (-> (p/let [_ (or
+                                          (util/electron?)
+                                          (nfs/check-directory-permission! repo))]
+                                 (fs/write-plain-text-file! repo (config/get-repo-dir repo) path content
+                                                            {:old-content original-content}))
+                               (p/catch (fn [error]
+                                          (state/pub-event! [:notification/show
+                                                             {:content (str "Failed to save the file " path ". Error: "
+                                                                            (str error))
+                                                              :status :error
+                                                              :clear? false}])
+                                          (state/pub-event! [:capture-error
+                                                             {:error error
+                                                              :payload {:type :write-file/failed}}])
+                                          (log/error :write-file/failed {:path path
+                                                                         :content content
+                                                                         :error error})))))))
         finish-handler (fn []
         finish-handler (fn []
                          (when finish-handler
                          (when finish-handler
                            (finish-handler)))]
                            (finish-handler)))]

+ 7 - 7
src/main/frontend/handler/global_config.cljs

@@ -50,30 +50,30 @@
         config-path (global-config-path)]
         config-path (global-config-path)]
     (p/let [_ (fs/mkdir-if-not-exists config-dir)
     (p/let [_ (fs/mkdir-if-not-exists config-dir)
             file-exists? (fs/create-if-not-exists repo-url nil config-path default-content)]
             file-exists? (fs/create-if-not-exists repo-url nil config-path default-content)]
-           (when-not file-exists?
-             (set-global-config-state! default-content)))))
+      (when-not file-exists?
+        (set-global-config-state! default-content)))))
 
 
 (defn restore-global-config!
 (defn restore-global-config!
   "Sets global config state from config file"
   "Sets global config state from config file"
   []
   []
   (let [config-path (global-config-path)]
   (let [config-path (global-config-path)]
     (p/let [config-content (fs/read-file nil config-path)]
     (p/let [config-content (fs/read-file nil config-path)]
-           (set-global-config-state! config-content))))
+      (set-global-config-state! config-content))))
 
 
 (defn set-global-config-kv!
 (defn set-global-config-kv!
   [k v]
   [k v]
   (let [result (rewrite/parse-string
   (let [result (rewrite/parse-string
-                 (or (state/get-global-config-str-content) "{}"))
+                (or (state/get-global-config-str-content) "{}"))
         ks (if (sequential? k) k [k])
         ks (if (sequential? k) k [k])
         v (cond->> v
         v (cond->> v
-                   (map? v)
-                   (reduce-kv (fn [a k v] (rewrite/assoc a k v)) (rewrite/parse-string "{}")))
+            (map? v)
+            (reduce-kv (fn [a k v] (rewrite/assoc a k v)) (rewrite/parse-string "{}")))
         new-result (if (and (= 1 (count ks))
         new-result (if (and (= 1 (count ks))
                             (nil? v))
                             (nil? v))
                      (rewrite/dissoc result (first ks))
                      (rewrite/dissoc result (first ks))
                      (rewrite/assoc-in result ks v))
                      (rewrite/assoc-in result ks v))
         new-str-content (str new-result)]
         new-str-content (str new-result)]
-    (fs/write-file! nil nil (global-config-path) new-str-content {:skip-compare? true})
+    (fs/write-plain-text-file! nil nil (global-config-path) new-str-content {:skip-compare? true})
     (state/set-global-config! (rewrite/sexpr new-result) new-str-content)))
     (state/set-global-config! (rewrite/sexpr new-result) new-str-content)))
 
 
 (defn start
 (defn start

+ 81 - 81
src/main/frontend/handler/plugin.cljs

@@ -27,11 +27,11 @@
   (when input
   (when input
     (let [f (fn [[k v]] (if (keyword? k) [(csk/->camelCase (name k)) v] [k v]))]
     (let [f (fn [[k v]] (if (keyword? k) [(csk/->camelCase (name k)) v] [k v]))]
       (walk/postwalk
       (walk/postwalk
-        (fn [x]
-          (cond
-            (map? x) (into {} (map f x))
-            (uuid? x) (str x)
-            :else x)) input))))
+       (fn [x]
+         (cond
+           (map? x) (into {} (map f x))
+           (uuid? x) (str x)
+           :else x)) input))))
 
 
 (defn invoke-exported-api
 (defn invoke-exported-api
   [type & args]
   [type & args]
@@ -66,16 +66,16 @@
       (p/then #(bean/->clj %))
       (p/then #(bean/->clj %))
       (p/then #(state/set-state! :plugin/preferences %))
       (p/then #(state/set-state! :plugin/preferences %))
       (p/catch
       (p/catch
-        #(js/console.error %))))
+       #(js/console.error %))))
 
 
 (defn save-plugin-preferences!
 (defn save-plugin-preferences!
   ([input] (save-plugin-preferences! input true))
   ([input] (save-plugin-preferences! input true))
   ([input reload-state?]
   ([input reload-state?]
    (when-let [^js input (and (map? input) (bean/->js input))]
    (when-let [^js input (and (map? input) (bean/->js input))]
      (p/then
      (p/then
-       (js/LSPluginCore.saveUserPreferences input)
-       #(when reload-state?
-          (load-plugin-preferences))))))
+      (js/LSPluginCore.saveUserPreferences input)
+      #(when reload-state?
+         (load-plugin-preferences))))))
 
 
 (defn gh-repo-url [repo]
 (defn gh-repo-url [repo]
   (str "https://github.com/" repo))
   (str "https://github.com/" repo))
@@ -89,42 +89,42 @@
   [refresh?]
   [refresh?]
   (if (or refresh? (nil? (:plugin/marketplace-pkgs @state/state)))
   (if (or refresh? (nil? (:plugin/marketplace-pkgs @state/state)))
     (p/create
     (p/create
-      (fn [resolve reject]
-        (let [on-ok (fn [res]
-                      (if-let [res (and res (bean/->clj res))]
-                        (let [pkgs (:packages res)]
-                          (state/set-state! :plugin/marketplace-pkgs pkgs)
-                          (resolve pkgs))
-                        (reject nil)))]
-          (if (state/http-proxy-enabled-or-val?)
-            (-> (ipc/ipc :httpFetchJSON plugins-url)
-                (p/then on-ok)
-                (p/catch reject))
-            (util/fetch plugins-url on-ok reject)))))
+     (fn [resolve reject]
+       (let [on-ok (fn [res]
+                     (if-let [res (and res (bean/->clj res))]
+                       (let [pkgs (:packages res)]
+                         (state/set-state! :plugin/marketplace-pkgs pkgs)
+                         (resolve pkgs))
+                       (reject nil)))]
+         (if (state/http-proxy-enabled-or-val?)
+           (-> (ipc/ipc :httpFetchJSON plugins-url)
+               (p/then on-ok)
+               (p/catch reject))
+           (util/fetch plugins-url on-ok reject)))))
     (p/resolved (:plugin/marketplace-pkgs @state/state))))
     (p/resolved (:plugin/marketplace-pkgs @state/state))))
 
 
 (defn load-marketplace-stats
 (defn load-marketplace-stats
   [refresh?]
   [refresh?]
   (if (or refresh? (nil? (:plugin/marketplace-stats @state/state)))
   (if (or refresh? (nil? (:plugin/marketplace-stats @state/state)))
     (p/create
     (p/create
-      (fn [resolve reject]
-        (let [on-ok (fn [^js res]
-                      (if-let [res (and res (bean/->clj res))]
-                        (do
-                          (state/set-state!
-                            :plugin/marketplace-stats
-                            (into {} (map (fn [[k stat]]
-                                            [k (assoc stat
-                                                 :total_downloads
-                                                 (reduce (fn [a b] (+ a (get b 2))) 0 (:releases stat)))])
-                                          res)))
-                          (resolve nil))
-                        (reject nil)))]
-          (if (state/http-proxy-enabled-or-val?)
-            (-> (ipc/ipc :httpFetchJSON stats-url)
-                (p/then on-ok)
-                (p/catch reject))
-            (util/fetch stats-url on-ok reject)))))
+     (fn [resolve reject]
+       (let [on-ok (fn [^js res]
+                     (if-let [res (and res (bean/->clj res))]
+                       (do
+                         (state/set-state!
+                          :plugin/marketplace-stats
+                          (into {} (map (fn [[k stat]]
+                                          [k (assoc stat
+                                                    :total_downloads
+                                                    (reduce (fn [a b] (+ a (get b 2))) 0 (:releases stat)))])
+                                        res)))
+                         (resolve nil))
+                       (reject nil)))]
+         (if (state/http-proxy-enabled-or-val?)
+           (-> (ipc/ipc :httpFetchJSON stats-url)
+               (p/then on-ok)
+               (p/catch reject))
+           (util/fetch stats-url on-ok reject)))))
     (p/resolved nil)))
     (p/resolved nil)))
 
 
 (defn check-or-update-marketplace-plugin!
 (defn check-or-update-marketplace-plugin!
@@ -164,7 +164,7 @@
     (when-let [matched (medley/find-first #(= (:key (second %)) key) commands)]
     (when-let [matched (medley/find-first #(= (:key (second %)) key) commands)]
       (let [[_ cmd action pid] matched]
       (let [[_ cmd action pid] matched]
         (state/pub-event!
         (state/pub-event!
-          [:exec-plugin-cmd {:type type :key key :pid pid :cmd (assoc cmd :args args) :action action}])))))
+         [:exec-plugin-cmd {:type type :key key :pid pid :cmd (assoc cmd :args args) :action action}])))))
 
 
 (defn open-updates-downloading
 (defn open-updates-downloading
   []
   []
@@ -207,19 +207,19 @@
                            (if (plugin-common-handler/installed? id)
                            (if (plugin-common-handler/installed? id)
                              (when-let [^js pl (get-plugin-inst id)] ;; update
                              (when-let [^js pl (get-plugin-inst id)] ;; update
                                (p/then
                                (p/then
-                                 (.reload pl)
-                                 #(do
+                                (.reload pl)
+                                #(do
                                     ;;(if theme (select-a-plugin-theme id))
                                     ;;(if theme (select-a-plugin-theme id))
-                                    (notification/show!
-                                      (t :plugin/update-plugin name (.-version (.-options pl))) :success)
-                                    (state/consume-updates-from-coming-plugin! payload true))))
+                                   (notification/show!
+                                    (t :plugin/update-plugin name (.-version (.-options pl))) :success)
+                                   (state/consume-updates-from-coming-plugin! payload true))))
 
 
                              (do                            ;; register new
                              (do                            ;; register new
                                (p/then
                                (p/then
-                                 (js/LSPluginCore.register (bean/->js {:key id :url dst}))
-                                 (fn [] (when theme (js/setTimeout #(select-a-plugin-theme id) 300))))
+                                (js/LSPluginCore.register (bean/->js {:key id :url dst}))
+                                (fn [] (when theme (js/setTimeout #(select-a-plugin-theme id) 300))))
                                (notification/show!
                                (notification/show!
-                                 (t :plugin/installed-plugin name) :success)))))
+                                (t :plugin/installed-plugin name) :success)))))
 
 
                        :error
                        :error
                        (let [error-code  (keyword (string/replace (:error-code payload) #"^[\s\:\[]+" ""))
                        (let [error-code  (keyword (string/replace (:error-code payload) #"^[\s\:\[]+" ""))
@@ -242,10 +242,10 @@
 
 
                              ;; notify human tips
                              ;; notify human tips
                              (notification/show!
                              (notification/show!
-                               (str
-                                 (if (= :error type) "[Error]" "")
-                                 (str "<" (:id payload) "> ")
-                                 msg) type)))
+                              (str
+                               (if (= :error type) "[Error]" "")
+                               (str "<" (:id payload) "> ")
+                               msg) type)))
 
 
                          (when-not fake-error?
                          (when-not fake-error?
                            (js/console.error "Update Error:" (:error-code payload))))
                            (js/console.error "Update Error:" (:error-code payload))))
@@ -298,7 +298,7 @@
                                    (get keybinding-mode-handler-map (keyword mode)))
                                    (get keybinding-mode-handler-map (keyword mode)))
                      :action     (fn []
                      :action     (fn []
                                    (state/pub-event!
                                    (state/pub-event!
-                                     [:exec-plugin-cmd {:type type :key key :pid pid :cmd cmd :action action}]))}]
+                                    [:exec-plugin-cmd {:type type :key key :pid pid :cmd cmd :action action}]))}]
     palette-cmd))
     palette-cmd))
 
 
 (defn simple-cmd-keybinding->shortcut-args
 (defn simple-cmd-keybinding->shortcut-args
@@ -455,11 +455,11 @@
     (when-not (string/blank? content)
     (when-not (string/blank? content)
       (let [content (if-not (string/blank? url)
       (let [content (if-not (string/blank? url)
                       (string/replace
                       (string/replace
-                        content #"!\[[^\]]*\]\((.*?)\s*(\"(?:.*[^\"])\")?\s*\)"
-                        (fn [[matched link]]
-                          (if (and link (not (string/starts-with? link "http")))
-                            (string/replace matched link (util/node-path.join url link))
-                            matched)))
+                       content #"!\[[^\]]*\]\((.*?)\s*(\"(?:.*[^\"])\")?\s*\)"
+                       (fn [[matched link]]
+                         (if (and link (not (string/starts-with? link "http")))
+                           (string/replace matched link (util/node-path.join url link))
+                           matched)))
                       content)]
                       content)]
         (format/to-html content :markdown (gp-mldoc/default-config :markdown))))
         (format/to-html content :markdown (gp-mldoc/default-config :markdown))))
     (catch :default e
     (catch :default e
@@ -556,7 +556,7 @@
       (p/let [repo ""
       (p/let [repo ""
               path (get-ls-dotdir-root)
               path (get-ls-dotdir-root)
               path (util/node-path.join path dirname (str key ".json"))]
               path (util/node-path.join path dirname (str key ".json"))]
-        (fs/write-file! repo nil path content {:skip-compare? true})))))
+        (fs/write-plain-text-file! repo nil path content {:skip-compare? true})))))
 
 
 (defn make-fn-to-unlink-dotdir-json
 (defn make-fn-to-unlink-dotdir-json
   [dirname]
   [dirname]
@@ -583,11 +583,11 @@
 (defn- get-user-default-plugins
 (defn- get-user-default-plugins
   []
   []
   (p/catch
   (p/catch
-    (p/let [files ^js (ipc/ipc "getUserDefaultPlugins")
-            files (js->clj files)]
-      (map #(hash-map :url %) files))
-    (fn [e]
-      (js/console.error e))))
+   (p/let [files ^js (ipc/ipc "getUserDefaultPlugins")
+           files (js->clj files)]
+     (map #(hash-map :url %) files))
+   (fn [e]
+     (js/console.error e))))
 
 
 (defn set-auto-checking!
 (defn set-auto-checking!
   [v]
   [v]
@@ -693,7 +693,7 @@
   (let [el (js/document.createElement "div")]
   (let [el (js/document.createElement "div")]
     (.appendChild js/document.body el)
     (.appendChild js/document.body el)
     (rum/mount
     (rum/mount
-      (lsp-indicator) el))
+     (lsp-indicator) el))
 
 
   (state/set-state! :plugin/indicator-text "LOADING")
   (state/set-state! :plugin/indicator-text "LOADING")
 
 
@@ -713,12 +713,12 @@
                                 (.on "registered"
                                 (.on "registered"
                                      (fn [^js pl]
                                      (fn [^js pl]
                                        (register-plugin
                                        (register-plugin
-                                         (bean/->clj (.parse js/JSON (.stringify js/JSON pl))))))
+                                        (bean/->clj (.parse js/JSON (.stringify js/JSON pl))))))
 
 
                                 (.on "reloaded"
                                 (.on "reloaded"
                                      (fn [^js pl]
                                      (fn [^js pl]
                                        (register-plugin
                                        (register-plugin
-                                         (bean/->clj (.parse js/JSON (.stringify js/JSON pl))))))
+                                        (bean/->clj (.parse js/JSON (.stringify js/JSON pl))))))
 
 
                                 (.on "unregistered" (fn [pid]
                                 (.on "unregistered" (fn [pid]
                                                       (let [pid (keyword pid)]
                                                       (let [pid (keyword pid)]
@@ -775,15 +775,15 @@
                                                (when-let [plugins (and perf-table (.entries perf-table))]
                                                (when-let [plugins (and perf-table (.entries perf-table))]
                                                  (->> plugins
                                                  (->> plugins
                                                       (keep
                                                       (keep
-                                                        (fn [[_k ^js v]]
-                                                          (when-let [end (and (some-> v (.-o) (.-disabled) (not))
-                                                                              (.-e v))]
-                                                            (when (and (number? end)
+                                                       (fn [[_k ^js v]]
+                                                         (when-let [end (and (some-> v (.-o) (.-disabled) (not))
+                                                                             (.-e v))]
+                                                           (when (and (number? end)
                                                                        ;; valid end time
                                                                        ;; valid end time
-                                                                       (> end 0)
+                                                                      (> end 0)
                                                                        ;; greater than 6s
                                                                        ;; greater than 6s
-                                                                       (> (- end (.-s v)) 6000))
-                                                              v))))
+                                                                      (> (- end (.-s v)) 6000))
+                                                             v))))
                                                       ((fn [perfs]
                                                       ((fn [perfs]
                                                          (doseq [perf perfs]
                                                          (doseq [perf perfs]
                                                            (state/pub-event! [:plugin/loader-perf-tip (bean/->clj perf)])))))))))
                                                            (state/pub-event! [:plugin/loader-perf-tip (bean/->clj perf)])))))))))
@@ -793,13 +793,13 @@
               _               (.register js/LSPluginCore (bean/->js (if (seq default-plugins) default-plugins [])) true)])
               _               (.register js/LSPluginCore (bean/->js (if (seq default-plugins) default-plugins [])) true)])
 
 
       (p/then
       (p/then
-        (fn []
-          (state/set-state! :plugin/indicator-text "END")
-          (callback)))
+       (fn []
+         (state/set-state! :plugin/indicator-text "END")
+         (callback)))
       (p/catch
       (p/catch
-        (fn [^js e]
-          (log/error :setup-plugin-system-error e)
-          (state/set-state! :plugin/indicator-text (str "Fatal: " e))))))
+       (fn [^js e]
+         (log/error :setup-plugin-system-error e)
+         (state/set-state! :plugin/indicator-text (str "Fatal: " e))))))
 
 
 (defn setup!
 (defn setup!
   "setup plugin core handler"
   "setup plugin core handler"
@@ -813,4 +813,4 @@
    :auto-checking? (boolean (:plugin/updates-auto-checking? @state/state))
    :auto-checking? (boolean (:plugin/updates-auto-checking? @state/state))
    :coming         (count (:plugin/updates-coming @state/state))
    :coming         (count (:plugin/updates-coming @state/state))
    :installing     (:plugin/installing @state/state)
    :installing     (:plugin/installing @state/state)
-   :downloading?   (boolean (:plugin/updates-downloading? @state/state))})
+   :downloading?   (boolean (:plugin/updates-downloading? @state/state))})

+ 12 - 12
src/main/frontend/handler/plugin_config.cljs

@@ -39,14 +39,14 @@ when a plugin is installed, updated or removed"
                               str)]
                               str)]
          ;; fs protocols require repo and dir when they aren't necessary. For this component,
          ;; fs protocols require repo and dir when they aren't necessary. For this component,
          ;; neither is needed so these are blank and nil respectively
          ;; neither is needed so these are blank and nil respectively
-         (fs/write-file! "" nil (plugin-config-path) updated-content {:skip-compare? true})))
+    (fs/write-plain-text-file! "" nil (plugin-config-path) updated-content {:skip-compare? true})))
 
 
 (defn remove-plugin
 (defn remove-plugin
   "Removes a plugin from plugin.edn"
   "Removes a plugin from plugin.edn"
   [plugin-id]
   [plugin-id]
   (p/let [content (fs/read-file "" (plugin-config-path))
   (p/let [content (fs/read-file "" (plugin-config-path))
           updated-content (-> content rewrite/parse-string (rewrite/dissoc (keyword plugin-id)) str)]
           updated-content (-> content rewrite/parse-string (rewrite/dissoc (keyword plugin-id)) str)]
-    (fs/write-file! "" nil (plugin-config-path) updated-content {:skip-compare? true})))
+    (fs/write-plain-text-file! "" nil (plugin-config-path) updated-content {:skip-compare? true})))
 
 
 (defn- create-plugin-config-file-if-not-exists
 (defn- create-plugin-config-file-if-not-exists
   []
   []
@@ -79,16 +79,16 @@ returns map of plugins to install and uninstall"
   (p/catch
   (p/catch
    (p/let [edn-plugins* (fs/read-file nil (plugin-config-path))
    (p/let [edn-plugins* (fs/read-file nil (plugin-config-path))
            edn-plugins (edn/read-string edn-plugins*)]
            edn-plugins (edn/read-string edn-plugins*)]
-          (if-let [errors (->> edn-plugins (m/explain plugin-config-schema/Plugins-edn) me/humanize)]
-            (do
-              (notification/show! "Invalid plugins.edn provided. See javascript console for specific errors"
-                                  :error)
-              (log/error :plugin-edn-errors errors)
-              (println "Invalid plugins.edn, errors: " errors))
-            (let [plugins-to-change (determine-plugins-to-change
-                                     (:plugin/installed-plugins @state/state)
-                                     edn-plugins)]
-              (state/pub-event! [:go/plugins-from-file plugins-to-change]))))
+     (if-let [errors (->> edn-plugins (m/explain plugin-config-schema/Plugins-edn) me/humanize)]
+       (do
+         (notification/show! "Invalid plugins.edn provided. See javascript console for specific errors"
+                             :error)
+         (log/error :plugin-edn-errors errors)
+         (println "Invalid plugins.edn, errors: " errors))
+       (let [plugins-to-change (determine-plugins-to-change
+                                (:plugin/installed-plugins @state/state)
+                                edn-plugins)]
+         (state/pub-event! [:go/plugins-from-file plugins-to-change]))))
    (fn [e]
    (fn [e]
      (if (= :reader-exception (:type (ex-data e)))
      (if (= :reader-exception (:type (ex-data e)))
        (notification/show! "Malformed plugins.edn provided. Please check the file has correct edn syntax."
        (notification/show! "Malformed plugins.edn provided. Please check the file has correct edn syntax."

+ 3 - 7
src/main/frontend/util/persist_var.cljs

@@ -8,8 +8,7 @@
             [cljs.reader :as reader]
             [cljs.reader :as reader]
             [promesa.core :as p]))
             [promesa.core :as p]))
 
 
-
-(defn- load-rpath 
+(defn- load-rpath
   "Returns the relative path to the file that stores the persist-var"
   "Returns the relative path to the file that stores the persist-var"
   [location]
   [location]
   (str config/app-name "/" location ".edn"))
   (str config/app-name "/" location ".edn"))
@@ -67,7 +66,7 @@
             repo (state/get-current-repo)
             repo (state/get-current-repo)
             content (str (get-in @*value [repo :value]))
             content (str (get-in @*value [repo :value]))
             dir (config/get-repo-dir repo)]
             dir (config/get-repo-dir repo)]
-        (fs/write-file! repo dir path content {:skip-compare? true}))))
+        (fs/write-plain-text-file! repo dir path content {:skip-compare? true}))))
 
 
   IDeref
   IDeref
   (-deref [_this]
   (-deref [_this]
@@ -83,7 +82,6 @@
   (-pr-writer [_ w _opts]
   (-pr-writer [_ w _opts]
     (write-all w (str "#PersistVar[" @*value ", loc: " location "]"))))
     (write-all w (str "#PersistVar[" @*value ", loc: " location "]"))))
 
 
-
 (def *all-persist-vars (atom []))
 (def *all-persist-vars (atom []))
 
 
 (defn load-vars []
 (defn load-vars []
@@ -106,6 +104,4 @@
 (comment
 (comment
   (do
   (do
     (def bbb (persist-var 1 "aaa"))
     (def bbb (persist-var 1 "aaa"))
-    (-save bbb)
-
-    ))
+    (-save bbb)))

+ 59 - 59
src/main/logseq/api.cljs

@@ -89,25 +89,25 @@
   ;; get app base info
   ;; get app base info
   []
   []
   (bean/->js
   (bean/->js
-    (sdk-utils/normalize-keyword-for-json
-      {:version fv/version})))
+   (sdk-utils/normalize-keyword-for-json
+    {:version fv/version})))
 
 
 (def ^:export get_user_configs
 (def ^:export get_user_configs
   (fn []
   (fn []
     (bean/->js
     (bean/->js
-      (sdk-utils/normalize-keyword-for-json
-        {:preferred-language      (:preferred-language @state/state)
-         :preferred-theme-mode    (:ui/theme @state/state)
-         :preferred-format        (state/get-preferred-format)
-         :preferred-workflow      (state/get-preferred-workflow)
-         :preferred-todo          (state/get-preferred-todo)
-         :preferred-date-format   (state/get-date-formatter)
-         :preferred-start-of-week (state/get-start-of-week)
-         :current-graph           (state/get-current-repo)
-         :show-brackets           (state/show-brackets?)
-         :enabled-journals        (state/enable-journals?)
-         :enabled-flashcards      (state/enable-flashcards?)
-         :me                      (state/get-me)}))))
+     (sdk-utils/normalize-keyword-for-json
+      {:preferred-language      (:preferred-language @state/state)
+       :preferred-theme-mode    (:ui/theme @state/state)
+       :preferred-format        (state/get-preferred-format)
+       :preferred-workflow      (state/get-preferred-workflow)
+       :preferred-todo          (state/get-preferred-todo)
+       :preferred-date-format   (state/get-date-formatter)
+       :preferred-start-of-week (state/get-start-of-week)
+       :current-graph           (state/get-current-repo)
+       :show-brackets           (state/show-brackets?)
+       :enabled-journals        (state/enable-journals?)
+       :enabled-flashcards      (state/enable-flashcards?)
+       :me                      (state/get-me)}))))
 
 
 (def ^:export get_current_graph_configs
 (def ^:export get_current_graph_configs
   (fn [& keys]
   (fn [& keys]
@@ -173,7 +173,7 @@
     (let [repo ""
     (let [repo ""
 
 
           path (util/node-path.join path "package.json")]
           path (util/node-path.join path "package.json")]
-      (fs/write-file! repo nil path (js/JSON.stringify data nil 2) {:skip-compare? true}))))
+      (fs/write-plain-text-file! repo nil path (js/JSON.stringify data nil 2) {:skip-compare? true}))))
 
 
 (def ^:export save_focused_code_editor_content
 (def ^:export save_focused_code_editor_content
   (fn []
   (fn []
@@ -193,7 +193,7 @@
           user-path-root (util/node-path.dirname user-path)
           user-path-root (util/node-path.dirname user-path)
           exist?         (fs/file-exists? user-path-root "")
           exist?         (fs/file-exists? user-path-root "")
           _              (when-not exist? (fs/mkdir-recur! user-path-root))
           _              (when-not exist? (fs/mkdir-recur! user-path-root))
-          _              (fs/write-file! repo nil user-path content {:skip-compare? true})]
+          _              (fs/write-plain-text-file! repo nil user-path content {:skip-compare? true})]
     user-path))
     user-path))
 
 
 (defn ^:private write_dotdir_file
 (defn ^:private write_dotdir_file
@@ -284,8 +284,8 @@
                         (plugin-handler/get-ls-dotdir-root))
                         (plugin-handler/get-ls-dotdir-root))
             plugin-id (util/node-path.basename plugin-id)
             plugin-id (util/node-path.basename plugin-id)
             exist?    (fs/file-exists?
             exist?    (fs/file-exists?
-                        (util/node-path.join root "storages" plugin-id)
-                        file)]
+                       (util/node-path.join root "storages" plugin-id)
+                       file)]
       exist?)))
       exist?)))
 
 
 (def ^:export clear_plugin_storage_files
 (def ^:export clear_plugin_storage_files
@@ -306,8 +306,8 @@
             ^js files  (ipc/ipc :listdir files-path)]
             ^js files  (ipc/ipc :listdir files-path)]
       (when (js-iterable? files)
       (when (js-iterable? files)
         (bean/->js
         (bean/->js
-          (map #(some-> (string/replace-first % files-path "")
-                        (string/replace #"^/+" "")) files))))))
+         (map #(some-> (string/replace-first % files-path "")
+                       (string/replace #"^/+" "")) files))))))
 
 
 (def ^:export load_user_preferences
 (def ^:export load_user_preferences
   (fn []
   (fn []
@@ -325,7 +325,7 @@
       (p/let [repo ""
       (p/let [repo ""
               path (plugin-handler/get-ls-dotdir-root)
               path (plugin-handler/get-ls-dotdir-root)
               path (util/node-path.join path "preferences.json")]
               path (util/node-path.join path "preferences.json")]
-        (fs/write-file! repo nil path (js/JSON.stringify data nil 2) {:skip-compare? true})))))
+        (fs/write-plain-text-file! repo nil path (js/JSON.stringify data nil 2) {:skip-compare? true})))))
 
 
 (def ^:export load_plugin_user_settings
 (def ^:export load_plugin_user_settings
   ;; results [path data]
   ;; results [path data]
@@ -343,8 +343,8 @@
   (fn [pid ^js cmd-actions]
   (fn [pid ^js cmd-actions]
     (when-let [[cmd actions] (bean/->clj cmd-actions)]
     (when-let [[cmd actions] (bean/->clj cmd-actions)]
       (plugin-handler/register-plugin-slash-command
       (plugin-handler/register-plugin-slash-command
-        pid [cmd (mapv #(into [(keyword (first %))]
-                              (rest %)) actions)]))))
+       pid [cmd (mapv #(into [(keyword (first %))]
+                             (rest %)) actions)]))))
 
 
 (def ^:export register_plugin_simple_command
 (def ^:export register_plugin_simple_command
   (fn [pid ^js cmd-action palette?]
   (fn [pid ^js cmd-action palette?]
@@ -409,7 +409,7 @@
   (fn [pid type ^js opts]
   (fn [pid type ^js opts]
     (when-let [opts (bean/->clj opts)]
     (when-let [opts (bean/->clj opts)]
       (plugin-handler/register-plugin-ui-item
       (plugin-handler/register-plugin-ui-item
-        pid (assoc opts :type type)))))
+       pid (assoc opts :type type)))))
 
 
 ;; app
 ;; app
 (def ^:export relaunch
 (def ^:export relaunch
@@ -559,12 +559,12 @@
               (let [properties (bean/->clj properties)
               (let [properties (bean/->clj properties)
                     {:keys [redirect createFirstBlock format journal]} (bean/->clj opts)
                     {:keys [redirect createFirstBlock format journal]} (bean/->clj opts)
                     name       (page-handler/create!
                     name       (page-handler/create!
-                                 name
-                                 {:redirect?           (if (boolean? redirect) redirect true)
-                                  :journal?            journal
-                                  :create-first-block? (if (boolean? createFirstBlock) createFirstBlock true)
-                                  :format              format
-                                  :properties          properties})]
+                                name
+                                {:redirect?           (if (boolean? redirect) redirect true)
+                                 :journal?            journal
+                                 :create-first-block? (if (boolean? createFirstBlock) createFirstBlock true)
+                                 :format              format
+                                 :properties          properties})]
                 (db-model/get-page name)))
                 (db-model/get-page name)))
             (:db/id)
             (:db/id)
             (db-utils/pull)
             (db-utils/pull)
@@ -581,9 +581,9 @@
 (defn ^:export open_in_right_sidebar
 (defn ^:export open_in_right_sidebar
   [block-id-or-uuid]
   [block-id-or-uuid]
   (editor-handler/open-block-in-sidebar!
   (editor-handler/open-block-in-sidebar!
-    (if (number? block-id-or-uuid)
-      block-id-or-uuid
-      (sdk-utils/uuid-or-throw-error block-id-or-uuid))))
+   (if (number? block-id-or-uuid)
+     block-id-or-uuid
+     (sdk-utils/uuid-or-throw-error block-id-or-uuid))))
 
 
 (defn ^:export new_block_uuid []
 (defn ^:export new_block_uuid []
   (str (db/new-block-id)))
   (str (db/new-block-id)))
@@ -616,7 +616,7 @@
           edit-block?            (if (nil? focus) true focus)
           edit-block?            (if (nil? focus) true focus)
           _                      (when (and custom-uuid (db-model/query-block-by-uuid custom-uuid))
           _                      (when (and custom-uuid (db-model/query-block-by-uuid custom-uuid))
                                    (throw (js/Error.
                                    (throw (js/Error.
-                                            (util/format "Custom block UUID already exists (%s)." custom-uuid))))
+                                           (util/format "Custom block UUID already exists (%s)." custom-uuid))))
           block-uuid'            (if (and (not sibling) before block-uuid)
           block-uuid'            (if (and (not sibling) before block-uuid)
                                    (let [block       (db/entity [:block/uuid block-uuid])
                                    (let [block       (db/entity [:block/uuid block-uuid])
                                          first-child (db-model/get-by-parent-&-left (db/get-db)
                                          first-child (db-model/get-by-parent-&-left (db/get-db)
@@ -634,16 +634,16 @@
                                    false
                                    false
                                    before?)
                                    before?)
           new-block              (editor-handler/api-insert-new-block!
           new-block              (editor-handler/api-insert-new-block!
-                                   content
-                                   {:block-uuid    block-uuid'
-                                    :sibling?      sibling?
-                                    :before?       before?
-                                    :edit-block?   edit-block?
-                                    :page          page-name
-                                    :custom-uuid   custom-uuid
-                                    :ordered-list? (if (boolean? autoOrderedList) autoOrderedList false)
-                                    :properties    (merge properties
-                                                     (when custom-uuid {:id custom-uuid}))})]
+                                  content
+                                  {:block-uuid    block-uuid'
+                                   :sibling?      sibling?
+                                   :before?       before?
+                                   :edit-block?   edit-block?
+                                   :page          page-name
+                                   :custom-uuid   custom-uuid
+                                   :ordered-list? (if (boolean? autoOrderedList) autoOrderedList false)
+                                   :properties    (merge properties
+                                                         (when custom-uuid {:id custom-uuid}))})]
       (bean/->js (sdk-utils/normalize-keyword-for-json new-block)))))
       (bean/->js (sdk-utils/normalize-keyword-for-json new-block)))))
 
 
 (def ^:export insert_batch_block
 (def ^:export insert_batch_block
@@ -658,11 +658,11 @@
                                    (let [uuid (:id (:properties block))]
                                    (let [uuid (:id (:properties block))]
                                      (when (and uuid (db-model/query-block-by-uuid (sdk-utils/uuid-or-throw-error uuid)))
                                      (when (and uuid (db-model/query-block-by-uuid (sdk-utils/uuid-or-throw-error uuid)))
                                        (throw (js/Error.
                                        (throw (js/Error.
-                                                (util/format "Custom block UUID already exists (%s)." uuid)))))))
+                                               (util/format "Custom block UUID already exists (%s)." uuid)))))))
               block (if (and before sibling)
               block (if (and before sibling)
                       (db/pull (:db/id (:block/left block))) block)
                       (db/pull (:db/id (:block/left block))) block)
               _ (editor-handler/insert-block-tree-after-target
               _ (editor-handler/insert-block-tree-after-target
-                  (:db/id block) sibling bb (:block/format block) keep-uuid?)]
+                 (:db/id block) sibling bb (:block/format block) keep-uuid?)]
           nil)))))
           nil)))))
 
 
 (def ^:export remove_block
 (def ^:export remove_block
@@ -670,7 +670,7 @@
     (let [includeChildren true
     (let [includeChildren true
           repo            (state/get-current-repo)]
           repo            (state/get-current-repo)]
       (editor-handler/delete-block-aux!
       (editor-handler/delete-block-aux!
-        {:block/uuid (sdk-utils/uuid-or-throw-error block-uuid) :repo repo} includeChildren)
+       {:block/uuid (sdk-utils/uuid-or-throw-error block-uuid) :repo repo} includeChildren)
       nil)))
       nil)))
 
 
 (def ^:export update_block
 (def ^:export update_block
@@ -736,7 +736,7 @@
                      (not (util/collapsed? block))
                      (not (util/collapsed? block))
                      (boolean flag))]
                      (boolean flag))]
           (if flag (editor-handler/collapse-block! block-uuid)
           (if flag (editor-handler/collapse-block! block-uuid)
-                   (editor-handler/expand-block! block-uuid))
+              (editor-handler/expand-block! block-uuid))
           nil)))))
           nil)))))
 
 
 (def ^:export upsert_block_property
 (def ^:export upsert_block_property
@@ -860,7 +860,7 @@
   [query-string]
   [query-string]
   (when-let [repo (state/get-current-repo)]
   (when-let [repo (state/get-current-repo)]
     (when-let [result (query-dsl/query repo query-string
     (when-let [result (query-dsl/query repo query-string
-                        {:disable-reactive? true})]
+                                       {:disable-reactive? true})]
       (bean/->js (sdk-utils/normalize-keyword-for-json (flatten @result))))))
       (bean/->js (sdk-utils/normalize-keyword-for-json (flatten @result))))))
 
 
 (defn ^:export datascript_query
 (defn ^:export datascript_query
@@ -926,25 +926,25 @@
                   init?      (plugin-handler/register-plugin-resources pid :scripts {:key s :src s})]]
                   init?      (plugin-handler/register-plugin-resources pid :scripts {:key s :src s})]]
       (when init?
       (when init?
         (p/catch
         (p/catch
-          (p/then
-            (do
-              (upt-status :pending)
-              (loader/load s nil {:attributes {:data-ref (name pid)}}))
-            #(upt-status :done))
-          #(upt-status :error))))))
+         (p/then
+          (do
+            (upt-status :pending)
+            (loader/load s nil {:attributes {:data-ref (name pid)}}))
+          #(upt-status :done))
+         #(upt-status :error))))))
 
 
 (defn ^:export exper_register_fenced_code_renderer
 (defn ^:export exper_register_fenced_code_renderer
   [pid type ^js opts]
   [pid type ^js opts]
   (when-let [^js _pl (plugin-handler/get-plugin-inst pid)]
   (when-let [^js _pl (plugin-handler/get-plugin-inst pid)]
     (plugin-handler/register-fenced-code-renderer
     (plugin-handler/register-fenced-code-renderer
-      (keyword pid) type (reduce #(assoc %1 %2 (aget opts (name %2))) {}
-                                 [:edit :before :subs :render]))))
+     (keyword pid) type (reduce #(assoc %1 %2 (aget opts (name %2))) {}
+                                [:edit :before :subs :render]))))
 
 
 (defn ^:export exper_register_extensions_enhancer
 (defn ^:export exper_register_extensions_enhancer
   [pid type enhancer]
   [pid type enhancer]
   (when-let [^js _pl (and (fn? enhancer) (plugin-handler/get-plugin-inst pid))]
   (when-let [^js _pl (and (fn? enhancer) (plugin-handler/get-plugin-inst pid))]
     (plugin-handler/register-extensions-enhancer
     (plugin-handler/register-extensions-enhancer
-      (keyword pid) type {:enhancer enhancer})))
+     (keyword pid) type {:enhancer enhancer})))
 
 
 (defonce *request-k (volatile! 0))
 (defonce *request-k (volatile! 0))
 
 

+ 2 - 2
src/main/logseq/sdk/git.cljs

@@ -18,11 +18,11 @@
             dir (config/get-repo-dir repo)
             dir (config/get-repo-dir repo)
             _ (fs/create-if-not-exists repo dir file)
             _ (fs/create-if-not-exists repo dir file)
             content (fs/read-file dir file)]
             content (fs/read-file dir file)]
-           content)))
+      content)))
 
 
 (defn ^:export save_ignore_file
 (defn ^:export save_ignore_file
   [content]
   [content]
   (when-let [repo (and (string? content) (state/get-current-repo))]
   (when-let [repo (and (string? content) (state/get-current-repo))]
     (p/let [file ".gitignore"
     (p/let [file ".gitignore"
             dir (config/get-repo-dir repo)
             dir (config/get-repo-dir repo)
-            _ (fs/write-file! repo dir file content {:skip-compare? true})])))
+            _ (fs/write-plain-text-file! repo dir file content {:skip-compare? true})])))