monoidentity 0.12.5 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/+client.d.ts +1 -1
- package/dist/+client.js +1 -1
- package/dist/storage/backupcloud.js +35 -33
- package/dist/storage.d.ts +2 -0
- package/dist/storage.js +5 -0
- package/package.json +1 -1
package/dist/+client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from "./+common.js";
|
|
2
|
-
export { getLoginRecognized, getVerification, getStorage, getScopedFS } from "./storage.js";
|
|
2
|
+
export { getLoginRecognized, getVerification, getStorage, getScopedFS, completeSync, } from "./storage.js";
|
|
3
3
|
export { retrieveVerification } from "./verification-client.js";
|
|
4
4
|
export { default as rawAttest } from "./verification/attest-remote.js";
|
|
5
5
|
export { trackReady } from "./trackready.js";
|
package/dist/+client.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from "./+common.js";
|
|
2
|
-
export { getLoginRecognized, getVerification, getStorage, getScopedFS } from "./storage.js";
|
|
2
|
+
export { getLoginRecognized, getVerification, getStorage, getScopedFS, completeSync, } from "./storage.js";
|
|
3
3
|
export { retrieveVerification } from "./verification-client.js";
|
|
4
4
|
export { default as rawAttest } from "./verification/attest-remote.js";
|
|
5
5
|
export { trackReady } from "./trackready.js";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AwsClient } from "aws4fetch";
|
|
2
2
|
import { storageClient, STORAGE_EVENT } from "./storageclient.svelte.js";
|
|
3
|
+
import { addToSync } from "../../src/lib/storage.js";
|
|
3
4
|
const CLOUD_CACHE_KEY = "monoidentity-x/cloud-cache";
|
|
4
5
|
const isJunk = (key) => key.includes(".obsidian/") || key.includes(".cache/");
|
|
5
6
|
const keepAnyway = (key) => key.includes(".cache/");
|
|
@@ -68,7 +69,36 @@ export const backupCloud = async (bucket) => {
|
|
|
68
69
|
await syncFromCloud(bucket, client);
|
|
69
70
|
const syncIntervalId = setInterval(() => syncFromCloud(bucket, client), 15 * 60 * 1000);
|
|
70
71
|
// Continuous sync: mirror local changes to cloud
|
|
71
|
-
const
|
|
72
|
+
const write = async (key, value) => {
|
|
73
|
+
const url = `${bucket.base}/${key}`;
|
|
74
|
+
if (value != undefined) {
|
|
75
|
+
// PUT content (unconditional to start; you can add If-Match/If-None-Match for safety)
|
|
76
|
+
const r = await client.fetch(url, {
|
|
77
|
+
method: "PUT",
|
|
78
|
+
headers: { "content-type": "application/octet-stream" },
|
|
79
|
+
body: value,
|
|
80
|
+
});
|
|
81
|
+
if (!r.ok)
|
|
82
|
+
throw new Error(`PUT ${key} failed: ${r.status}`);
|
|
83
|
+
// Update cache
|
|
84
|
+
const etag = r.headers.get("etag")?.replaceAll('"', "");
|
|
85
|
+
if (etag) {
|
|
86
|
+
const cache = JSON.parse(localStorage[CLOUD_CACHE_KEY] || "{}");
|
|
87
|
+
cache[key] = { etag, content: value };
|
|
88
|
+
localStorage[CLOUD_CACHE_KEY] = JSON.stringify(cache);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
// DELETE key
|
|
93
|
+
const r = await client.fetch(url, { method: "DELETE" });
|
|
94
|
+
if (!r.ok && r.status != 404)
|
|
95
|
+
throw new Error(`DELETE ${key} failed: ${r.status}`);
|
|
96
|
+
const cache = JSON.parse(localStorage[CLOUD_CACHE_KEY] || "{}");
|
|
97
|
+
delete cache[key];
|
|
98
|
+
localStorage[CLOUD_CACHE_KEY] = JSON.stringify(cache);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const listener = (event) => {
|
|
72
102
|
let key = event.detail.key;
|
|
73
103
|
if (!key.startsWith("monoidentity/"))
|
|
74
104
|
return;
|
|
@@ -76,38 +106,10 @@ export const backupCloud = async (bucket) => {
|
|
|
76
106
|
if (isJunk(key))
|
|
77
107
|
return;
|
|
78
108
|
console.debug("[monoidentity cloud] saving", key);
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const r = await client.fetch(url, {
|
|
84
|
-
method: "PUT",
|
|
85
|
-
headers: { "content-type": "application/octet-stream" },
|
|
86
|
-
body: event.detail.value,
|
|
87
|
-
});
|
|
88
|
-
if (!r.ok)
|
|
89
|
-
throw new Error(`PUT ${key} failed: ${r.status}`);
|
|
90
|
-
// Update cache
|
|
91
|
-
const etag = r.headers.get("etag")?.replaceAll('"', "");
|
|
92
|
-
if (etag) {
|
|
93
|
-
const cache = JSON.parse(localStorage[CLOUD_CACHE_KEY] || "{}");
|
|
94
|
-
cache[key] = { etag, content: event.detail.value };
|
|
95
|
-
localStorage[CLOUD_CACHE_KEY] = JSON.stringify(cache);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
// DELETE key
|
|
100
|
-
const r = await client.fetch(url, { method: "DELETE" });
|
|
101
|
-
if (!r.ok && r.status != 404)
|
|
102
|
-
throw new Error(`DELETE ${key} failed: ${r.status}`);
|
|
103
|
-
const cache = JSON.parse(localStorage[CLOUD_CACHE_KEY] || "{}");
|
|
104
|
-
delete cache[key];
|
|
105
|
-
localStorage[CLOUD_CACHE_KEY] = JSON.stringify(cache);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
catch (err) {
|
|
109
|
-
console.warn("[monoidentity cloud] sync failed", key, err);
|
|
110
|
-
}
|
|
109
|
+
const promise = write(key, event.detail.value).catch((err) => {
|
|
110
|
+
console.warn("[monoidentity cloud] save failed", key, err);
|
|
111
|
+
});
|
|
112
|
+
addToSync(promise);
|
|
111
113
|
};
|
|
112
114
|
addEventListener(STORAGE_EVENT, listener);
|
|
113
115
|
unmount = () => {
|
package/dist/storage.d.ts
CHANGED
package/dist/storage.js
CHANGED
|
@@ -6,9 +6,14 @@ import { verify } from "@tsndr/cloudflare-worker-jwt";
|
|
|
6
6
|
import publicKey from "./verification/public-key.js";
|
|
7
7
|
import { storageClient } from "./storage/storageclient.svelte.js";
|
|
8
8
|
let app = "unknown";
|
|
9
|
+
let syncPromise = Promise.resolve();
|
|
9
10
|
export const conf = (a) => {
|
|
10
11
|
app = a;
|
|
11
12
|
};
|
|
13
|
+
export const addToSync = (p) => {
|
|
14
|
+
syncPromise = syncPromise.then(() => p);
|
|
15
|
+
};
|
|
16
|
+
export const completeSync = () => syncPromise;
|
|
12
17
|
const LOGIN_RECOGNIZED_PATH = ".core/login.encjson";
|
|
13
18
|
export const getLoginRecognized = () => {
|
|
14
19
|
const client = storageClient();
|