Now getting note data for each note

This commit is contained in:
Ian Cooperman 2022-08-02 12:25:08 -07:00
parent a4bfa7dd05
commit 2a6c968a99

View File

@ -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))
})