diff --git a/joplin.js b/joplin.js index ae2cae7..c1c5256 100644 --- a/joplin.js +++ b/joplin.js @@ -2,21 +2,40 @@ import fetch from 'node-fetch' import 'dotenv/config' -//This function gets notes from a specified notebook, using the notebook's ID. The fields parameter specifies which fields to include in the response. -// @param {string=} notebookID - The id of the notebook you want to get notes from, as extracted from the notebook's external link -// @param {Array[string]=} fields - The specific fields wanted in the returned response. Valid fields can be found in this table: https://joplinapp.org/api/references/rest_api/#properties -async function getNotesFromNotebook(notebookID, fields) { - const fieldsString = fields.join() +class Joplin { + constructor(joplinToken, joplinPort) { + this.token = joplinToken + this.port = joplinPort + console.log(this.port) - let foldersURL = new URL("http://localhost:" + process.env.JOPLIN_CLIPPER_PORT + "/folders/" + notebookID + "/notes") - foldersURL.searchParams.append("token", process.env.JOPLIN_TOKEN) - foldersURL.searchParams.append("fields", fieldsString) + this.getNotesFromNotebook.bind(this) + } - const res = await fetch(foldersURL.href) - const data = await res.json() + + //This function gets notes from a specified notebook, using the notebook's ID. The fields parameter specifies which fields to include in the response. + // @param {string=} notebookID - The id of the notebook you want to get notes from, as extracted from the notebook's external link + // @param {Array[string]=} fields - The specific fields wanted in the returned response. Valid fields can be found in this table: https://joplinapp.org/api/references/rest_api/#properties + async getNotesFromNotebook(notebookID, fields) { + const fieldsString = fields.join() + + let tempURL = "http://localhost:" + this.port + "/folders/" + notebookID + "/notes" + console.log(tempURL) + let foldersURL = new URL(tempURL) + foldersURL.searchParams.append("token", this.token) + foldersURL.searchParams.append("fields", fieldsString) - return data + const res = await fetch(foldersURL.href) + const data = await res.json() + + return data + } } -getNotesFromNotebook(process.env.JOPLIN_NOTEBOOK_ID, ["id", "title", "body", "created_time", "latitude", "longitude", "altitude", "is_todo", "todo_due", "todo_completed"]) + +let joplin = new Joplin(process.env.JOPLIN_TOKEN, process.env.JOPLIN_CLIPPER_PORT) + + + + +joplin.getNotesFromNotebook(process.env.JOPLIN_NOTEBOOK_ID, ["id", "title", "body", "created_time", "latitude", "longitude", "altitude", "is_todo", "todo_due", "todo_completed"]) .then(res => console.log(res)) \ No newline at end of file