Просмотр исходного кода

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

Tienson Qin 9 месяцев назад
Родитель
Сommit
cf8947da04

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

@@ -67,7 +67,7 @@
     (let [repo-cur (state/get-current-repo)
           repo-dir (config/get-repo-dir repo-cur)
           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$
   [target-key]
@@ -116,15 +116,14 @@
                                   new-fpath  (str fdir "/" fname "_" fstamp ".png")
                                   old-fpath  (and old-fstamp (str fdir "/" fname "_" old-fstamp ".png"))
                                   _          (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))
 
                           (fn [err]
                             (js/console.error "[write area image Error]" err))))]
 
-          (.toBlob canvas' callback))
-        ))))
+          (.toBlob canvas' callback))))))
 
 (defn update-hl-block!
   [highlight]

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

@@ -89,7 +89,7 @@
       (protocol/rmdir! fs dir))))
 
 ;; 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"
   [repo dir rpath content opts]
   (when content
@@ -215,7 +215,7 @@
          true)
        (p/catch
         (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))))))
 
 (defn file-exists?

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

@@ -163,8 +163,7 @@
                  :remote->local-full-sync-failed
                  :local->remote-full-sync-failed
                  :get-remote-graph-failed
-                 :get-deletion-logs-failed
-                 })
+                 :get-deletion-logs-failed})
 
 (s/def ::sync-event (s/keys :req-un [::event ::data]))
 
@@ -197,7 +196,6 @@
   [x]
   (when (instance? ExceptionInfo x) x))
 
-
 (def ws-addr config/WS-URL)
 
 ;; Warning: make sure to `persist-var/-load` graphs-txid before using it.
@@ -325,9 +323,9 @@
 (defn <request [api-name & args]
   (let [name (str api-name (.now js/Date))]
     (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]
   (let [r (string/replace path (js/RegExp. (str "^" (gstring/regExpEscape dir))) "")]
@@ -416,19 +414,19 @@
   (let [update? (= "update_files" TXType)
         delete? (= "delete_files" TXType)
         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
-                (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
-                (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
              "delete_files" delete-xf
              "update_files" update-xf
@@ -565,7 +563,6 @@
    (map-indexed filepath+checksum->diff)
    (diffs->partitioned-filetxns n)))
 
-
 (deftype FileMetadata [size etag path encrypted-path last-modified remote? txid ^:mutable normalized-path]
   Object
   (get-normalized-path [_]
@@ -601,13 +598,10 @@
       :txid txid
       not-found))
 
-
   IPrintWithWriter
   (-pr-writer [_ w _opts]
     (write-all w (str {:size size :etag etag :path path :remote? remote? :txid txid :last-modified last-modified}))))
 
-
-
 (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),
   even local-file's last-modified > remote-file's last-modified.
@@ -664,21 +658,21 @@
    #{} s1))
 
 (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
   FileMetadata
@@ -731,7 +725,6 @@
 
   gp-util/path-normalize)
 
-
 ;;; ### APIs
 ;; `RSAPI` call apis through rsapi package, supports operations on files
 
@@ -770,16 +763,13 @@
   (<get-graph-encrypt-keys [this graph-uuid])
   (<upload-graph-encrypt-keys [this graph-uuid public-key encrypted-private-key]))
 
-
 (defprotocol IRemoteControlAPI
   "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
   (<get-token [this]))
 
-
 (defn <case-different-local-file-exist?
   "e.g. filepath=\"pages/Foo.md\"
   found-filepath=\"pages/foo.md\"
@@ -1133,8 +1123,8 @@
      (go-loop []
        (let [{:keys [val stop]}
              (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
            stop (do (async/unmix-all out-mix)
                     (doseq [[topic ch] topic&chs]
@@ -1143,12 +1133,10 @@
            val (do (pp/pprint [:debug :sync-event val])
                    (recur))))))))
 
-
 (defn stop-debug-print-sync-events-loop
   []
   (offer! debug-print-sync-events-loop-stop-chan true))
 
-
 ;;; sync events ends
 
 (defn- fire-file-sync-storage-exceed-limit-event!
@@ -1237,7 +1225,6 @@
                 (recur result-file-meta-list others))))
         (vals (persistent! result-file-meta-list))))))
 
