Skip to content

Commit

Permalink
Fixes for bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
fbennett committed Dec 12, 2023
1 parent e402927 commit e49683b
Show file tree
Hide file tree
Showing 3 changed files with 191 additions and 237 deletions.
34 changes: 10 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,19 @@ The tool can be set up by cloning its GitHub repo, or directly via
NPM. The commands for updating the tool differ depending on which
installation method is used.

### Installing from NPM

To install directly from NPM, use the following command:

``` bash
bash> npm install --global citeproc-cite-service
```

In this case, the tool can be updated with the following
command:

``` bash
bash> npm update citeproc-cite-service
```

### Installing from the GitHub repo

The following commands can be used to install the tool from a clone of
the GitHub repository:

``` bash
bash> git clone https://github.com/Juris-M/citeproc-cite-service.git
bash> git clone --recursive https://github.com/Juris-M/citeproc-cite-service.git
bash> cd citeproc-cite-service
bash> npm install
bash> npm link
```

If tool is installed in this way, version updates can be pulled in with
the following commands, issued within the repo directory:
Version updates can be pulled in with the following commands, issued within the repo directory:

``` bash
bash> git pull
Expand All @@ -64,7 +48,7 @@ For initial testing, copy the file `callbacks-sample.js` to `callbacks.js`:
bash> cp callbacks-sample.js callbacks.js
```

For purposes of illustration, the sample `callbacks-sample.js` file
For purposes of illustration, the sample ``callbacks-sample.js`` file
contains functions that will write the data necessary to sync local
data with a Zotero library into a file hierarchy. The functions *can
and should* be adapted to apply changes directly to the local data
Expand Down Expand Up @@ -114,7 +98,6 @@ the header can be ignored, they will be stripped before JSON processing):
// For details, see README.md or https://www.npmjs.com/package/citeproc-cite-service
{
"dataPath": "/option/data-dir/or/cwd",
"dataMode": "CSL-M",
"access": {
"groupID": 123456,
"libraryKey": "aBcDeFg7HiJkLmN8oPqRsTu9"
Expand Down Expand Up @@ -212,10 +195,13 @@ bottom of this README for example output):
- **country:** The ISO country code of the item, derived from a tag
prefixed with `cn:` (i.e. `cn:PL`).
- **tags:** Any tags associated with the item.
- **cslItem:** The item metadata in CSL JSON format. If the `dataMode`
is set to `CSL-M` in `config.json` (the default), the data will
include multilingual and extended fields. If set to `CSL`, any
such fields will remain encoded in the `note` field.
- **cslItem:** The item metadata in CSL-M JSON format.
- **cslJsonItem:** The item metadata in CSL JSON format, with
CSL-M extended fields encoded as serialized JSON under
their Jurism field names in the ``note`` field. This
data is suitable for import into Zotero or Jurism, and
if imported with the former, will sync correctly to
a Jurism client.

An update under `attachments` has the following top-level elements
(see the bottom of this README for example output):
Expand Down
23 changes: 6 additions & 17 deletions callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,9 @@ var callbacks = {
fs.writeFileSync(path.join(this.dirs.attachmentsDir, "deletes.txt"), keys.join("\n"));
},
add: async function(siteAttachment){
var m = siteAttachment.filename.match(/\.(pdf|txt|zip|rtf)$/);
var ext = m ? m[1] : "pdf";
this.fileExtFromKey[siteAttachment.key] = ext;
fs.writeFileSync(path.join(this.dirs.attachmentsAdd, siteAttachment.key + ".json"), JSON.stringify(siteAttachment, null, 2));
},
mod: async function(siteAttachment){
var m = siteAttachment.filename.match(/\.(pdf|txt|zip|rtf)$/);
var ext = m ? m[1] : "pdf";
this.fileExtFromKey[siteAttachment.key] = ext;
fs.writeFileSync(path.join(this.dirs.attachmentsMod, siteAttachment.key + ".json"), JSON.stringify(siteAttachment, null, 2));
}
},
Expand All @@ -77,17 +71,12 @@ var callbacks = {
}
}
},
exists: async function(key) {
if (!this.fileExtFromKey[key]) {
return null;
} else {
var filePath = path.join(this.dirs.files, key + "." + this.fileExtFromKey[key]);
return fs.existsSync(filePath);
}
},
add: async function(key, data){
var filePath = path.join(this.dirs.files, key + "." + this.fileExtFromKey[key])
fs.writeFileSync(filePath, data);
add: async function(key){
// true as second argument expects attachment file content
var response = await this.callAPI("/items/" + key + "/file", true);
var info = await this.getRealBufferAndExt(response.body);
var filePath = path.join(this.cfg.dirs.files, `${key}.${info.fileInfo.ext}`)
fs.writeFileSync(filePath, info.buf);
}
}
}
Expand Down
Loading

0 comments on commit e49683b

Please sign in to comment.