Add somes tests about lastEntriesLink field and patch an error about lastEntriesLink's typing

This commit is contained in:
2021-03-23 18:10:57 +01:00
parent ce1d8f4ab6
commit df3f2a3049
3 changed files with 152 additions and 69 deletions

View File

@ -2,5 +2,5 @@ export interface ListenerRSSInfos {
readonly address: string; // feed's address
readonly timeloop?: number; // update time RSS feed
readonly customfields?: { [key: string]: string | string[] }; // rss fields custom
readonly lastEntriesLinks?: [string]; // links from lastentries
readonly lastEntriesLinks?: string[]; // links from lastentries
}

View File

@ -66,25 +66,27 @@ export class ListenerRss extends EventEmitter {
start(): void {
this.loopRunning = true;
const fun: () => void = () => {
this.fetchRSS()
.then((obj: { [key: string]: any }) => {
this.emit("update", obj);
const updatedEntriesLinks = obj.items.map(
(item: { link: string }) => item.link
);
const fun: () => void = async () => {
await Promise.resolve(
this.fetchRSS()
.then((obj: { [key: string]: any }) => {
this.emit("update", obj);
const updatedEntriesLinks = obj.items.map(
(item: { link: string }) => item.link
);
const newEntries = obj.items.filter(
(item: { link: string }) =>
!this.lastEntriesLinks.includes(item.link)
);
const newEntries = obj.items.filter(
(item: { link: string }) =>
!this.lastEntriesLinks.includes(item.link)
);
if (newEntries.length !== 0) {
this.emit("newEntries", newEntries);
}
this.lastEntriesLinks = updatedEntriesLinks;
})
.catch((err) => this.emit("error", err));
if (newEntries.length !== 0) {
this.emit("newEntries", newEntries);
}
this.lastEntriesLinks = updatedEntriesLinks;
})
.catch((err) => this.emit("error", err))
);
};
(async () => {