From f138f76250848f4d23d0f0771a9f97e8b7930177 Mon Sep 17 00:00:00 2001 From: Shmavon Gazanchyan Date: Sun, 23 Jun 2024 00:01:01 +0100 Subject: [PATCH] Add configuration for Zotero server port and shared group selection See more info on shared group selection request: https://github.com/MunGell/ZotServer/issues/2 See more info on port settings request: https://github.com/jannessm/joplin-zotero-link/issues/3 Fixes https://github.com/vanakat/zotero-link/issues/3 --- src/ZoteroAdapter.ts | 10 ++++++++++ src/ZoteroBridgeSettingTab.ts | 37 ++++++++++++++++++++++++++++++++++- src/ZoteroBridgeSettings.ts | 2 +- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/ZoteroAdapter.ts b/src/ZoteroAdapter.ts index 73d57a2..5756b5c 100644 --- a/src/ZoteroAdapter.ts +++ b/src/ZoteroAdapter.ts @@ -46,6 +46,16 @@ export class LocalAPIV3Adapter implements ZoteroAdapter { }) } + groups(): Promise { + return request({ + url: `http://${this.settings.host}:${this.settings.port}/api/users/0/groups`, + method: 'get', + contentType: 'application/json' + }) + .then(JSON.parse) + .then((groups: any[]) => groups.map(group => group.data)); + } + items(parameters: ZoteroItemsRequestParameters): Promise { return request({ url: `${this.baseUrl}/items?` + new URLSearchParams(parameters).toString(), diff --git a/src/ZoteroBridgeSettingTab.ts b/src/ZoteroBridgeSettingTab.ts index bebc214..0ec8aca 100644 --- a/src/ZoteroBridgeSettingTab.ts +++ b/src/ZoteroBridgeSettingTab.ts @@ -1,3 +1,4 @@ +import { LocalAPIV3Adapter } from './ZoteroAdapter'; import { ZoteroBridge } from './ZoteroBridge'; import { ZoteroBridgeConnectionType } from './ZoteroBridgeSettings' import { App, PluginSettingTab, Setting } from 'obsidian'; @@ -15,9 +16,10 @@ export class ZoteroBridgeSettingTab extends PluginSettingTab { new Setting(this.containerEl) .setName('Connection type') + .setDesc('Note that you either need to install ZotServer plugin in Zotero 6 or enable Local API support in Zotero 7 advanced settings.') .addDropdown(dropdown => { dropdown - .addOption(ZoteroBridgeConnectionType.ZotServer.toString(), 'ZotServer Plugin') + .addOption(ZoteroBridgeConnectionType.ZotServer.toString(), 'Zotero 6 ZotServer Plugin') .addOption(ZoteroBridgeConnectionType.LocalAPIV3.toString(), 'Zotero 7 Local API (v3)') .setValue(this.plugin.settings.connectionType.toString()) .onChange(async (value) => { @@ -26,5 +28,38 @@ export class ZoteroBridgeSettingTab extends PluginSettingTab { }); }) }); + + new Setting(this.containerEl) + .setName('User or group') + .setDesc('This parameter only works with Zotero 7 connection type.') + .addDropdown(async dropdown => { + const adapter = new LocalAPIV3Adapter(this.plugin.settings); + const groups = await adapter.groups() + + dropdown.addOption(`users/0`, 'My Library') + + groups.forEach(group => { + dropdown.addOption(`groups/${group.id}`, group.name) + }) + + dropdown.setValue(this.plugin.settings.userOrGroup) + .onChange(async (value) => { + await this.plugin.saveSettings({ + userOrGroup: value + }); + }) + }); + + new Setting(this.containerEl) + .setName('Zotero server port') + .setDesc(`Don't change unless you really know what you are doing`) + .addText(txt => { + txt.setValue(this.plugin.settings.port.toString()) + .onChange(async (value) => { + await this.plugin.saveSettings({ + port: value + }); + }) + }); } } diff --git a/src/ZoteroBridgeSettings.ts b/src/ZoteroBridgeSettings.ts index d753e32..1a1ff50 100644 --- a/src/ZoteroBridgeSettings.ts +++ b/src/ZoteroBridgeSettings.ts @@ -12,7 +12,7 @@ export interface ZoteroBridgeSettings { export const DEFAULT_SETTINGS: Partial = { connectionType: ZoteroBridgeConnectionType.ZotServer, - userOrGroup: 'users/0', // TODO: hardcoded to the main user + userOrGroup: 'users/0', host: 'localhost', port: '23119', };