Clean up
This commit is contained in:
parent
5886e54e56
commit
8a63f84ecc
2 changed files with 15 additions and 83 deletions
|
|
@ -12,17 +12,13 @@ import {
|
|||
|
||||
import * as plugin from "../../backend/sync_lib/pkg/sync_lib.js";
|
||||
import * as wasmBin from "../../backend/sync_lib/pkg/sync_lib_bg.wasm";
|
||||
import { getSystemErrorName } from "util";
|
||||
import { SyncSettingsTab } from "./settings/settings-tab.js";
|
||||
import { SyncSettingsTab } from "./views/settings-tab.js";
|
||||
import { SyncView } from "./views/sync-view.js";
|
||||
import {
|
||||
DEFAULT_SETTINGS,
|
||||
SettingsContainer,
|
||||
SyncSettings,
|
||||
} from "./settings/settings.js";
|
||||
|
||||
import { Logger } from "./logger.js";
|
||||
import { SyncEventHandler } from "./events/sync-event-handler.js";
|
||||
import { Syncer } from "./syncer/syncer.js";
|
||||
import { SyncServer } from "./services/sync_service.js";
|
||||
import { Database } from "./database/database.js";
|
||||
|
||||
export default class SyncPlugin extends Plugin {
|
||||
async onload() {
|
||||
|
|
@ -30,7 +26,6 @@ export default class SyncPlugin extends Plugin {
|
|||
|
||||
await plugin.default(Promise.resolve((wasmBin as any).default));
|
||||
|
||||
// This adds an editor command that can perform some operation on the current editor instance
|
||||
this.addCommand({
|
||||
id: "sample-editor-command",
|
||||
name: "Sample editor command",
|
||||
|
|
@ -40,16 +35,18 @@ export default class SyncPlugin extends Plugin {
|
|||
},
|
||||
});
|
||||
|
||||
const settingsContainer = new SettingsContainer(
|
||||
this,
|
||||
await this.loadData()
|
||||
);
|
||||
this.addSettingTab(
|
||||
new SyncSettingsTab(this.app, this, settingsContainer)
|
||||
const database = new Database(
|
||||
await this.loadData(),
|
||||
this.saveData.bind(this)
|
||||
);
|
||||
|
||||
const syncer = new Syncer(settingsContainer);
|
||||
const eventHandler = new SyncEventHandler(syncer);
|
||||
const syncServer = new SyncServer(database);
|
||||
|
||||
this.addSettingTab(
|
||||
new SyncSettingsTab(this.app, this, database, syncServer)
|
||||
);
|
||||
|
||||
const eventHandler = new SyncEventHandler(database, syncServer);
|
||||
|
||||
[
|
||||
this.app.vault.on(
|
||||
|
|
@ -70,7 +67,6 @@ export default class SyncPlugin extends Plugin {
|
|||
),
|
||||
].forEach((event) => this.registerEvent(event));
|
||||
|
||||
// When registering intervals, this function will automatically clear the interval when the plugin is disabled.
|
||||
this.registerInterval(
|
||||
window.setInterval(() => console.log("setInterval"), 5 * 60 * 1000)
|
||||
);
|
||||
|
|
@ -79,11 +75,7 @@ export default class SyncPlugin extends Plugin {
|
|||
const ribbonIconEl = this.addRibbonIcon(
|
||||
"dice",
|
||||
"Sample Plugin",
|
||||
(evt: MouseEvent) => {
|
||||
this.activateView();
|
||||
|
||||
new Notice("This is a notice!");
|
||||
}
|
||||
(_: MouseEvent) => this.activateView()
|
||||
);
|
||||
ribbonIconEl.addClass("my-plugin-ribbon-class");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,60 +0,0 @@
|
|||
import { SettingsContainer, SyncSettings } from "src/settings/settings";
|
||||
|
||||
import * as plugin from "../../../backend/sync_lib/pkg/sync_lib.js";
|
||||
|
||||
import createClient, { Client } from "openapi-fetch";
|
||||
import type { components, paths } from "./types"; // generated by openapi-typescript
|
||||
import { Logger } from "src/logger.js";
|
||||
|
||||
export class Syncer {
|
||||
private static vault_id = "default";
|
||||
private client: Client<paths>;
|
||||
|
||||
public constructor(private settings: SettingsContainer) {
|
||||
this.createClient(settings.getSettings());
|
||||
settings.onChange((s) => this.createClient(s));
|
||||
}
|
||||
|
||||
private createClient(settings: SyncSettings) {
|
||||
this.client = createClient<paths>({
|
||||
baseUrl: settings.remoteUri,
|
||||
});
|
||||
}
|
||||
|
||||
public async onCreate(
|
||||
relativePath: string,
|
||||
content: string
|
||||
): Promise<
|
||||
components["schemas"]["DocumentVersionWithoutContent"] | undefined
|
||||
> {
|
||||
let response = await this.client.POST("/vaults/{vault_id}/documents", {
|
||||
params: {
|
||||
path: { vault_id: Syncer.vault_id },
|
||||
header: {
|
||||
authorization:
|
||||
"Bearer " + this.settings.getSettings().token,
|
||||
},
|
||||
},
|
||||
body: {
|
||||
contentBase64: plugin.string_to_base64(content),
|
||||
createdDate: new Date().toISOString(),
|
||||
isBinary: true,
|
||||
relativePath,
|
||||
},
|
||||
});
|
||||
|
||||
Logger.getInstance().info(
|
||||
"Created document " + JSON.stringify(response.data)
|
||||
);
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
||||
private uri(path: string) {
|
||||
let uri = this.settings.getSettings().remoteUri;
|
||||
if (!uri.endsWith("/")) {
|
||||
uri += "/";
|
||||
}
|
||||
return uri + path;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue