-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
65 lines (53 loc) · 2.07 KB
/
app.js
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var searchZamunda = require("./SearchZamunda.js");
//var rss = require('node-rss');
var rss = require('rss');
var express = require('express')
var app = express()
app.get('/', function (req, res) {
console.log("request start");
var searchString = req.query.searchString;
if (searchString) {
searchZamunda(searchString)
.then(function (searchResults) {
/*
var feed = rss.createNewFeed('Search Zamunda for "' + searchString + '"',
'http://zamunda.net/',
'Search zamunda for torrents',
'AntSoft',
'http://someurl.com/rss/MostRecent.xml',
{ 'CustomTag': 'This is a custom tag under the channel tag!' });
*/
var feed = new rss({
title: 'Search Zamunda for "' + searchString + '"',
description: "Search zamunda for torrents"
});
var blogs = searchResults.map(function (value, index) {
return {
title: value.name,
url: value.downloadLink,
date: value.dateAdded.toUTCString(),
description: value.name + " " + value.cat
};
});
blogs.forEach(function (blog) {
feed.item(blog);
});
var xmlString = feed.xml({indent: true});
res.send(xmlString);
console.log("request end");
})
.catch(function (e) {
res.status(500).send(e.message + e.stack);
console.error("request end with error: " + e.message + e.stack);
});
}
else {
res.send("need request param: seachString!");
console.log("request end");
}
})
var server = app.listen(3000, function () {
var host = server.address().address
var port = server.address().port
console.log('Example app listening at http://%s:%s', host, port)
})