diff --git a/joplin.js b/joplin.js index 9b2aa95..5a6581b 100644 --- a/joplin.js +++ b/joplin.js @@ -5,9 +5,8 @@ let url = new URL("http://localhost:" + process.env.JOPLIN_CLIPPER_PORT + "/note url.searchParams.append("token", process.env.JOPLIN_TOKEN) -async function getNotes(notebookID) { +async function getNoteMetadataFromNotebook(notebookID) { let foldersURL = new URL("http://localhost:" + process.env.JOPLIN_CLIPPER_PORT + "/folders/" + process.env.JOPLIN_NOTEBOOK_ID + "/notes") - foldersURL.searchParams.append("token", process.env.JOPLIN_TOKEN) const res = await fetch(foldersURL.href) @@ -16,18 +15,35 @@ async function getNotes(notebookID) { return data } -async function getNoteData(noteID) { +async function getNote(noteID) { let noteURL = new URL("http://localhost:" + process.env.JOPLIN_CLIPPER_PORT + "/notes/" + noteID) + noteURL.searchParams.append("token", process.env.JOPLIN_TOKEN) + noteURL.searchParams.append("fields", "id,title,body") + console.log(noteURL.href) const res = await fetch(noteURL.href) - const data = await res.json() + const note = await res.json() - return data + return note } -getNotes() +getNoteMetadataFromNotebook() .then(res => { - res.items.forEach(element => { - console.log(element.id) + let noteIDs = [] + res.items.forEach(note => { + noteIDs.push(note.id) }); + return noteIDs + }) + .then(async noteIDs => { + let notes = [] + for (let i = 0; i < noteIDs.length; i++) { + const note = await getNote(noteIDs[i]) + notes.push(note) + } + + return notes + }) + .then(notes => { + notes.forEach(note => console.log(note.body)) }) \ No newline at end of file