https://github.com/retorquere/zotero-sync
https://github.com/retorquere/zotero-sync
sync zotero zotero-sync
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/retorquere/zotero-sync
- Owner: retorquere
- License: agpl-3.0
- Created: 2021-04-16T09:12:44.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-01-03T15:15:35.000Z (over 2 years ago)
- Last Synced: 2024-10-12T21:17:30.774Z (over 1 year ago)
- Topics: sync, zotero, zotero-sync
- Language: TypeScript
- Homepage: https://retorque.re/zotero-sync/
- Size: 225 KB
- Stars: 33
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Zotero one-way sync
* Get a Zotero API key [here](https://www.zotero.org/settings/keys/new) -- the key only needs read only access to what you want to have synced
```
import { Sync } from '@retorquere/zotero-sync'
import { Store } from '@retorquere/zotero-sync/json-store'
(async () => {
const zotero = new Sync
// will emit the following so you can track progress:
// emit(Sync.event.library, , n, total number of libraries). Called at the start of a library sync. Library name is empty for the main library, if there's a name, it's a group library
// emit(Sync.event.error, err)
// emit(Sync.event.item, , n, total number of items within library). Called when an item is added/updated
// emit(Sync.event.collection, , n, number of collections within library). Called when a collection is added/updated
for (const event of [ Sync.event.library, Sync.event.collection, Sync.event.item, Sync.event.error ]) {
zotero.on(event, (e => function() { console.log(e, [...arguments]) })(event))
}
await zotero.login(process.env.ZOTERO_API_KEY)
await zotero.sync(await (new Store).load('data'))
})().catch(err => {
console.log(err)
process.exit(1)
})
```
or
```
const Sync = require('@retorquere/zotero-sync').Sync
const Store = require('@retorquere/zotero-sync/json-store').Store
(async () => {
const zotero = new Sync;
for (const event of [Sync.event.library, Sync.event.collection, Sync.event.item, Sync.event.error]) {
zotero.on(event, (e => function () { console.log(e, [...arguments]); })(event));
}
await zotero.login(process.env.ZOTERO_API_KEY);
await zotero.sync(await (new Store).load('data'));
})().catch(err => {
console.log(err);
process.exit(1);
});
```
or (untested) local access
```
const Sync = require('@retorquere/zotero-sync').Sync
const Store = require('@retorquere/zotero-sync/json-store').Store
(async () => {
const zotero = new Sync;
for (const event of [Sync.event.library, Sync.event.collection, Sync.event.item, Sync.event.error]) {
zotero.on(event, (e => function () { console.log(e, [...arguments]); })(event));
}
zotero.local()
await zotero.sync(await (new Store).load('data'));
})().catch(err => {
console.log(err);
process.exit(1);
});
```
make your own store by implementing
```
interface Library {
version: number
name: string
save: (name: string, version: number) => Promise
remove_collections: (keys: string[]) => Promise
add_collection: (collection: Collection) => Promise
add: (item: Item.Any) => Promise
remove: (keys: string[]) => Promise
}
interface Store {
libraries: string[] // user_or_group_prefix
remove: (user_or_group_prefix: string) => Promise
get: (user_or_group_prefix: string) => Promise // must return a library -- create one if it doesn't exist yet
}
```