feat(rss): cover atom feeds
This commit is contained in:
@@ -1,16 +1,34 @@
|
|||||||
import { IGlobalVariable } from '@automatisch/types';
|
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||||
import { XMLParser } from 'fast-xml-parser';
|
import { XMLParser } from 'fast-xml-parser';
|
||||||
|
import bcrypt from 'bcrypt';
|
||||||
|
|
||||||
|
const getInternalId = async (item: IJSONObject): Promise<string> => {
|
||||||
|
if (item.guid) {
|
||||||
|
return item.guid.toString();
|
||||||
|
} else if (item.id) {
|
||||||
|
return item.id.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return await hashItem(JSON.stringify(item));
|
||||||
|
};
|
||||||
|
|
||||||
|
const hashItem = async (value: string) => {
|
||||||
|
return await bcrypt.hash(value, 1);
|
||||||
|
};
|
||||||
|
|
||||||
const newItemsInFeed = async ($: IGlobalVariable) => {
|
const newItemsInFeed = async ($: IGlobalVariable) => {
|
||||||
const { data } = await $.http.get($.step.parameters.feedUrl as string);
|
const { data } = await $.http.get($.step.parameters.feedUrl as string);
|
||||||
const parser = new XMLParser();
|
const parser = new XMLParser();
|
||||||
const parsedData = parser.parse(data);
|
const parsedData = parser.parse(data);
|
||||||
|
|
||||||
for (const item of parsedData.rss.channel.item) {
|
// naive implementation to cover atom and rss feeds
|
||||||
|
const items = parsedData.rss?.channel?.item || parsedData.feed?.entry || [];
|
||||||
|
|
||||||
|
for (const item of items) {
|
||||||
const dataItem = {
|
const dataItem = {
|
||||||
raw: item,
|
raw: item,
|
||||||
meta: {
|
meta: {
|
||||||
internalId: item.guid,
|
internalId: await getInternalId(item),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user