Add somes tests about lastEntriesLink field and patch an error about lastEntriesLink's typing
This commit is contained in:
@ -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
|
||||
}
|
||||
|
@ -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 () => {
|
||||
|
Reference in New Issue
Block a user