syncthing-hooks/api.js
2021-04-18 01:41:41 +02:00

23 lines
516 B
JavaScript

const got = require('got');
const { getEnvVar } = require('./env.js');
const fetchEvents = () =>
got('http://localhost:8384/rest/events', {
headers: {
'X-API-Key': getEnvVar('API_KEY','invalid')
},
}).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,
};