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";
|
||||
|
||||
export type DocumentId = string;
|
||||
export type DocumentVersionId = number;
|
||||
export type RelativePath = string;
|
||||
|
||||
export interface SyncSettings {
|
||||
remoteUri: string;
|
||||
token: string;
|
||||
fullScanIntervalInSeconds: number;
|
||||
fullScanEnabled: boolean;
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: SyncSettings = {
|
||||
remoteUri: "",
|
||||
token: "",
|
||||
fullScanIntervalInSeconds: 60,
|
||||
fullScanEnabled: true,
|
||||
};
|
||||
|
||||
export interface DocumentMetadata {
|
||||
documentId: DocumentId;
|
||||
parentVersionId: DocumentVersionId;
|
||||
}
|
||||
import { DEFAULT_SETTINGS, SyncSettings } from "./sync-settings";
|
||||
import {
|
||||
RelativePath,
|
||||
DocumentMetadata,
|
||||
DocumentId,
|
||||
DocumentVersionId,
|
||||
} from "./document-metadata";
|
||||
|
||||
interface StoredDatabase {
|
||||
documents: Map<RelativePath, DocumentMetadata>;
|
||||
|
|
@ -69,6 +53,10 @@ export class Database {
|
|||
);
|
||||
}
|
||||
|
||||
public getDocuments(): Map<RelativePath, DocumentMetadata> {
|
||||
return this._documents;
|
||||
}
|
||||
|
||||
public getSettings(): SyncSettings {
|
||||
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 createClient, { Client } from "openapi-fetch";
|
||||
import type { components, paths } from "./types.js"; // generated by openapi-typescript
|
||||
import { Logger } from "src/logger.js";
|
||||
import type { components, paths } from "./types"; // generated by openapi-typescript
|
||||
import { Logger } from "src/logger";
|
||||
import { Database } from "src/database/database";
|
||||
import { SyncSettings } from "src/database/sync-settings";
|
||||
import {
|
||||
Database,
|
||||
DocumentId,
|
||||
DocumentVersionId,
|
||||
SyncSettings,
|
||||
} from "src/database/database.js";
|
||||
} from "src/database/document-metadata.js";
|
||||
|
||||
export class SyncServer {
|
||||
private static VAULT_ID = "default";
|
||||
|
|
@ -47,7 +47,7 @@ export class SyncServer {
|
|||
content: ArrayBuffer;
|
||||
relativePath: string;
|
||||
createdDate: Date;
|
||||
}): Promise<components["schemas"]["DocumentVersionWithoutContent"]> {
|
||||
}): Promise<components["schemas"]["DocumentVersion"]> {
|
||||
let contentBytes = new Uint8Array(content);
|
||||
let response = await this.client.POST("/vaults/{vault_id}/documents", {
|
||||
params: {
|
||||
|
|
@ -88,7 +88,7 @@ export class SyncServer {
|
|||
relativePath: string;
|
||||
content: ArrayBuffer;
|
||||
createdDate: Date;
|
||||
}): Promise<components["schemas"]["DocumentVersionWithoutContent"]> {
|
||||
}): Promise<components["schemas"]["DocumentVersion"]> {
|
||||
let contentBytes = new Uint8Array(content);
|
||||
|
||||
let response = await this.client.PUT(
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ export interface paths {
|
|||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["DocumentVersionWithoutContent"];
|
||||
"application/json": components["schemas"]["DocumentVersion"];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
@ -156,7 +156,7 @@ export interface paths {
|
|||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["DocumentVersionWithoutContent"];
|
||||
"application/json": components["schemas"]["DocumentVersion"];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import {
|
|||
Setting,
|
||||
} from "obsidian";
|
||||
|
||||
import SyncPlugin from "src/plugin.js";
|
||||
import SyncPlugin from "src/plugin";
|
||||
import { Database } from "src/database/database";
|
||||
import { SyncServer } from "src/services/sync_service";
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue