-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
45 lines (38 loc) · 1.26 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const request = require('request');
require('dotenv').config();
const API_TOKEN = process.env.joplin_key;
const API_BASE_URL = process.env.joplin_url;
function searchNotes() {
return new Promise((resolve, reject) => {
const options = {
url: `${API_BASE_URL}/search?token=${API_TOKEN}&limit=10&query=${process.argv[2]}`,
json: true,
headers: {
'User-Agent': 'Chrome', // Set the custom User-Agent header here
},
};
request.get(options, (error, response, body) => {
if (error) {
reject(error);
} else if (response.statusCode !== 200) {
reject(new Error(`Request failed with status code ${response.statusCode}`));
} else {
resolve(body.items);
}
});
});
}
searchNotes()
.then((notes) => {
console.log(JSON.stringify({ "items" : notes.map((note) => ({
title: note.title,
subtitle: `Open note ...`,
valid: true,
arg: `[${note.title}](joplin://x-callback-url/openNote?id=${note.id})`, // Pass the note ID as an argument for Alfred to use later
icon: {path: "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertCautionIcon.icns"}
}))}));
//process.exit(0)
})
.catch((err) => {
console.error('Error:', err.message);
});