Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow one way sync #22

Open
markchalloner opened this issue Dec 19, 2024 · 1 comment
Open

Allow one way sync #22

markchalloner opened this issue Dec 19, 2024 · 1 comment

Comments

@markchalloner
Copy link

There is no option to specify a one way sync (e.g. download only).

Unfortunately when trying to workaround this with a couchdb readonly user (via a validation function) even if the file in storage has not been changed, the daemon will attempt to update the document on remote and exit on receiving a unexpected response.

12/17/2024, 11:01:13 PM 10      WATCH: PROCESS DONE: file.md
error: Uncaught (in promise) {
  id: "file.md",
  rev: "1-0123456789abcdef",
  error: "forbidden",
  reason: "Read-only access. Updates are not allowed.",
  name: "forbidden",
  status: 500,
  message: "Read-only access. Updates are not allowed.",
  stack: "Error\n" +
    "    at Object.generateErrorFromResponse (file:///var/lib/notes/.cache/deno/npm/registry.npmjs.org/pouchdb-errors/8.0.1/lib/index.js:100:18)\n" +
    "    at file:///var/lib/notes/.cache/deno/npm/registry.npmjs.org/pouchdb-adapter-http/8.0.1/lib/index.js:258:32\n" +
    "    at Array.map (<anonymous>)\n" +
    "    at fetchJSON (file:///var/lib/notes/.cache/deno/npm/registry.npmjs.org/pouchdb-adapter-http/8.0.1/lib/index.js:256:33)\n" +
    "    at Object.runMicrotasks (ext:core/01_core.js:691:26)\n" +
    "    at processTicksAndRejections (ext:deno_node/_next_tick.ts:57:10)\n" +
    "    at runNextTicks (ext:deno_node/_next_tick.ts:75:3)\n" +
    "    at eventLoopTick (ext:core/01_core.js:182:21)\n" +
    "    at async klass.HttpPouch.api._bulkDocs (file:///var/lib/notes/.cache/deno/npm/registry.npmjs.org/pouchdb-adapter-http/8.0.1/lib/index.js:753:22)",
  docId: "file.md"
}
@scbash
Copy link

scbash commented Dec 22, 2024

I've also been thinking about this. Earlier this month I started to prototype a solution, but ran into #20 which limited my ability to test. Here's my initial patch, which stubs out the dispatcher function that sends events to the other peers (I did this for the local storage peer, but it could easily be moved to the Peer base class for all peers):

diff --git a/PeerStorage.ts b/PeerStorage.ts
index 0c53938..d1ec6b2 100644
--- a/PeerStorage.ts
+++ b/PeerStorage.ts
@@ -21,6 +21,11 @@ export class PeerStorage extends Peer {
 
 
     constructor(conf: PeerStorageConf, dispatcher: DispatchFun) {
+        if (conf.downloadOnly) {
+            dispatcher = async function(source: Peer, path: string, data: FileData | false) {
+                return
+            }
+        }
         super(conf, dispatcher);
     }
 
diff --git a/types.ts b/types.ts
index f0baedc..e06be7c 100644
--- a/types.ts
+++ b/types.ts
@@ -16,6 +16,7 @@ export interface PeerStorageConf {
         args: string[]
     }
     useChokidar?: boolean;
+    downloadOnly?: boolean;
 }
 export interface PeerCouchDBConf extends DirectFileManipulatorOptions {
     type: "couchdb";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants