Add vault name setting
This commit is contained in:
parent
728c4a5a28
commit
d069cbdb67
3 changed files with 58 additions and 19 deletions
|
|
@ -1,6 +1,7 @@
|
|||
export interface SyncSettings {
|
||||
remoteUri: string;
|
||||
token: string;
|
||||
vaultName: string;
|
||||
fetchChangesUpdateIntervalMs: number;
|
||||
isSyncEnabled: boolean;
|
||||
}
|
||||
|
|
@ -8,6 +9,7 @@ export interface SyncSettings {
|
|||
export const DEFAULT_SETTINGS: SyncSettings = {
|
||||
remoteUri: "",
|
||||
token: "",
|
||||
vaultName: "default",
|
||||
fetchChangesUpdateIntervalMs: 1000,
|
||||
isSyncEnabled: true,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import {
|
|||
} from "src/database/document-metadata.js";
|
||||
|
||||
export class SyncServer {
|
||||
private static VAULT_ID = "default";
|
||||
private client: Client<paths>;
|
||||
|
||||
public constructor(private database: Database) {
|
||||
|
|
@ -56,22 +55,25 @@ export class SyncServer {
|
|||
contentBytes: Uint8Array;
|
||||
createdDate: Date;
|
||||
}): Promise<components["schemas"]["DocumentVersion"]> {
|
||||
const response = await this.client.POST("/vaults/{vault_id}/documents", {
|
||||
params: {
|
||||
path: {
|
||||
vault_id: SyncServer.VAULT_ID,
|
||||
const response = await this.client.POST(
|
||||
"/vaults/{vault_id}/documents",
|
||||
{
|
||||
params: {
|
||||
path: {
|
||||
vault_id: this.database.getSettings().vaultName,
|
||||
},
|
||||
header: {
|
||||
authorization:
|
||||
"Bearer " + this.database.getSettings().token,
|
||||
},
|
||||
},
|
||||
header: {
|
||||
authorization:
|
||||
"Bearer " + this.database.getSettings().token,
|
||||
body: {
|
||||
contentBase64: lib.bytes_to_base64(contentBytes),
|
||||
createdDate: createdDate.toISOString(),
|
||||
relativePath,
|
||||
},
|
||||
},
|
||||
body: {
|
||||
contentBase64: lib.bytes_to_base64(contentBytes),
|
||||
createdDate: createdDate.toISOString(),
|
||||
relativePath,
|
||||
},
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.data) {
|
||||
throw new Error(`Failed to create document: ${response.error}`);
|
||||
|
|
@ -102,7 +104,7 @@ export class SyncServer {
|
|||
{
|
||||
params: {
|
||||
path: {
|
||||
vault_id: SyncServer.VAULT_ID,
|
||||
vault_id: this.database.getSettings().vaultName,
|
||||
document_id: documentId,
|
||||
},
|
||||
header: {
|
||||
|
|
@ -144,7 +146,7 @@ export class SyncServer {
|
|||
{
|
||||
params: {
|
||||
path: {
|
||||
vault_id: SyncServer.VAULT_ID,
|
||||
vault_id: this.database.getSettings().vaultName,
|
||||
document_id: documentId,
|
||||
},
|
||||
header: {
|
||||
|
|
@ -180,7 +182,7 @@ export class SyncServer {
|
|||
{
|
||||
params: {
|
||||
path: {
|
||||
vault_id: SyncServer.VAULT_ID,
|
||||
vault_id: this.database.getSettings().vaultName,
|
||||
document_id: documentId,
|
||||
},
|
||||
header: {
|
||||
|
|
@ -208,7 +210,7 @@ export class SyncServer {
|
|||
const response = await this.client.GET("/vaults/{vault_id}/documents", {
|
||||
params: {
|
||||
path: {
|
||||
vault_id: SyncServer.VAULT_ID,
|
||||
vault_id: this.database.getSettings().vaultName,
|
||||
},
|
||||
header: {
|
||||
authorization:
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import { Database } from "src/database/database";
|
|||
import { SyncServer } from "src/services/sync_service";
|
||||
|
||||
export class SyncSettingsTab extends PluginSettingTab {
|
||||
private editedVaultName: string;
|
||||
|
||||
public constructor(
|
||||
app: App,
|
||||
plugin: SyncPlugin,
|
||||
|
|
@ -12,6 +14,11 @@ export class SyncSettingsTab extends PluginSettingTab {
|
|||
private syncServer: SyncServer
|
||||
) {
|
||||
super(app, plugin);
|
||||
this.editedVaultName = this.database.getSettings().vaultName;
|
||||
this.database.addOnSettingsChangeHandlers((s) => {
|
||||
this.editedVaultName = s.vaultName;
|
||||
this.display();
|
||||
});
|
||||
}
|
||||
|
||||
display(): void {
|
||||
|
|
@ -60,6 +67,34 @@ export class SyncSettingsTab extends PluginSettingTab {
|
|||
})
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Vault name")
|
||||
.setDesc(
|
||||
"Set the name of the remote vault that you want to sync with"
|
||||
)
|
||||
.setTooltip("todo, links to dcocs")
|
||||
.addText((text) =>
|
||||
text
|
||||
.setPlaceholder("My Obsidian Vault")
|
||||
.setValue(this.database.getSettings().vaultName)
|
||||
.onChange((value) => (this.editedVaultName = value))
|
||||
)
|
||||
.addButton((button) =>
|
||||
button.setButtonText("Apply").onClick(async () => {
|
||||
if (
|
||||
this.editedVaultName ===
|
||||
this.database.getSettings().vaultName
|
||||
) {
|
||||
return;
|
||||
}
|
||||
this.database.setSetting("vaultName", this.editedVaultName);
|
||||
await this.database.resetSyncState();
|
||||
new Notice(
|
||||
"Sync state has been reset, you will need to resync"
|
||||
);
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Access token")
|
||||
.setDesc(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue