sync: handle HTTP 304 correctly
This commit is contained in:
parent
eaced5ca63
commit
3603a68669
@ -1586,7 +1586,14 @@ export interface BackupProviderRecord {
|
|||||||
*/
|
*/
|
||||||
lastBackupHash?: string;
|
lastBackupHash?: string;
|
||||||
|
|
||||||
lastBackupTimestamp?: Timestamp;
|
/**
|
||||||
|
* Last time that we successfully uploaded a backup (or
|
||||||
|
* the uploaded backup was already current).
|
||||||
|
*
|
||||||
|
* Does NOT correspond to the timestamp of the backup,
|
||||||
|
* which only changes when the backup content changes.
|
||||||
|
*/
|
||||||
|
lastBackupCycleTimestamp?: Timestamp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Proposal that we're currently trying to pay for.
|
* Proposal that we're currently trying to pay for.
|
||||||
|
@ -296,6 +296,21 @@ async function runBackupCycleForProvider(
|
|||||||
|
|
||||||
logger.trace(`sync response status: ${resp.status}`);
|
logger.trace(`sync response status: ${resp.status}`);
|
||||||
|
|
||||||
|
if (resp.status === HttpResponseStatus.NotModified) {
|
||||||
|
await ws.db
|
||||||
|
.mktx((x) => ({ backupProvider: x.backupProviders }))
|
||||||
|
.runReadWrite(async (tx) => {
|
||||||
|
const prov = await tx.backupProvider.get(provider.baseUrl);
|
||||||
|
if (!prov) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
delete prov.lastError;
|
||||||
|
prov.lastBackupCycleTimestamp = getTimestampNow();
|
||||||
|
await tx.backupProvider.put(prov);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (resp.status === HttpResponseStatus.PaymentRequired) {
|
if (resp.status === HttpResponseStatus.PaymentRequired) {
|
||||||
logger.trace("payment required for backup");
|
logger.trace("payment required for backup");
|
||||||
logger.trace(`headers: ${j2s(resp.headers)}`);
|
logger.trace(`headers: ${j2s(resp.headers)}`);
|
||||||
@ -360,7 +375,7 @@ async function runBackupCycleForProvider(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
prov.lastBackupHash = encodeCrock(currentBackupHash);
|
prov.lastBackupHash = encodeCrock(currentBackupHash);
|
||||||
prov.lastBackupTimestamp = getTimestampNow();
|
prov.lastBackupCycleTimestamp = getTimestampNow();
|
||||||
prov.lastError = undefined;
|
prov.lastError = undefined;
|
||||||
await tx.backupProviders.put(prov);
|
await tx.backupProviders.put(prov);
|
||||||
});
|
});
|
||||||
@ -382,7 +397,7 @@ async function runBackupCycleForProvider(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
prov.lastBackupHash = encodeCrock(hash(backupEnc));
|
prov.lastBackupHash = encodeCrock(hash(backupEnc));
|
||||||
prov.lastBackupTimestamp = getTimestampNow();
|
prov.lastBackupCycleTimestamp = getTimestampNow();
|
||||||
prov.lastError = undefined;
|
prov.lastError = undefined;
|
||||||
await tx.backupProvider.put(prov);
|
await tx.backupProvider.put(prov);
|
||||||
});
|
});
|
||||||
@ -684,7 +699,7 @@ export async function getBackupInfo(
|
|||||||
providers.push({
|
providers.push({
|
||||||
active: x.active,
|
active: x.active,
|
||||||
syncProviderBaseUrl: x.baseUrl,
|
syncProviderBaseUrl: x.baseUrl,
|
||||||
lastSuccessfulBackupTimestamp: x.lastBackupTimestamp,
|
lastSuccessfulBackupTimestamp: x.lastBackupCycleTimestamp,
|
||||||
paymentProposalIds: x.paymentProposalIds,
|
paymentProposalIds: x.paymentProposalIds,
|
||||||
lastError: x.lastError,
|
lastError: x.lastError,
|
||||||
paymentStatus: await getProviderPaymentInfo(ws, x),
|
paymentStatus: await getProviderPaymentInfo(ws, x),
|
||||||
@ -759,7 +774,7 @@ async function backupRecoveryTheirs(
|
|||||||
}
|
}
|
||||||
const providers = await tx.backupProviders.iter().toArray();
|
const providers = await tx.backupProviders.iter().toArray();
|
||||||
for (const prov of providers) {
|
for (const prov of providers) {
|
||||||
prov.lastBackupTimestamp = undefined;
|
prov.lastBackupCycleTimestamp = undefined;
|
||||||
prov.lastBackupHash = undefined;
|
prov.lastBackupHash = undefined;
|
||||||
await tx.backupProviders.put(prov);
|
await tx.backupProviders.put(prov);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user