Always fetch the right document version content
This commit is contained in:
parent
bfe3e9aeeb
commit
a1bda41646
2 changed files with 43 additions and 7 deletions
|
|
@ -276,6 +276,44 @@ export class SyncService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getDocumentVersionContent({
|
||||||
|
documentId,
|
||||||
|
vaultUpdateId
|
||||||
|
}: {
|
||||||
|
documentId: DocumentId;
|
||||||
|
vaultUpdateId: VaultUpdateId;
|
||||||
|
}): Promise<Uint8Array> {
|
||||||
|
return this.retryForever(async () => {
|
||||||
|
this.logger.debug(
|
||||||
|
`Getting document with id ${documentId} and version ${vaultUpdateId}`
|
||||||
|
);
|
||||||
|
|
||||||
|
const response = await this.client(
|
||||||
|
this.getUrl(
|
||||||
|
`/documents/${documentId}/versions/${vaultUpdateId}/content`
|
||||||
|
),
|
||||||
|
{
|
||||||
|
headers: this.getDefaultHeaders()
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const result = await response.bytes();
|
||||||
|
this.logger.debug(
|
||||||
|
`Got document version content for document ${documentId} version ${vaultUpdateId}`
|
||||||
|
);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
const result: SerializedError =
|
||||||
|
(await response.json()) as SerializedError; // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion
|
||||||
|
|
||||||
|
throw new Error(
|
||||||
|
`Failed to get document: ${SyncService.formatError(result)}`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public async getAll(
|
public async getAll(
|
||||||
since?: VaultUpdateId
|
since?: VaultUpdateId
|
||||||
): Promise<FetchLatestDocumentsResponse> {
|
): Promise<FetchLatestDocumentsResponse> {
|
||||||
|
|
|
||||||
|
|
@ -413,11 +413,11 @@ export class UnrestrictedSyncer {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const content = (
|
const contentBytes =
|
||||||
await this.syncService.get({
|
await this.syncService.getDocumentVersionContent({
|
||||||
documentId: remoteVersion.documentId
|
documentId: remoteVersion.documentId,
|
||||||
})
|
vaultUpdateId: remoteVersion.vaultUpdateId
|
||||||
).contentBase64;
|
});
|
||||||
|
|
||||||
// We're trying to create an entirely new document that didn't exist locally
|
// We're trying to create an entirely new document that didn't exist locally
|
||||||
document = this.database.getDocumentByDocumentId(
|
document = this.database.getDocumentByDocumentId(
|
||||||
|
|
@ -431,8 +431,6 @@ export class UnrestrictedSyncer {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const contentBytes = base64ToBytes(content);
|
|
||||||
|
|
||||||
await this.operations.ensureClearPath(remoteVersion.relativePath);
|
await this.operations.ensureClearPath(remoteVersion.relativePath);
|
||||||
|
|
||||||
const [promise, resolve] = createPromise();
|
const [promise, resolve] = createPromise();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue