Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fe572b41c9 | ||
|
|
ca5ca5f576 | ||
|
|
0e6182b887 | ||
|
|
c5a7085fda | ||
|
|
640f1e56f1 |
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "remotely-save",
|
||||
"name": "Remotely Save",
|
||||
"version": "0.4.15",
|
||||
"version": "0.4.16",
|
||||
"minAppVersion": "0.13.21",
|
||||
"description": "Yet another unofficial plugin allowing users to synchronize notes between local device and the cloud service.",
|
||||
"author": "fyears",
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "remotely-save",
|
||||
"name": "Remotely Save",
|
||||
"version": "0.4.15",
|
||||
"version": "0.4.16",
|
||||
"minAppVersion": "0.13.21",
|
||||
"description": "Yet another unofficial plugin allowing users to synchronize notes between local device and the cloud service.",
|
||||
"author": "fyears",
|
||||
|
||||
+2
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "remotely-save",
|
||||
"version": "0.4.15",
|
||||
"version": "0.4.16",
|
||||
"description": "This is yet another sync plugin for Obsidian app.",
|
||||
"scripts": {
|
||||
"dev2": "node esbuild.config.mjs --watch",
|
||||
@@ -76,6 +76,7 @@
|
||||
"emoji-regex": "^10.3.0",
|
||||
"http-status-codes": "^2.3.0",
|
||||
"localforage": "^1.10.0",
|
||||
"localforage-getitems": "^1.4.2",
|
||||
"lodash": "^4.17.21",
|
||||
"lucide": "^0.298.0",
|
||||
"mime-types": "^2.1.35",
|
||||
|
||||
+6
-5
@@ -1,4 +1,6 @@
|
||||
import localforage from "localforage";
|
||||
import { extendPrototype } from "localforage-getitems";
|
||||
extendPrototype(localforage);
|
||||
export type LocalForage = typeof localforage;
|
||||
import { nanoid } from "nanoid";
|
||||
import { requireApiVersion, TAbstractFile, TFile, TFolder } from "obsidian";
|
||||
@@ -434,13 +436,12 @@ export const getAllPrevSyncRecordsByVaultAndProfile = async (
|
||||
vaultRandomID: string,
|
||||
profileID: string
|
||||
) => {
|
||||
// console.debug('inside getAllPrevSyncRecordsByVaultAndProfile')
|
||||
const keys = await db.prevSyncRecordsTbl.keys();
|
||||
// console.debug(`inside getAllPrevSyncRecordsByVaultAndProfile, keys=${keys}`)
|
||||
const res: Entity[] = [];
|
||||
for (const key of keys) {
|
||||
const kv: Record<string, Entity | null> =
|
||||
await db.prevSyncRecordsTbl.getItems();
|
||||
for (const key of Object.getOwnPropertyNames(kv)) {
|
||||
if (key.startsWith(`${vaultRandomID}\t${profileID}\t`)) {
|
||||
const val: Entity | null = await db.prevSyncRecordsTbl.getItem(key);
|
||||
const val = kv[key];
|
||||
if (val !== null) {
|
||||
res.push(val);
|
||||
}
|
||||
|
||||
+42
-27
@@ -221,14 +221,19 @@ const fullfillMTimeOfRemoteEntityInplace = (
|
||||
remote: Entity,
|
||||
mtimeCli?: number
|
||||
) => {
|
||||
// TODO:
|
||||
// on 20240405, we find that dropbox's mtimeCli is not updated
|
||||
// if the content is not updated even the time is updated...
|
||||
// so we do not check remote.mtimeCli for now..
|
||||
if (
|
||||
mtimeCli !== undefined &&
|
||||
mtimeCli > 0 &&
|
||||
mtimeCli > 0 /* &&
|
||||
(remote.mtimeCli === undefined ||
|
||||
remote.mtimeCli <= 0 ||
|
||||
(remote.mtimeSvr !== undefined &&
|
||||
remote.mtimeSvr > 0 &&
|
||||
remote.mtimeCli >= remote.mtimeSvr))
|
||||
*/
|
||||
) {
|
||||
remote.mtimeCli = mtimeCli;
|
||||
}
|
||||
@@ -1120,26 +1125,31 @@ const dispatchOperationToActualV3 = async (
|
||||
r.decision === "conflict_created_then_do_nothing" ||
|
||||
r.decision === "folder_existed_both_then_do_nothing"
|
||||
) {
|
||||
// !! we need to upsert the record,
|
||||
// !! we MIGHT need to upsert the record,
|
||||
// so that next time we can determine the change delta
|
||||
// if we have prevSync, we store it because it should keep all necessary info
|
||||
let entity = r.prevSync;
|
||||
// if we don't have prevSync, we use remote entity AND local mtime
|
||||
// as if it is "uploaded"
|
||||
if (entity === undefined && r.remote !== undefined) {
|
||||
entity = await decryptRemoteEntityInplace(r.remote, cipher);
|
||||
entity = await fullfillMTimeOfRemoteEntityInplace(
|
||||
entity,
|
||||
r.local?.mtimeCli
|
||||
);
|
||||
}
|
||||
if (entity !== undefined) {
|
||||
await upsertPrevSyncRecordByVaultAndProfile(
|
||||
db,
|
||||
vaultRandomID,
|
||||
profileID,
|
||||
entity
|
||||
);
|
||||
|
||||
if (r.prevSync !== undefined) {
|
||||
// if we have prevSync,
|
||||
// we don't need to do anything, because the record is already there!
|
||||
} else {
|
||||
// if we don't have prevSync, we use remote entity AND local mtime
|
||||
// as if it is "uploaded"
|
||||
if (r.remote !== undefined) {
|
||||
let entity = await decryptRemoteEntityInplace(r.remote, cipher);
|
||||
entity = await fullfillMTimeOfRemoteEntityInplace(
|
||||
entity,
|
||||
r.local?.mtimeCli
|
||||
);
|
||||
|
||||
if (entity !== undefined) {
|
||||
await upsertPrevSyncRecordByVaultAndProfile(
|
||||
db,
|
||||
vaultRandomID,
|
||||
profileID,
|
||||
entity
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (
|
||||
r.decision === "local_is_modified_then_push" ||
|
||||
@@ -1166,8 +1176,13 @@ const dispatchOperationToActualV3 = async (
|
||||
cipher,
|
||||
r.local!.keyEnc
|
||||
);
|
||||
// console.debug(`after uploadToRemote`);
|
||||
// console.debug(`entity=${JSON.stringify(entity,null,2)}`)
|
||||
// console.debug(`mtimeCli=${mtimeCli}`)
|
||||
await decryptRemoteEntityInplace(entity, cipher);
|
||||
// console.debug(`after dec, entity=${JSON.stringify(entity,null,2)}`)
|
||||
await fullfillMTimeOfRemoteEntityInplace(entity, mtimeCli);
|
||||
// console.debug(`after fullfill, entity=${JSON.stringify(entity,null,2)}`)
|
||||
await upsertPrevSyncRecordByVaultAndProfile(
|
||||
db,
|
||||
vaultRandomID,
|
||||
@@ -1364,9 +1379,9 @@ export const doActualSync = async (
|
||||
|
||||
for (let j = 0; j < operations.length; ++j) {
|
||||
const singleLevelOps = operations[j];
|
||||
console.debug(
|
||||
`singleLevelOps=${JSON.stringify(singleLevelOps, null, 2)}`
|
||||
);
|
||||
// console.debug(
|
||||
// `singleLevelOps=${JSON.stringify(singleLevelOps, null, 2)}`
|
||||
// );
|
||||
if (singleLevelOps === undefined || singleLevelOps === null) {
|
||||
continue;
|
||||
}
|
||||
@@ -1380,9 +1395,9 @@ export const doActualSync = async (
|
||||
const key = val.key;
|
||||
|
||||
const fn = async () => {
|
||||
console.debug(
|
||||
`start syncing "${key}" with plan ${JSON.stringify(val)}`
|
||||
);
|
||||
// console.debug(
|
||||
// `start syncing "${key}" with plan ${JSON.stringify(val)}`
|
||||
// );
|
||||
|
||||
if (callbackSyncProcess !== undefined) {
|
||||
await callbackSyncProcess(
|
||||
@@ -1407,7 +1422,7 @@ export const doActualSync = async (
|
||||
cipher
|
||||
);
|
||||
|
||||
console.debug(`finished ${key}`);
|
||||
// console.debug(`finished ${key}`);
|
||||
};
|
||||
|
||||
queue.add(fn).catch((e) => {
|
||||
|
||||
Reference in New Issue
Block a user