promise all sync
This commit is contained in:
parent
2012758383
commit
b6df3f7ed5
196
src/sync.ts
196
src/sync.ts
@ -290,103 +290,105 @@ export const doActualSync = async (
|
|||||||
keyStates: Record<string, FileOrFolderMixedState>,
|
keyStates: Record<string, FileOrFolderMixedState>,
|
||||||
password: string = ""
|
password: string = ""
|
||||||
) => {
|
) => {
|
||||||
Object.entries(keyStates)
|
await Promise.all(
|
||||||
.sort((k, v) => -(k as string).length)
|
Object.entries(keyStates)
|
||||||
.map(async ([k, v]) => {
|
.sort((k, v) => -(k as string).length)
|
||||||
const key = k as string;
|
.map(async ([k, v]) => {
|
||||||
const state = v as FileOrFolderMixedState;
|
const key = k as string;
|
||||||
let remoteEncryptedKey = key;
|
const state = v as FileOrFolderMixedState;
|
||||||
if (password !== "") {
|
let remoteEncryptedKey = key;
|
||||||
remoteEncryptedKey = state.remote_encrypted_key;
|
if (password !== "") {
|
||||||
if (remoteEncryptedKey === undefined || remoteEncryptedKey === "") {
|
remoteEncryptedKey = state.remote_encrypted_key;
|
||||||
remoteEncryptedKey = await encryptStringToBase32(key, password);
|
if (remoteEncryptedKey === undefined || remoteEncryptedKey === "") {
|
||||||
|
remoteEncryptedKey = await encryptStringToBase32(key, password);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
state.decision === undefined ||
|
state.decision === undefined ||
|
||||||
state.decision === "unknown" ||
|
state.decision === "unknown" ||
|
||||||
state.decision === "undecided"
|
state.decision === "undecided"
|
||||||
) {
|
) {
|
||||||
throw Error(`unknown decision in ${JSON.stringify(state)}`);
|
throw Error(`unknown decision in ${JSON.stringify(state)}`);
|
||||||
} else if (state.decision === "skip") {
|
} else if (state.decision === "skip") {
|
||||||
// do nothing
|
// do nothing
|
||||||
} else if (state.decision === "download_clearhist") {
|
} else if (state.decision === "download_clearhist") {
|
||||||
await downloadFromRemote(
|
await downloadFromRemote(
|
||||||
s3Client,
|
s3Client,
|
||||||
s3Config,
|
s3Config,
|
||||||
state.key,
|
state.key,
|
||||||
vault,
|
vault,
|
||||||
state.mtime_remote,
|
state.mtime_remote,
|
||||||
password,
|
password,
|
||||||
remoteEncryptedKey
|
remoteEncryptedKey
|
||||||
);
|
);
|
||||||
await clearDeleteRenameHistoryOfKey(db, state.key);
|
await clearDeleteRenameHistoryOfKey(db, state.key);
|
||||||
} else if (state.decision === "upload_clearhist") {
|
} else if (state.decision === "upload_clearhist") {
|
||||||
const remoteObjMeta = await uploadToRemote(
|
const remoteObjMeta = await uploadToRemote(
|
||||||
s3Client,
|
s3Client,
|
||||||
s3Config,
|
s3Config,
|
||||||
state.key,
|
state.key,
|
||||||
vault,
|
vault,
|
||||||
false,
|
false,
|
||||||
password,
|
password,
|
||||||
remoteEncryptedKey
|
remoteEncryptedKey
|
||||||
);
|
);
|
||||||
await upsertSyncMetaMappingDataS3(
|
await upsertSyncMetaMappingDataS3(
|
||||||
db,
|
db,
|
||||||
state.key,
|
state.key,
|
||||||
state.mtime_local,
|
state.mtime_local,
|
||||||
state.size_local,
|
state.size_local,
|
||||||
state.key,
|
state.key,
|
||||||
remoteObjMeta.LastModified.valueOf(),
|
remoteObjMeta.LastModified.valueOf(),
|
||||||
remoteObjMeta.ContentLength,
|
remoteObjMeta.ContentLength,
|
||||||
remoteObjMeta.ETag
|
remoteObjMeta.ETag
|
||||||
);
|
);
|
||||||
await clearDeleteRenameHistoryOfKey(db, state.key);
|
await clearDeleteRenameHistoryOfKey(db, state.key);
|
||||||
} else if (state.decision === "download") {
|
} else if (state.decision === "download") {
|
||||||
await mkdirpInVault(state.key, vault);
|
await mkdirpInVault(state.key, vault);
|
||||||
await downloadFromRemote(
|
await downloadFromRemote(
|
||||||
s3Client,
|
s3Client,
|
||||||
s3Config,
|
s3Config,
|
||||||
state.key,
|
state.key,
|
||||||
vault,
|
vault,
|
||||||
state.mtime_remote,
|
state.mtime_remote,
|
||||||
password,
|
password,
|
||||||
remoteEncryptedKey
|
remoteEncryptedKey
|
||||||
);
|
);
|
||||||
} else if (state.decision === "delremote_clearhist") {
|
} else if (state.decision === "delremote_clearhist") {
|
||||||
await deleteFromRemote(
|
await deleteFromRemote(
|
||||||
s3Client,
|
s3Client,
|
||||||
s3Config,
|
s3Config,
|
||||||
state.key,
|
state.key,
|
||||||
password,
|
password,
|
||||||
remoteEncryptedKey
|
remoteEncryptedKey
|
||||||
);
|
);
|
||||||
await clearDeleteRenameHistoryOfKey(db, state.key);
|
await clearDeleteRenameHistoryOfKey(db, state.key);
|
||||||
} else if (state.decision === "upload") {
|
} else if (state.decision === "upload") {
|
||||||
const remoteObjMeta = await uploadToRemote(
|
const remoteObjMeta = await uploadToRemote(
|
||||||
s3Client,
|
s3Client,
|
||||||
s3Config,
|
s3Config,
|
||||||
state.key,
|
state.key,
|
||||||
vault,
|
vault,
|
||||||
false,
|
false,
|
||||||
password,
|
password,
|
||||||
remoteEncryptedKey
|
remoteEncryptedKey
|
||||||
);
|
);
|
||||||
await upsertSyncMetaMappingDataS3(
|
await upsertSyncMetaMappingDataS3(
|
||||||
db,
|
db,
|
||||||
state.key,
|
state.key,
|
||||||
state.mtime_local,
|
state.mtime_local,
|
||||||
state.size_local,
|
state.size_local,
|
||||||
state.key,
|
state.key,
|
||||||
remoteObjMeta.LastModified.valueOf(),
|
remoteObjMeta.LastModified.valueOf(),
|
||||||
remoteObjMeta.ContentLength,
|
remoteObjMeta.ContentLength,
|
||||||
remoteObjMeta.ETag
|
remoteObjMeta.ETag
|
||||||
);
|
);
|
||||||
} else if (state.decision === "clearhist") {
|
} else if (state.decision === "clearhist") {
|
||||||
await clearDeleteRenameHistoryOfKey(db, state.key);
|
await clearDeleteRenameHistoryOfKey(db, state.key);
|
||||||
} else {
|
} else {
|
||||||
throw Error("this should never happen!");
|
throw Error("this should never happen!");
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user