-
 (extend-type RemoteAPI
   IRemoteAPI
   (<user-info [this]
@@ -1443,13 +1430,10 @@
 
 (comment
   (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 ^:private *get-graph-salt-memoize-cache (atom {}))
 (defn update-graph-salt-cache [graph-uuid v]
   {:pre [(map? v)
@@ -1526,9 +1510,6 @@
           val val
           timeout (recur))))))
 
-
-
-
 (defn- assert-local-txid<=remote-txid
   []
   (when-let [local-txid (last @graphs-txid)]
@@ -1553,7 +1534,6 @@
          sync-state--remove-recent-remote->local-files
          sync-state--stopped?)
 
-
 (defn- filetxns=>recent-remote->local-files
   [filetxns]
   (let [{:keys [update-filetxns delete-filetxns rename-filetxns]}
@@ -1615,7 +1595,7 @@
                                       (fs/unlink! repo (path/path-join repo-dir base-file) {}))
                                      ;; base-content != current-content, merge, do not delete
                                      (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
                                                                                                          :from-disk? true
                                                                                                          :fs/event :fs/remote-file-change}))))
@@ -1665,7 +1645,7 @@
                                                     merged-content (diff-merge/three-way-merge base-content incoming-content current-content format)]
                                               (when (seq merged-content)
                                                 (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
                                                                                                                    :from-disk? true
                                                                                                                    :fs/event :fs/remote-file-change})))))))
@@ -1692,7 +1672,7 @@
 
                                           ;; else
                                             (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
                                                                                                                :from-disk? true
                                                                                                                :fs/event :fs/remote-file-change})))))))))))))))))
@@ -1729,8 +1709,8 @@
                      [recent-remote->local-file-item])
               (<! (<delete-local-files rsapi graph-uuid base-path [relative-p*]))
               (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?)
                                       (<fetch-remote-and-update-local-files graph-uuid base-path (map relative-path filetxns))
@@ -1786,8 +1766,8 @@
                                                      (not (instance? ExceptionInfo r)))]
           ;; remove these recent-remote->local-file-items 5s later
           (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
             (instance? ExceptionInfo r) r
             @*paused                    {:pause true}
@@ -1846,7 +1826,6 @@
   [r]
   (some->> (ex-cause r) str (re-find #"Request is not yet valid")))
 
-
 ;; type = "change" | "add" | "unlink"
 (deftype FileChangeEvent [type dir path stat checksum]
   IRelativePath
@@ -1881,7 +1860,6 @@
   (-pr-writer [_ w _opts]
     (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
   "return nil when related local files not found"
   [graph-uuid ^FileChangeEvent e]
@@ -1954,8 +1932,8 @@
     (go-loop []
       (let [{:keys [rename-event local-change]}
             (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
           rename-event
           (let [repo-dir (config/get-repo-dir (:repo rename-event))
@@ -1968,13 +1946,13 @@
             (swap! *rename-events conj k1 k2)
             ;; remove rename-events after 2s
             (go (<! (timeout 3000))
-              (swap! *rename-events disj k1 k2))
+                (swap! *rename-events disj k1 k2))
             ;; add 2 simulated file-watcher events
             (>! ch (->FileChangeEvent "unlink" repo-dir (:old-path rename-event*) nil nil))
             (>! ch (->FileChangeEvent "add" repo-dir (:new-path rename-event*)
                                       {:mtime (tc/to-long (t/now))
                                        :size 1 ; add a fake size
-                                       } "fake-checksum"))
+                                       }"fake-checksum"))
             (recur))
           local-change
           (cond
@@ -2051,7 +2029,6 @@
     (js/localStorage.removeItem k))
   (reset! pwd-map {}))
 
-
 (defn encrypt+persist-pwd!
   "- persist encrypted pwd at local-storage"
   [pwd graph-uuid]
@@ -2099,7 +2076,6 @@
       (when (and private-key (string/starts-with? private-key "AGE-SECRET-KEY"))
         (set-keys&notify graph-uuid public-key private-key)))))
 
-
 (def <restored-pwd (chan (async/sliding-buffer 1)))
 (def <restored-pwd-pub (async/pub <restored-pwd :graph-uuid))
 
@@ -2129,7 +2105,6 @@
   (swap! pwd-map dissoc graph-uuid)
   (remove-pwd! graph-uuid))
 
-
 (defn- <loop-ensure-pwd&keys
   [graph-uuid repo *stopped?]
   (let [<restored-pwd-sub-chan (chan 1)]
@@ -2191,7 +2166,6 @@
                       (clear-pwd! graph-uuid)
                       (recur))))))))))
 
