,,
This commit is contained in:
parent
0c75d3b4c2
commit
3dab48f58b
1 changed files with 1141 additions and 1376 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import type { DocumentId, VaultUpdateId } from "../persistence/database";
|
||||
import type { Settings } from "../persistence/settings";
|
||||
import { abortable } from "../utils/abortable";
|
||||
import { VaultHistoryStatus } from "../types/vault-history-status";
|
||||
import type { DocumentUpdateResponse } from "./types/DocumentUpdateResponse";
|
||||
import type { DocumentVersionWithoutContent } from "./types/DocumentVersionWithoutContent";
|
||||
import type { EventBatch } from "./types/EventBatch";
|
||||
|
|
@ -31,12 +31,6 @@ export class SyncService {
|
|||
this.pause();
|
||||
}
|
||||
|
||||
public get vaultHistoryStatus(): VaultHistoryStatus {
|
||||
return this.history.get() !== undefined
|
||||
? VaultHistoryStatus.STORED
|
||||
: VaultHistoryStatus.MISSING;
|
||||
}
|
||||
|
||||
public pause(): void {
|
||||
this.session.abort(new SyncResetError());
|
||||
}
|
||||
|
|
@ -57,7 +51,7 @@ export class SyncService {
|
|||
return this.request("/vault-snapshot");
|
||||
}
|
||||
|
||||
public async getEvents(after: number): Promise<EventBatch> {
|
||||
public async getEvents(after: VaultUpdateId): Promise<EventBatch> {
|
||||
return this.request(`/events-since?after=${after}`);
|
||||
}
|
||||
|
||||
|
|
@ -68,13 +62,13 @@ export class SyncService {
|
|||
}
|
||||
|
||||
public async putFileContent(
|
||||
id: string,
|
||||
id: DocumentId,
|
||||
request: PutFileContent
|
||||
): Promise<DocumentUpdateResponse> {
|
||||
return this.request(`/documents/${id}`, request);
|
||||
}
|
||||
|
||||
public async getDocumentMetadata(id: string): Promise<DocumentVersionWithoutContent> {
|
||||
public async getDocumentMetadata(id: DocumentId): Promise<DocumentVersionWithoutContent> {
|
||||
return this.request(`/documents/${id}/metadata`);
|
||||
}
|
||||
|
||||
|
|
@ -82,8 +76,8 @@ export class SyncService {
|
|||
documentId,
|
||||
vaultUpdateId
|
||||
}: {
|
||||
documentId: string;
|
||||
vaultUpdateId: number;
|
||||
documentId: DocumentId;
|
||||
vaultUpdateId: VaultUpdateId;
|
||||
}): Promise<Uint8Array> {
|
||||
return this.request(
|
||||
`/documents/${documentId}/versions/${vaultUpdateId}/content`,
|
||||
|
|
@ -95,27 +89,23 @@ export class SyncService {
|
|||
|
||||
private getHistoryHeaders(): Record<string, string> {
|
||||
const checkpoint = this.history.get();
|
||||
return checkpoint !== undefined && checkpoint !== ""
|
||||
return checkpoint !== undefined
|
||||
? { "X-Vault-Link-History": checkpoint }
|
||||
: {};
|
||||
}
|
||||
|
||||
private async recordHistory(response: Response): Promise<void> {
|
||||
const checkpoint = response.headers.get("x-vault-link-history");
|
||||
if (checkpoint === null || checkpoint === "")
|
||||
throw new PermanentSyncError("Missing server history checkpoint");
|
||||
const previous = this.history.get();
|
||||
if (checkpoint === previous) return;
|
||||
if (
|
||||
checkpoint !== null &&
|
||||
checkpoint !== ""
|
||||
) {
|
||||
const previous = this.history.get();
|
||||
if (checkpoint === previous) return;
|
||||
if (
|
||||
previous === undefined ||
|
||||
previous === "" ||
|
||||
Number(checkpoint.split(":")[0]) >=
|
||||
previous === undefined ||
|
||||
Number(checkpoint.split(":")[0]) >=
|
||||
Number(previous.split(":")[0])
|
||||
)
|
||||
await this.history.save(checkpoint);
|
||||
}
|
||||
)
|
||||
await this.history.save(checkpoint);
|
||||
}
|
||||
|
||||
private checkHistory(response: Response): void {
|
||||
|
|
|
|||
Loading…
Reference in a new issue