瀏覽代碼

refactor(db): get-config reset-config!

defclass 4 年之前
父節點
當前提交
4410ae7147

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

@@ -41,7 +41,7 @@
   get-all-templates get-block-and-children get-block-and-children-no-cache get-block-by-uuid get-block-children
   get-block-children-ids get-block-content get-block-file get-block-immediate-children get-block-page
   get-block-page-end-pos get-block-parent get-block-parents get-block-referenced-blocks get-block-refs-count
-  get-blocks-by-priority get-blocks-contents get-collapsed-blocks get-config get-custom-css
+  get-blocks-by-priority get-blocks-contents get-collapsed-blocks get-custom-css
   get-date-scheduled-or-deadlines get-db-type get-empty-pages get-file get-file-after-blocks get-file-after-blocks-meta
   get-file-blocks get-file-contents get-file-last-modified-at get-file-no-sub get-file-page get-file-page-id
   get-file-pages get-files get-files-blocks get-files-full get-files-that-referenced-page get-journals-length
@@ -50,7 +50,7 @@
   get-page-properties-content get-page-referenced-blocks get-page-referenced-pages get-page-unlinked-references
   get-pages get-pages-relation get-pages-that-mentioned-page get-public-pages get-tag-pages
   journal-page? local-native-fs? mark-repo-as-cloned! page-alias-set page-blocks-transform pull-block
-  reset-config! set-file-last-modified-at! transact-files-db! with-block-refs-count get-modified-pages]
+  set-file-last-modified-at! transact-files-db! with-block-refs-count get-modified-pages]
 
  [frontend.db.react
   get-current-marker get-current-page get-current-priority get-handler-keys set-file-content! set-key-value

+ 0 - 16
src/main/frontend/db/model.cljs

@@ -997,22 +997,6 @@
           repo-url)
      ffirst)))
 
-(defn get-config
-  [repo-url]
-  (get-file repo-url (str config/app-name "/" config/config-file)))
-
-(defn reset-config!
-  [repo-url content]
-  (when-let [content (or content (get-config repo-url))]
-    (let [config (try
-                   (reader/read-string content)
-                   (catch js/Error e
-                     (println "Parsing config file failed: ")
-                     (js/console.dir e)
-                     {}))]
-      (state/set-config! repo-url config)
-      config)))
-
 (defn get-db-type
   [repo]
   (db-utils/get-key-value repo :db/type))

+ 4 - 3
src/main/frontend/handler/file.cljs

@@ -24,7 +24,8 @@
             [cljs-time.core :as t]
             [cljs-time.coerce :as tc]
             [frontend.utf8 :as utf8]
-            ["ignore" :as Ignore]))
+            ["ignore" :as Ignore]
+            [frontend.handler.utils :as h-utils]))
 
 (defn load-file
   [repo-url path]
@@ -79,10 +80,10 @@
    (restore-config! repo-url nil project-changed-check?))
   ([repo-url config-content project-changed-check?]
    (let [config-content (if config-content config-content
-                            (db/get-config repo-url))]
+                            (h-utils/get-config repo-url))]
      (when config-content
        (let [old-project (:project (state/get-config))
-             new-config (db/reset-config! repo-url config-content)]
+             new-config (h-utils/reset-config! repo-url config-content)]
          (when (and (not (config/local-db? repo-url))
                     project-changed-check?)
            (let [new-project (:project new-config)

+ 3 - 2
src/main/frontend/handler/repo.cljs

@@ -25,7 +25,8 @@
             [clojure.string :as string]
             [frontend.dicts :as dicts]
             [frontend.helper :as helper]
-            [frontend.spec :as spec]))
+            [frontend.spec :as spec]
+            [frontend.handler.utils :as h-utils]))
 
 ;; Project settings should be checked in two situations:
 ;; 1. User changes the config.edn directly in logseq.com (fn: alter-file)
@@ -61,7 +62,7 @@
                               (db/get-file repo-url path))
                 content (or old-content default-content)]
             (file-handler/reset-file! repo-url path content)
-            (db/reset-config! repo-url content)
+            (h-utils/reset-config! repo-url content)
             (when-not (= content old-content)
               (git-handler/git-add repo-url path))))))))
 

+ 21 - 0
src/main/frontend/handler/utils.cljs

@@ -0,0 +1,21 @@
+(ns frontend.handler.utils
+  (:require [frontend.state :as state]
+            [cljs.reader :as reader]
+            [frontend.config :as config]
+            [frontend.db :as db]))
+
+(defn get-config
+  [repo-url]
+  (db/get-file repo-url (str config/app-name "/" config/config-file)))
+
+(defn reset-config!
+  [repo-url content]
+  (when-let [content (or content (get-config repo-url))]
+    (let [config (try
+                   (reader/read-string content)
+                   (catch js/Error e
+                     (println "Parsing config file failed: ")
+                     (js/console.dir e)
+                     {}))]
+      (state/set-config! repo-url config)
+      config)))