-
 (defn- <set-env&keys
   [prod? graph-uuid]
   (let [{:keys [private-key public-key]} (get @pwd-map graph-uuid)]
@@ -2246,7 +2220,6 @@
            (fn [_ _ _ _]
              (offer! recent-edited-chan true)))
 
-
 ;;; ### sync state
 
 (def *resume-state
@@ -2390,7 +2363,6 @@
   (contains? #{::idle ::local->remote ::remote->local ::local->remote-full-sync ::remote->local-full-sync}
              (:state sync-state)))
 
-
 ;;; ### remote->local syncer & local->remote syncer
 
 (defprotocol IRemote->LocalSync
@@ -2646,11 +2618,11 @@
          local-files-meta-map))))
 
 (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
-                       private-immediately-local->remote-chan private-recent-edited-chan]
+                      private-immediately-local->remote-chan private-recent-edited-chan]
   Object
   (filter-file-change-events-fn [_]
     (fn [^FileChangeEvent e]
@@ -2817,21 +2789,21 @@
                                             <!
                                             (sort-by (sort-file-metadata-fn :recent-days-range recent-10-days-range) >))
                 change-events
-                                       (sequence
-                                        (comp
+                (sequence
+                 (comp
                                          ;; 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)
                                            filter-upload-files-with-reserved-chars)
                 _                      (swap! *sync-state #(sync-state-reset-full-local->remote-files % distinct-change-events))
                 change-events-partitions
-                                       (sequence
+                (sequence
                                         ;; 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)]"
                      (count (flatten change-events-partitions)) "files need to sync and"
                      (count delete-local-files) "local files need to delete")
@@ -2852,8 +2824,8 @@
                              [fake-recent-remote->local-file-item])
                       (<! (<delete-local-files rsapi graph-uuid base-path [(relative-path f)]))
                       (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)))
 
             ;; 2. upload local files
@@ -2871,13 +2843,12 @@
                               (or need-sync-remote graph-has-been-deleted unknown stop) r)))))]
               ;; update *txid-for-get-deletion-log
               (reset! *txid-for-get-deletion-log @*txid)
-              r
-              )))))))
+              r)))))))
 
 ;;; ### put all stuff together
 
 (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
               ^:mutable ratelimit-local-changes-chan
               *txid *txid-for-get-deletion-log
@@ -3281,7 +3252,6 @@
     (reset! current-sm-graph-uuid graph-uuid)
     (sync-manager user-uuid graph-uuid base-path repo txid *sync-state)))
 
