-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeed.js
More file actions
39 lines (34 loc) · 848 Bytes
/
feed.js
File metadata and controls
39 lines (34 loc) · 848 Bytes
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
let Feed = function (name, route, providers) {
this._name = name;
this._route = route;
this._providers = providers;
};
const xmlEscapeMap = {
'&': '&',
'"': '"',
'<': '<',
'>': '>'
};
function encodeXml(string) {
return string.replace(/([\&"<>])/g, function(str, item) {
return xmlEscapeMap[item];
});
}
const dateSort = function (a, b ){
if (a.date > b.date) return -1;
if (a.date < b.date) return 1;
return 0;
};
Feed.prototype = {
getName: function () {
return this._name;
},
getRoute: function () {
return this._route;
},
get: function () {
const items = this._providers.reduce((accumulator, value) => {return value.getItems().concat(accumulator)}, []);
return items.map((i) => {i.torrent = encodeXml(i.torrent); return i;}).sort(dateSort);
}
};
module.exports = Feed;