File size: 1,070 Bytes
3206347 |
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 |
import { XMLParser } from 'fast-xml-parser';
import bcrypt from 'bcrypt';
const getInternalId = async (item) => {
if (item.guid) {
return typeof item.guid === 'object'
? item.guid['#text'].toString()
: item.guid.toString();
} else if (item.id) {
return typeof item.id === 'object'
? item.id['#text'].toString()
: item.id.toString();
}
return await hashItem(JSON.stringify(item));
};
const hashItem = async (value) => {
return await bcrypt.hash(value, 1);
};
const newItemsInFeed = async ($) => {
const { data } = await $.http.get($.step.parameters.feedUrl);
const parser = new XMLParser({
ignoreAttributes: false,
});
const parsedData = parser.parse(data);
// naive implementation to cover atom and rss feeds
const items = parsedData.rss?.channel?.item || parsedData.feed?.entry || [];
for (const item of items) {
const dataItem = {
raw: item,
meta: {
internalId: await getInternalId(item),
},
};
$.pushTriggerItem(dataItem);
}
};
export default newItemsInFeed;
|