mirror of
https://github.com/remotely-save/remotely-save.git
synced 2024-06-07 21:10:45 +00:00
quick fix for onedrive path
This commit is contained in:
parent
2a797f8c40
commit
3d6746ed99
@ -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))
|
||||||
|
Loading…
Reference in New Issue
Block a user