Compare commits

..
3 Commits
Author SHA1 Message Date
fyears 9a1b11b811 0.2.7 2022-01-03 01:04:45 +08:00
fyears 3d6746ed99 quick fix for onedrive path 2022-01-03 01:03:56 +08:00
fyears 2a797f8c40 force refresh version download 2022-01-01 23:58:25 +08:00
5 changed files with 34 additions and 14 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
This is yet another unofficial sync plugin for Obsidian. If you like it or find it useful, please consider give it a [star ![GitHub Repo stars](https://img.shields.io/github/stars/fyears/remotely-save?style=social)](https://github.com/fyears/remotely-save) on Github. This is yet another unofficial sync plugin for Obsidian. If you like it or find it useful, please consider give it a [star ![GitHub Repo stars](https://img.shields.io/github/stars/fyears/remotely-save?style=social)](https://github.com/fyears/remotely-save) on Github.
[![BuildCI](https://github.com/fyears/remotely-save/actions/workflows/auto-build.yml/badge.svg)](https://github.com/fyears/remotely-save/actions/workflows/auto-build.yml) [![Latest release: 0.2.6)](https://img.shields.io/github/downloads/fyears/remotely-save/0.2.6/main.js)](https://github.com/fyears/remotely-save/releases) [![Previous release: 0.2.5)](https://img.shields.io/github/downloads/fyears/remotely-save/0.2.5/main.js)](https://github.com/fyears/remotely-save/releases) [![BuildCI](https://github.com/fyears/remotely-save/actions/workflows/auto-build.yml/badge.svg)](https://github.com/fyears/remotely-save/actions/workflows/auto-build.yml) [![Latest release: 0.2.6)](https://img.shields.io/github/downloads/fyears/remotely-save/0.2.6/main.js?sort=semver)](https://github.com/fyears/remotely-save/releases) [![Previous release: 0.2.5)](https://img.shields.io/github/downloads/fyears/remotely-save/0.2.5/main.js)](https://github.com/fyears/remotely-save/releases)
## Disclaimer ## Disclaimer
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"id": "remotely-save", "id": "remotely-save",
"name": "Remotely Save", "name": "Remotely Save",
"version": "0.2.6", "version": "0.2.7",
"minAppVersion": "0.12.15", "minAppVersion": "0.12.15",
"description": "Yet another unofficial plugin allowing users to synchronize notes between local device and the cloud service.", "description": "Yet another unofficial plugin allowing users to synchronize notes between local device and the cloud service.",
"author": "fyears", "author": "fyears",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "remotely-save", "name": "remotely-save",
"version": "0.2.6", "version": "0.2.7",
"description": "This is yet another sync plugin for Obsidian app.", "description": "This is yet another sync plugin for Obsidian app.",
"scripts": { "scripts": {
"dev": "node esbuild.config.mjs", "dev": "node esbuild.config.mjs",
+30 -10
View File
@@ -245,19 +245,33 @@ const getNormPath = (fileOrFolderPath: string, vaultName: string) => {
return fileOrFolderPath.slice(`${prefix}/`.length); return fileOrFolderPath.slice(`${prefix}/`.length);
}; };
const constructFromDriveItemToRemoteItemError = (x: DriveItem) => {
return `parentPath="${x.parentReference.path}", selfName="${x.name}"`;
};
const fromDriveItemToRemoteItem = ( const fromDriveItemToRemoteItem = (
x: DriveItem, x: DriveItem,
vaultName: string vaultName: string
): RemoteItem => { ): RemoteItem => {
let key = ""; let key = "";
const COMMON_PREFIX = `/drive/root:/Apps/remotely-save/${vaultName}`; // possible prefix:
const COMMON_PREFIX_OTHERS = `/drive/items/`; // pure english: /drive/root:/Apps/remotely-save/${vaultName}
if (`${x.parentReference.path}/${x.name}`.startsWith(COMMON_PREFIX)) { // or localized, e.g.: /drive/root:/应用/remotely-save/${vaultName}
key = `${x.parentReference.path}/${x.name}`.substring( const FIRST_COMMON_PREFIX_REGEX = /^\/drive\/root:\/[^\/]+\/remotely-save\//g;
COMMON_PREFIX.length + 1
); // another possibile prefix
} else if (x.parentReference.path.startsWith(COMMON_PREFIX_OTHERS)) { const SECOND_COMMON_PREFIX_RAW = `/drive/items/`;
const fullPathOriginal = `${x.parentReference.path}/${x.name}`;
const matchFirstPrefixRes = fullPathOriginal.match(FIRST_COMMON_PREFIX_REGEX);
if (
matchFirstPrefixRes !== null &&
fullPathOriginal.startsWith(`${matchFirstPrefixRes[0]}${vaultName}`)
) {
const foundPrefix = `${matchFirstPrefixRes[0]}${vaultName}`;
key = fullPathOriginal.substring(foundPrefix.length + 1);
} else if (x.parentReference.path.startsWith(SECOND_COMMON_PREFIX_RAW)) {
// it's something like // it's something like
// /drive/items/<some_id>!<another_id>:/${vaultName}/<subfolder> // /drive/items/<some_id>!<another_id>:/${vaultName}/<subfolder>
// with uri encoded! // with uri encoded!
@@ -270,14 +284,14 @@ const fromDriveItemToRemoteItem = (
key = x.name; key = x.name;
} else { } else {
throw Error( throw Error(
`we meet file/folder and do not know how to deal with it:\n${JSON.stringify( `we meet file/folder and do not know how to deal with it:\n${constructFromDriveItemToRemoteItemError(
x x
)}` )}`
); );
} }
} else { } else {
throw Error( throw Error(
`we meet file/folder and do not know how to deal with it:\n${JSON.stringify( `we meet file/folder and do not know how to deal with it:\n${constructFromDriveItemToRemoteItemError(
x x
)}` )}`
); );
@@ -431,7 +445,7 @@ export const listFromRemote = async (
let res = await client.client let res = await client.client
.api(`/drive/special/approot:/${client.vaultName}:/delta`) .api(`/drive/special/approot:/${client.vaultName}:/delta`)
.get(); .get();
const driveItems = res.value as DriveItem[]; let driveItems = res.value as DriveItem[];
while (NEXT_LINK_KEY in res) { while (NEXT_LINK_KEY in res) {
res = await client.client.api(res[NEXT_LINK_KEY]).get(); res = await client.client.api(res[NEXT_LINK_KEY]).get();
@@ -444,6 +458,12 @@ export const listFromRemote = async (
await client.saveUpdatedConfigFunc(); await client.saveUpdatedConfigFunc();
} }
driveItems = driveItems.map((x) => {
const y = cloneDeep(x);
y.parentReference.path = y.parentReference.path.replace("/Apps", "/应用");
return y;
});
// unify everything to RemoteItem // unify everything to RemoteItem
const unifiedContents = driveItems const unifiedContents = driveItems
.map((x) => fromDriveItemToRemoteItem(x, client.vaultName)) .map((x) => fromDriveItemToRemoteItem(x, client.vaultName))
+1 -1
View File
@@ -1,3 +1,3 @@
{ {
"0.2.6": "0.12.15" "0.2.7": "0.12.15"
} }