Skip to content

Commit

Permalink
Add configuration for Zotero server port and shared group selection
Browse files Browse the repository at this point in the history
See more info on shared group selection request: MunGell/ZotServer#2
See more info on port settings request: jannessm/joplin-zotero-link#3

Fixes vanakat/zotero-link#3
  • Loading branch information
MunGell committed Jun 22, 2024
1 parent 13ecad8 commit f138f76
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/ZoteroAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ export class LocalAPIV3Adapter implements ZoteroAdapter {
})
}

groups(): Promise<any[]> {
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<ZoteroItem[]> {
return request({
url: `${this.baseUrl}/items?` + new URLSearchParams(parameters).toString(),
Expand Down
37 changes: 36 additions & 1 deletion src/ZoteroBridgeSettingTab.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { LocalAPIV3Adapter } from './ZoteroAdapter';
import { ZoteroBridge } from './ZoteroBridge';
import { ZoteroBridgeConnectionType } from './ZoteroBridgeSettings'
import { App, PluginSettingTab, Setting } from 'obsidian';
Expand All @@ -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) => {
Expand All @@ -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
});
})
});
}
}
2 changes: 1 addition & 1 deletion src/ZoteroBridgeSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface ZoteroBridgeSettings {

export const DEFAULT_SETTINGS: Partial<ZoteroBridgeSettings> = {
connectionType: ZoteroBridgeConnectionType.ZotServer,
userOrGroup: 'users/0', // TODO: hardcoded to the main user
userOrGroup: 'users/0',
host: 'localhost',
port: '23119',
};

0 comments on commit f138f76

Please # to comment.