-
 (defn <sync-stop []
   (go
     (when-let [sm ^SyncManager (state/get-file-sync-manager (state/get-current-file-sync-graph-uuid))]
@@ -3324,15 +3294,15 @@
   (go
     (let [r (<! (<list-remote-graphs remoteapi))
           result
-            (or
+          (or
              ;; 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
         (notification/show! (t :file-sync/graph-deleted) :warning false))
@@ -3352,7 +3322,6 @@
   (when-let [graph-uuid (second @graphs-txid)]
     (get-pwd graph-uuid)))
 
-
 (defn- <connectivity-testing
   []
   (go
@@ -3522,7 +3491,6 @@
     (<sync-start))
   (recur))
 
-
 ;;; ### some sync events handler
 
 ;; re-exec remote->local-full-sync when it failed before
@@ -3548,6 +3516,5 @@
 
 ;;; add-tap
 (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!
           (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
                         [{:file/path path
                           :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 [_]
   (let [label "accent-colors-picker"]
     (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/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
   [content]
@@ -379,7 +379,6 @@
       (state/set-modal! #(diff/local-file repo path disk-content db-content)
                         {:label "diff__cp"}))))
 
-
 (defmethod handle :modal/display-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))
    {:id :https-proxy-panel :center? true}))
 
-
 (defmethod handle :redirect-to-home [_]
   (page-handler/create-today-journal!))
 
@@ -682,10 +680,10 @@
               (ipc/ipc "clearCache"))
           _ (idb/clear-local-storage-and-idb!)]
     (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! [[_]]
   (clear-cache!))
@@ -900,11 +898,11 @@
                                  (let [dir (config/get-repo-dir repo)]
                                    (p/let [content (fs/read-file dir file)]
                                      (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))))))
                      :class "inline mx-1")
           "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)]
      content)
    (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
   [repo-url paths]
@@ -63,7 +63,7 @@
     (-> (p/all (load-multiple-files repo-url files))
         (p/then (fn [contents]
                   (let [file-contents (cond->
-                                        (zipmap files contents)
+                                       (zipmap files contents)
 
                                         (seq images)
                                         (merge (zipmap images (repeat (count images) ""))))
@@ -114,7 +114,7 @@
         path-dir (config/get-repo-dir repo)
         write-file-options' (merge write-file-options
                                    (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
   "Does pre-checks on a global file, writes if it's not already written
@@ -125,18 +125,18 @@
     (do
       (detect-deprecations 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)))
 
 (defn alter-file
@@ -206,23 +206,23 @@
                        (when path
                          (let [path (gp-util/path-normalize 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 []
                          (when finish-handler
                            (finish-handler)))]

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

@@ -50,30 +50,30 @@
         config-path (global-config-path)]
     (p/let [_ (fs/mkdir-if-not-exists config-dir)
             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!
   "Sets global config state from config file"
   []
   (let [config-path (global-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!
   [k v]
   (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])
         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))
                             (nil? v))
                      (rewrite/dissoc result (first ks))
                      (rewrite/assoc-in result ks v))
         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)))
 
 (defn start

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

@@ -27,11 +27,11 @@
   (when input
     (let [f (fn [[k v]] (if (keyword? k) [(csk/->camelCase (name k)) v] [k v]))]
       (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
   [type & args]
@@ -66,16 +66,16 @@
       (p/then #(bean/->clj %))
       (p/then #(state/set-state! :plugin/preferences %))
       (p/catch
-        #(js/console.error %))))
+       #(js/console.error %))))
 
 (defn save-plugin-preferences!
   ([input] (save-plugin-preferences! input true))
   ([input reload-state?]
    (when-let [^js input (and (map? input) (bean/->js input))]
      (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]
   (str "https://github.com/" repo))
@@ -89,42 +89,42 @@
   [refresh?]
   (if (or refresh? (nil? (:plugin/marketplace-pkgs @state/state)))
     (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))))
 
 (defn load-marketplace-stats
   [refresh?]
   (if (or refresh? (nil? (:plugin/marketplace-stats @state/state)))
     (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)))
 
 (defn check-or-update-marketplace-plugin!
@@ -164,7 +164,7 @@
     (when-let [matched (medley/find-first #(= (:key (second %)) key) commands)]
       (let [[_ cmd action pid] matched]
         (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
   []
@@ -207,19 +207,19 @@
                            (if (plugin-common-handler/installed? id)
                              (when-let [^js pl (get-plugin-inst id)] ;; update
                                (p/then
-                                 (.reload pl)
-                                 #(do
+                                (.reload pl)
+                                #(do
                                     ;;(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
                                (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!
-                                 (t :plugin/installed-plugin name) :success)))))
+                                (t :plugin/installed-plugin name) :success)))))
 
                        :error
                        (let [error-code  (keyword (string/replace (:error-code payload) #"^[\s\:\[]+" ""))
@@ -242,10 +242,10 @@
 
                              ;; notify human tips
                              (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?
                            (js/console.error "Update Error:" (:error-code payload))))
@@ -298,7 +298,7 @@
                                    (get keybinding-mode-handler-map (keyword mode)))
                      :action     (fn []
                                    (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))
 
 (defn simple-cmd-keybinding->shortcut-args
@@ -455,11 +455,11 @@
     (when-not (string/blank? content)
       (let [content (if-not (string/blank? url)
                       (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)]
         (format/to-html content :markdown (gp-mldoc/default-config :markdown))))
     (catch :default e
@@ -556,7 +556,7 @@
       (p/let [repo ""
               path (get-ls-dotdir-root)
               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
   [dirname]
@@ -583,11 +583,11 @@
 (defn- get-user-default-plugins
   []
   (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!
   [v]
@@ -693,7 +693,7 @@
   (let [el (js/document.createElement "div")]
     (.appendChild js/document.body el)
     (rum/mount
-      (lsp-indicator) el))
+     (lsp-indicator) el))
 
   (state/set-state! :plugin/indicator-text "LOADING")
 
@@ -713,12 +713,12 @@
                                 (.on "registered"
                                      (fn [^js pl]
                                        (register-plugin
-                                         (bean/->clj (.parse js/JSON (.stringify js/JSON pl))))))
+                                        (bean/->clj (.parse js/JSON (.stringify js/JSON pl))))))
 
                                 (.on "reloaded"
                                      (fn [^js pl]
                                        (register-plugin
-                                         (bean/->clj (.parse js/JSON (.stringify js/JSON pl))))))
+                                        (bean/->clj (.parse js/JSON (.stringify js/JSON pl))))))
 
                                 (.on "unregistered" (fn [pid]
                                                       (let [pid (keyword pid)]
@@ -775,15 +775,15 @@
                                                (when-let [plugins (and perf-table (.entries perf-table))]
                                                  (->> plugins
                                                       (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
-                                                                       (> end 0)
+                                                                      (> end 0)
                                                                        ;; greater than 6s
-                                                                       (> (- end (.-s v)) 6000))
-                                                              v))))
+                                                                      (> (- end (.-s v)) 6000))
+                                                             v))))
                                                       ((fn [perfs]
                                                          (doseq [perf perfs]
                                                            (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)])
 
       (p/then
-        (fn []
-          (state/set-state! :plugin/indicator-text "END")
-          (callback)))
+       (fn []
+         (state/set-state! :plugin/indicator-text "END")
+         (callback)))
       (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!
   "setup plugin core handler"
@@ -813,4 +813,4 @@
    :auto-checking? (boolean (:plugin/updates-auto-checking? @state/state))
    :coming         (count (:plugin/updates-coming @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)]
          ;; fs protocols require repo and dir when they aren't necessary. For this component,
          ;; 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
   "Removes a plugin from plugin.edn"
   [plugin-id]
   (p/let [content (fs/read-file "" (plugin-config-path))
           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
   []
@@ -79,16 +79,16 @@ returns map of plugins to install and uninstall"
   (p/catch
    (p/let [edn-plugins* (fs/read-file nil (plugin-config-path))
            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]
      (if (= :reader-exception (:type (ex-data e)))
        (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]
             [promesa.core :as p]))
 
-
-(defn- load-rpath 
+(defn- load-rpath
   "Returns the relative path to the file that stores the persist-var"
   [location]
   (str config/app-name "/" location ".edn"))
@@ -67,7 +66,7 @@
             repo (state/get-current-repo)
             content (str (get-in @*value [repo :value]))
             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
   (-deref [_this]
@@ -83,7 +82,6 @@
   (-pr-writer [_ w _opts]
     (write-all w (str "#PersistVar[" @*value ", loc: " location "]"))))
 
-
 (def *all-persist-vars (atom []))
 
 (defn load-vars []
@@ -106,6 +104,4 @@
 (comment
   (do
     (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
   []
   (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
   (fn []
     (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
   (fn [& keys]
@@ -173,7 +173,7 @@
     (let [repo ""
 
           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
   (fn []
@@ -193,7 +193,7 @@
           user-path-root (util/node-path.dirname user-path)
           exist?         (fs/file-exists? 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))
 
 (defn ^:private write_dotdir_file
@@ -284,8 +284,8 @@
                         (plugin-handler/get-ls-dotdir-root))
             plugin-id (util/node-path.basename plugin-id)
             exist?    (fs/file-exists?
-                        (util/node-path.join root "storages" plugin-id)
-                        file)]
+                       (util/node-path.join root "storages" plugin-id)
+                       file)]
       exist?)))
 
 (def ^:export clear_plugin_storage_files
@@ -306,8 +306,8 @@
             ^js files  (ipc/ipc :listdir files-path)]
       (when (js-iterable? files)
         (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
   (fn []
@@ -325,7 +325,7 @@
       (p/let [repo ""
               path (plugin-handler/get-ls-dotdir-root)
               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
   ;; results [path data]
@@ -343,8 +343,8 @@
   (fn [pid ^js cmd-actions]
     (when-let [[cmd actions] (bean/->clj cmd-actions)]
       (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
   (fn [pid ^js cmd-action palette?]
@@ -409,7 +409,7 @@
   (fn [pid type ^js opts]
     (when-let [opts (bean/->clj opts)]
       (plugin-handler/register-plugin-ui-item
-        pid (assoc opts :type type)))))
+       pid (assoc opts :type type)))))
 
 ;; app
 (def ^:export relaunch
@@ -559,12 +559,12 @@
               (let [properties (bean/->clj properties)
                     {:keys [redirect createFirstBlock format journal]} (bean/->clj opts)
                     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/id)
             (db-utils/pull)
@@ -581,9 +581,9 @@
 (defn ^:export open_in_right_sidebar
   [block-id-or-uuid]
   (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 []
   (str (db/new-block-id)))
@@ -616,7 +616,7 @@
           edit-block?            (if (nil? focus) true focus)
           _                      (when (and custom-uuid (db-model/query-block-by-uuid custom-uuid))
                                    (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)
                                    (let [block       (db/entity [:block/uuid block-uuid])
                                          first-child (db-model/get-by-parent-&-left (db/get-db)
@@ -634,16 +634,16 @@
                                    false
                                    before?)
           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)))))
 
 (def ^:export insert_batch_block
@@ -658,11 +658,11 @@
                                    (let [uuid (:id (:properties block))]
                                      (when (and uuid (db-model/query-block-by-uuid (sdk-utils/uuid-or-throw-error uuid)))
                                        (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)
                       (db/pull (:db/id (:block/left block))) block)
               _ (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)))))
 
 (def ^:export remove_block
@@ -670,7 +670,7 @@
     (let [includeChildren true
           repo            (state/get-current-repo)]
       (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)))
 
 (def ^:export update_block
@@ -736,7 +736,7 @@
                      (not (util/collapsed? block))
                      (boolean flag))]
           (if flag (editor-handler/collapse-block! block-uuid)
-                   (editor-handler/expand-block! block-uuid))
+              (editor-handler/expand-block! block-uuid))
           nil)))))
 
 (def ^:export upsert_block_property
@@ -860,7 +860,7 @@
   [query-string]
   (when-let [repo (state/get-current-repo)]
     (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))))))
 
 (defn ^:export datascript_query
@@ -926,25 +926,25 @@
                   init?      (plugin-handler/register-plugin-resources pid :scripts {:key s :src s})]]
       (when init?
         (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
   [pid type ^js opts]
   (when-let [^js _pl (plugin-handler/get-plugin-inst pid)]
     (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
   [pid type enhancer]
   (when-let [^js _pl (and (fn? enhancer) (plugin-handler/get-plugin-inst pid))]
     (plugin-handler/register-extensions-enhancer
-      (keyword pid) type {:enhancer enhancer})))
+     (keyword pid) type {:enhancer enhancer})))
 
 (defonce *request-k (volatile! 0))
 

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

@@ -18,11 +18,11 @@
             dir (config/get-repo-dir repo)
             _ (fs/create-if-not-exists repo dir file)
             content (fs/read-file dir file)]
-           content)))
+      content)))
 
 (defn ^:export save_ignore_file
   [content]
   (when-let [repo (and (string? content) (state/get-current-repo))]
     (p/let [file ".gitignore"
             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})])))