syncthing-hooks/api.js

23 lines
536 B
JavaScript
Raw Normal View History

2020-03-17 22:11:02 +01:00
const got = require('got');
2021-04-18 01:41:41 +02:00
const { getEnvVar } = require('./env.js');
2020-03-17 22:11:02 +01:00
const fetchEvents = () =>
2021-04-18 01:42:48 +02:00
got(getEnvVar('ST_URL','http://localhost:8384/rest/events'), {
2020-03-17 22:11:02 +01:00
headers: {
2021-04-18 01:41:41 +02:00
'X-API-Key': getEnvVar('API_KEY','invalid')
2020-03-17 22:11:02 +01:00
},
}).json();
const fetchNewEvents = async seenIds => {
const events = await fetchEvents();
const newEvents = events.filter(event => seenIds && !seenIds.has(event.id));
return {
events: newEvents,
seenIds: new Set(events.map(x => x.id)),
};
};
module.exports = {
fetchNewEvents,
};