Explorar o código

feat(sync): impl 2-stage merge for mobile

Andelf %!s(int64=2) %!d(string=hai) anos
pai
achega
1cc9bb72aa
Modificáronse 4 ficheiros con 38 adicións e 24 borrados
  1. 1 1
      package.json
  2. 22 17
      src/main/frontend/fs.cljs
  3. 11 2
      src/main/frontend/fs/sync.cljs
  4. 4 4
      yarn.lock

+ 1 - 1
package.json

@@ -90,7 +90,7 @@
         "@capawesome/capacitor-background-task": "^2.0.0",
         "@excalidraw/excalidraw": "0.12.0",
         "@hugotomazi/capacitor-navigation-bar": "^2.0.0",
-        "@logseq/capacitor-file-sync": "0.0.24",
+        "@logseq/capacitor-file-sync": "0.0.27",
         "@logseq/diff-merge": "^0.0.2",
         "@logseq/react-tweet-embed": "1.3.1-1",
         "@radix-ui/colors": "^0.1.8",

+ 22 - 17
src/main/frontend/fs.cljs

@@ -137,6 +137,22 @@
             new-fpath (path/path-join repo-dir new-path)]
         (protocol/rename! (get-fs old-fpath) repo old-fpath new-fpath)))))
 
+(defn stat
+  ([fpath]
+   (protocol/stat (get-fs fpath) fpath))
+  ([dir path]
+   (let [fpath (path/path-join dir path)]
+     (protocol/stat (get-fs dir) fpath))))
+
+(defn mkdir-if-not-exists
+  [dir]
+  (when dir
+    (util/p-handle
+     (stat dir)
+     (fn [_stat])
+     (fn [_error]
+       (mkdir-recur! dir)))))
+
 (defn copy!
   "Only used by Logseq Sync"
   [repo old-path new-path]
@@ -149,15 +165,13 @@
           (map #(if (or (util/electron?) (mobile-util/native-platform?))
                   %
                   (str (config/get-repo-dir repo) "/" %))
-               [old-path new-path])]
-      (protocol/copy! (get-fs old-path) repo old-path new-path))))
+               [old-path new-path])
+          new-dir (path/dirname new-path)]
+      (p/do!
+       (mkdir-if-not-exists new-dir)
+       (protocol/copy! (get-fs old-path) repo old-path new-path)))))
+
 
-(defn stat
-  ([fpath]
-   (protocol/stat (get-fs fpath) fpath))
-  ([dir path]
-   (let [fpath (path/path-join dir path)]
-     (protocol/stat (get-fs dir) fpath))))
 
 (defn open-dir
   [dir]
@@ -192,15 +206,6 @@
   [dir]
   (protocol/unwatch-dir! (get-fs dir) dir))
 
-(defn mkdir-if-not-exists
-  [dir]
-  (when dir
-    (util/p-handle
-     (stat dir)
-     (fn [_stat])
-     (fn [_error]
-       (mkdir! dir)))))
-
 ;; FIXME: counterintuitive return value
 (defn create-if-not-exists
   "Create a file if it doesn't exist. return false on written, true on already exists"

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

@@ -958,7 +958,15 @@
                                                                      :token token})))))))
   (<fetch-remote-files [this graph-uuid base-path filepaths]
     (js/console.error "unimpl")
-    (prn ::todo))
+    (go
+      (let [token (<! (<get-token this))
+            r (<! (<retry-rsapi
+                   #(p->c (.fetchRemoteFiles mobile-util/file-sync
+                                             (clj->js {:graphUUID graph-uuid
+                                                       :basePath base-path
+                                                       :filePaths filepaths
+                                                       :token token})))))]
+        (js->clj (.-value r)))))
   (<download-version-files [this graph-uuid base-path filepaths]
     (go
       (let [token (<! (<get-token this))
@@ -994,12 +1002,13 @@
             r
             (get (js->clj r) "txid"))))))
 
-  (<delete-remote-files [this graph-uuid _base-path filepaths local-txid]
+  (<delete-remote-files [this graph-uuid base-path filepaths local-txid]
     (let [normalized-filepaths (mapv path-normalize filepaths)]
       (go
         (let [token (<! (<get-token this))
               r (<! (p->c (.deleteRemoteFiles mobile-util/file-sync
                                               (clj->js {:graphUUID graph-uuid
+                                                        :basePath base-path
                                                         :filePaths normalized-filepaths
                                                         :txid local-txid
                                                         :token token}))))]

+ 4 - 4
yarn.lock

@@ -487,10 +487,10 @@
     "@jridgewell/resolve-uri" "^3.0.3"
     "@jridgewell/sourcemap-codec" "^1.4.10"
 
-"@logseq/[email protected]4":
-  version "0.0.24"
-  resolved "https://registry.yarnpkg.com/@logseq/capacitor-file-sync/-/capacitor-file-sync-0.0.24.tgz#be7b69492b92df9c4e899502c632deebe179746b"
-  integrity sha512-CBIXEPYVp1ddjyYN+Z2dTQ9gwF0KYwZwlvwnl+zmR0Q3ODXxg75BExh5vAU8khXkSNZjZXgZT/J61/kn9xN11w==
+"@logseq/[email protected]7":
+  version "0.0.27"
+  resolved "https://registry.yarnpkg.com/@logseq/capacitor-file-sync/-/capacitor-file-sync-0.0.27.tgz#01f499943769dbeebd681f290ef86000d3b078b5"
+  integrity sha512-6gqKElG5qpN7HzEPMO1lpfJLhu7+xdMRB5DbJQdXwK5Di0XGsNGU7wu38quJVLeRFJJmbp1oNxdjHemIeTAAMw==
 
 "@logseq/diff-merge@^0.0.2":
   version "0.0.2"