Use new API
This commit is contained in:
parent
65a42a18bf
commit
570b5f9bfc
5 changed files with 31 additions and 19 deletions
|
|
@ -3,7 +3,7 @@ import { DEFAULT_SETTINGS, SyncSettings } from "./sync-settings";
|
||||||
import {
|
import {
|
||||||
RelativePath,
|
RelativePath,
|
||||||
DocumentMetadata,
|
DocumentMetadata,
|
||||||
DocumentVersionId,
|
VaultUpdateId,
|
||||||
} from "./document-metadata";
|
} from "./document-metadata";
|
||||||
|
|
||||||
interface StoredDatabase {
|
interface StoredDatabase {
|
||||||
|
|
@ -91,7 +91,7 @@ export class Database {
|
||||||
hash,
|
hash,
|
||||||
}: {
|
}: {
|
||||||
relativePath: RelativePath;
|
relativePath: RelativePath;
|
||||||
parentVersionId: DocumentVersionId;
|
parentVersionId: VaultUpdateId;
|
||||||
hash: string;
|
hash: string;
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
this._documents.set(relativePath, {
|
this._documents.set(relativePath, {
|
||||||
|
|
@ -109,7 +109,7 @@ export class Database {
|
||||||
}: {
|
}: {
|
||||||
oldRelativePath: RelativePath;
|
oldRelativePath: RelativePath;
|
||||||
relativePath: RelativePath;
|
relativePath: RelativePath;
|
||||||
parentVersionId: DocumentVersionId;
|
parentVersionId: VaultUpdateId;
|
||||||
hash: string;
|
hash: string;
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
this._documents.delete(oldRelativePath);
|
this._documents.delete(oldRelativePath);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
export type DocumentVersionId = number;
|
export type VaultUpdateId = number;
|
||||||
export type RelativePath = string;
|
export type RelativePath = string;
|
||||||
|
|
||||||
export interface DocumentMetadata {
|
export interface DocumentMetadata {
|
||||||
parentVersionId: DocumentVersionId;
|
parentVersionId: VaultUpdateId;
|
||||||
hash: string;
|
hash: string;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,7 @@ import type { components, paths } from "./types"; // generated by openapi-typesc
|
||||||
import { Logger } from "src/logger";
|
import { Logger } from "src/logger";
|
||||||
import { Database } from "src/database/database";
|
import { Database } from "src/database/database";
|
||||||
import { SyncSettings } from "src/database/sync-settings";
|
import { SyncSettings } from "src/database/sync-settings";
|
||||||
import {
|
import { VaultUpdateId, RelativePath } from "src/database/document-metadata.js";
|
||||||
DocumentVersionId,
|
|
||||||
RelativePath,
|
|
||||||
} from "src/database/document-metadata.js";
|
|
||||||
|
|
||||||
export class SyncServer {
|
export class SyncServer {
|
||||||
private static VAULT_ID = "default";
|
private static VAULT_ID = "default";
|
||||||
|
|
@ -53,7 +50,7 @@ export class SyncServer {
|
||||||
createdDate,
|
createdDate,
|
||||||
}: {
|
}: {
|
||||||
relativePath: RelativePath;
|
relativePath: RelativePath;
|
||||||
parentVersionId: DocumentVersionId | undefined;
|
parentVersionId: VaultUpdateId | undefined;
|
||||||
contentBytes: Uint8Array;
|
contentBytes: Uint8Array;
|
||||||
createdDate: Date;
|
createdDate: Date;
|
||||||
}): Promise<components["schemas"]["DocumentVersion"]> {
|
}): Promise<components["schemas"]["DocumentVersion"]> {
|
||||||
|
|
@ -160,9 +157,9 @@ export class SyncServer {
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getAll(): Promise<
|
public async getAll(
|
||||||
components["schemas"]["DocumentVersionWithoutContent"][]
|
since?: VaultUpdateId
|
||||||
> {
|
): Promise<components["schemas"]["FetchLatestDocumentsResponse"]> {
|
||||||
const response = await this.client.GET("/vaults/{vault_id}/documents", {
|
const response = await this.client.GET("/vaults/{vault_id}/documents", {
|
||||||
params: {
|
params: {
|
||||||
path: {
|
path: {
|
||||||
|
|
@ -172,6 +169,9 @@ export class SyncServer {
|
||||||
authorization:
|
authorization:
|
||||||
"Bearer " + this.database.getSettings().token,
|
"Bearer " + this.database.getSettings().token,
|
||||||
},
|
},
|
||||||
|
query: {
|
||||||
|
since_update_id: since,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,9 @@ export interface paths {
|
||||||
};
|
};
|
||||||
get: {
|
get: {
|
||||||
parameters: {
|
parameters: {
|
||||||
query?: never;
|
query?: {
|
||||||
|
since_update_id?: number | null;
|
||||||
|
};
|
||||||
header: {
|
header: {
|
||||||
authorization: string;
|
authorization: string;
|
||||||
};
|
};
|
||||||
|
|
@ -65,7 +67,7 @@ export interface paths {
|
||||||
[name: string]: unknown;
|
[name: string]: unknown;
|
||||||
};
|
};
|
||||||
content: {
|
content: {
|
||||||
"application/json": components["schemas"]["DocumentVersionWithoutContent"][];
|
"application/json": components["schemas"]["FetchLatestDocumentsResponse"];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -225,7 +227,7 @@ export interface components {
|
||||||
updatedDate: string;
|
updatedDate: string;
|
||||||
vaultId: string;
|
vaultId: string;
|
||||||
/** Format: int64 */
|
/** Format: int64 */
|
||||||
versionId: number;
|
vaultUpdateId: number;
|
||||||
};
|
};
|
||||||
DocumentVersionWithoutContent: {
|
DocumentVersionWithoutContent: {
|
||||||
/** Format: date-time */
|
/** Format: date-time */
|
||||||
|
|
@ -236,7 +238,12 @@ export interface components {
|
||||||
updatedDate: string;
|
updatedDate: string;
|
||||||
vaultId: string;
|
vaultId: string;
|
||||||
/** Format: int64 */
|
/** Format: int64 */
|
||||||
versionId: number;
|
vaultUpdateId: number;
|
||||||
|
};
|
||||||
|
FetchLatestDocumentsResponse: {
|
||||||
|
/** Format: int64 */
|
||||||
|
lastUpdateId: number;
|
||||||
|
latestDocuments: components["schemas"]["DocumentVersionWithoutContent"][];
|
||||||
};
|
};
|
||||||
PathParams: {
|
PathParams: {
|
||||||
vault_id: string;
|
vault_id: string;
|
||||||
|
|
@ -257,6 +264,10 @@ export interface components {
|
||||||
isAuthenticated: boolean;
|
isAuthenticated: boolean;
|
||||||
serverVersion: string;
|
serverVersion: string;
|
||||||
};
|
};
|
||||||
|
QueryParams: {
|
||||||
|
/** Format: int64 */
|
||||||
|
since_update_id?: number | null;
|
||||||
|
};
|
||||||
UpdateDocumentVersion: {
|
UpdateDocumentVersion: {
|
||||||
contentBase64: string;
|
contentBase64: string;
|
||||||
/** Format: date-time */
|
/** Format: date-time */
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,8 @@ import { TFile } from "obsidian";
|
||||||
import { Database } from "src/database/database";
|
import { Database } from "src/database/database";
|
||||||
import { Logger } from "src/logger";
|
import { Logger } from "src/logger";
|
||||||
import { SyncServer } from "src/services/sync_service";
|
import { SyncServer } from "src/services/sync_service";
|
||||||
import { hash, isEqualBytes } from "src/utils";
|
import { hash } from "src/utils/hash.js";
|
||||||
|
import { isEqualBytes } from "src/utils/is-equal-bytes.js";
|
||||||
|
|
||||||
export async function syncLocallyUpdatedFile({
|
export async function syncLocallyUpdatedFile({
|
||||||
database,
|
database,
|
||||||
|
|
@ -43,7 +44,7 @@ export async function syncLocallyUpdatedFile({
|
||||||
const localDbUpdatePromise = database.moveDocument({
|
const localDbUpdatePromise = database.moveDocument({
|
||||||
oldRelativePath: oldPath || file.path,
|
oldRelativePath: oldPath || file.path,
|
||||||
relativePath: file.path,
|
relativePath: file.path,
|
||||||
parentVersionId: response.versionId,
|
parentVersionId: response.vaultUpdateId,
|
||||||
hash: contentHash,
|
hash: contentHash,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue