Refactor & update API
This commit is contained in:
parent
5f1075879f
commit
3065edba37
6 changed files with 42 additions and 33 deletions
|
|
@ -1,27 +1,11 @@
|
||||||
import { Logger } from "src/logger";
|
import { Logger } from "src/logger";
|
||||||
|
import { DEFAULT_SETTINGS, SyncSettings } from "./sync-settings";
|
||||||
export type DocumentId = string;
|
import {
|
||||||
export type DocumentVersionId = number;
|
RelativePath,
|
||||||
export type RelativePath = string;
|
DocumentMetadata,
|
||||||
|
DocumentId,
|
||||||
export interface SyncSettings {
|
DocumentVersionId,
|
||||||
remoteUri: string;
|
} from "./document-metadata";
|
||||||
token: string;
|
|
||||||
fullScanIntervalInSeconds: number;
|
|
||||||
fullScanEnabled: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const DEFAULT_SETTINGS: SyncSettings = {
|
|
||||||
remoteUri: "",
|
|
||||||
token: "",
|
|
||||||
fullScanIntervalInSeconds: 60,
|
|
||||||
fullScanEnabled: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface DocumentMetadata {
|
|
||||||
documentId: DocumentId;
|
|
||||||
parentVersionId: DocumentVersionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface StoredDatabase {
|
interface StoredDatabase {
|
||||||
documents: Map<RelativePath, DocumentMetadata>;
|
documents: Map<RelativePath, DocumentMetadata>;
|
||||||
|
|
@ -69,6 +53,10 @@ export class Database {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getDocuments(): Map<RelativePath, DocumentMetadata> {
|
||||||
|
return this._documents;
|
||||||
|
}
|
||||||
|
|
||||||
public getSettings(): SyncSettings {
|
public getSettings(): SyncSettings {
|
||||||
return this._settings;
|
return this._settings;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
8
plugin/src/database/document-metadata.ts
Normal file
8
plugin/src/database/document-metadata.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
export type DocumentId = string;
|
||||||
|
export type DocumentVersionId = number;
|
||||||
|
export type RelativePath = string;
|
||||||
|
|
||||||
|
export interface DocumentMetadata {
|
||||||
|
documentId: DocumentId;
|
||||||
|
parentVersionId: DocumentVersionId;
|
||||||
|
}
|
||||||
13
plugin/src/database/sync-settings.ts
Normal file
13
plugin/src/database/sync-settings.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
export interface SyncSettings {
|
||||||
|
remoteUri: string;
|
||||||
|
token: string;
|
||||||
|
fullScanIntervalInSeconds: number;
|
||||||
|
fullScanEnabled: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const DEFAULT_SETTINGS: SyncSettings = {
|
||||||
|
remoteUri: "",
|
||||||
|
token: "",
|
||||||
|
fullScanIntervalInSeconds: 60,
|
||||||
|
fullScanEnabled: true,
|
||||||
|
};
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
import * as plugin from "../../../backend/sync_lib/pkg/sync_lib.js";
|
import * as plugin from "../../../backend/sync_lib/pkg/sync_lib.js";
|
||||||
|
|
||||||
import createClient, { Client } from "openapi-fetch";
|
import createClient, { Client } from "openapi-fetch";
|
||||||
import type { components, paths } from "./types.js"; // generated by openapi-typescript
|
import type { components, paths } from "./types"; // generated by openapi-typescript
|
||||||
import { Logger } from "src/logger.js";
|
import { Logger } from "src/logger";
|
||||||
|
import { Database } from "src/database/database";
|
||||||
|
import { SyncSettings } from "src/database/sync-settings";
|
||||||
import {
|
import {
|
||||||
Database,
|
|
||||||
DocumentId,
|
DocumentId,
|
||||||
DocumentVersionId,
|
DocumentVersionId,
|
||||||
SyncSettings,
|
} from "src/database/document-metadata.js";
|
||||||
} from "src/database/database.js";
|
|
||||||
|
|
||||||
export class SyncServer {
|
export class SyncServer {
|
||||||
private static VAULT_ID = "default";
|
private static VAULT_ID = "default";
|
||||||
|
|
@ -47,7 +47,7 @@ export class SyncServer {
|
||||||
content: ArrayBuffer;
|
content: ArrayBuffer;
|
||||||
relativePath: string;
|
relativePath: string;
|
||||||
createdDate: Date;
|
createdDate: Date;
|
||||||
}): Promise<components["schemas"]["DocumentVersionWithoutContent"]> {
|
}): Promise<components["schemas"]["DocumentVersion"]> {
|
||||||
let contentBytes = new Uint8Array(content);
|
let contentBytes = new Uint8Array(content);
|
||||||
let response = await this.client.POST("/vaults/{vault_id}/documents", {
|
let response = await this.client.POST("/vaults/{vault_id}/documents", {
|
||||||
params: {
|
params: {
|
||||||
|
|
@ -88,7 +88,7 @@ export class SyncServer {
|
||||||
relativePath: string;
|
relativePath: string;
|
||||||
content: ArrayBuffer;
|
content: ArrayBuffer;
|
||||||
createdDate: Date;
|
createdDate: Date;
|
||||||
}): Promise<components["schemas"]["DocumentVersionWithoutContent"]> {
|
}): Promise<components["schemas"]["DocumentVersion"]> {
|
||||||
let contentBytes = new Uint8Array(content);
|
let contentBytes = new Uint8Array(content);
|
||||||
|
|
||||||
let response = await this.client.PUT(
|
let response = await this.client.PUT(
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ export interface paths {
|
||||||
[name: string]: unknown;
|
[name: string]: unknown;
|
||||||
};
|
};
|
||||||
content: {
|
content: {
|
||||||
"application/json": components["schemas"]["DocumentVersionWithoutContent"];
|
"application/json": components["schemas"]["DocumentVersion"];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -156,7 +156,7 @@ export interface paths {
|
||||||
[name: string]: unknown;
|
[name: string]: unknown;
|
||||||
};
|
};
|
||||||
content: {
|
content: {
|
||||||
"application/json": components["schemas"]["DocumentVersionWithoutContent"];
|
"application/json": components["schemas"]["DocumentVersion"];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import {
|
||||||
Setting,
|
Setting,
|
||||||
} from "obsidian";
|
} from "obsidian";
|
||||||
|
|
||||||
import SyncPlugin from "src/plugin.js";
|
import SyncPlugin from "src/plugin";
|
||||||
import { Database } from "src/database/database";
|
import { Database } from "src/database/database";
|
||||||
import { SyncServer } from "src/services/sync_service";
|
import { SyncServer } from "src/services/sync_service";
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue