diff options
author | Sebastian <sebasjm@gmail.com> | 2021-07-07 13:28:02 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2021-07-07 13:28:10 -0300 |
commit | ebfc79756f14b08ac3735b2746ac48fd3483b5e4 (patch) | |
tree | 2937c7377b9620088d660aebcb4e2974fb646880 /packages/taler-wallet-core/src | |
parent | ff09c98f3b0515dd92dc5f9bab887336b080b4f5 (diff) | |
download | wallet-core-ebfc79756f14b08ac3735b2746ac48fd3483b5e4.tar.xz |
add providers filter to runBackupCycle
Diffstat (limited to 'packages/taler-wallet-core/src')
-rw-r--r-- | packages/taler-wallet-core/src/operations/backup/index.ts | 23 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/wallet.ts | 4 |
2 files changed, 24 insertions, 3 deletions
diff --git a/packages/taler-wallet-core/src/operations/backup/index.ts b/packages/taler-wallet-core/src/operations/backup/index.ts index 68040695c..9593325a3 100644 --- a/packages/taler-wallet-core/src/operations/backup/index.ts +++ b/packages/taler-wallet-core/src/operations/backup/index.ts @@ -33,6 +33,7 @@ import { Codec, codecForAmountString, codecForBoolean, + codecForList, codecForNumber, codecForString, codecOptional, @@ -41,6 +42,7 @@ import { getTimestampNow, j2s, Logger, + notEmpty, NotificationType, PreparePayResultType, RecoveryLoadRequest, @@ -520,6 +522,19 @@ export async function processBackupForProvider( await guardOperationException(run, onOpErr); } + +export interface RunBackupCycleRequest { + /** + * List of providers to backup or empty for all known providers. + */ + providers?: Array<string>; +} + +export const codecForRunBackupCycle = (): Codec<RunBackupCycleRequest> => + buildCodecForObject<RunBackupCycleRequest>() + .property("providers", codecOptional(codecForList(codecForString()))) + .build("RunBackupCycleRequest"); + /** * Do one backup cycle that consists of: * 1. Exporting a backup and try to upload it. @@ -527,11 +542,15 @@ export async function processBackupForProvider( * 2. Download, verify and import backups from connected sync accounts. * 3. Upload the updated backup blob. */ -export async function runBackupCycle(ws: InternalWalletState): Promise<void> { +export async function runBackupCycle(ws: InternalWalletState, req: RunBackupCycleRequest): Promise<void> { const providers = await ws.db .mktx((x) => ({ backupProviders: x.backupProviders })) .runReadOnly(async (tx) => { - return await tx.backupProviders.iter().toArray(); + if (req.providers) { + const rs = await Promise.all(req.providers.map(id => tx.backupProviders.get(id))) + return rs.filter(notEmpty) + } + return await tx.backupProviders.iter(req.providers).toArray(); }); const backupJson = await exportBackup(ws); const backupConfig = await provideBackupState(ws); diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index ca9afc073..d46914b37 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -41,6 +41,7 @@ import { import { addBackupProvider, codecForAddBackupProviderRequest, + codecForRunBackupCycle, getBackupInfo, getBackupRecovery, loadBackupRecovery, @@ -809,7 +810,8 @@ async function dispatchRequestInternal( return {}; } case "runBackupCycle": { - await runBackupCycle(ws); + const req = codecForRunBackupCycle().decode(payload); + await runBackupCycle(ws, req); return {}; } case "exportBackupRecovery": { |