-
Notifications
You must be signed in to change notification settings - Fork 1
/
torrents.js
31 lines (30 loc) · 1.04 KB
/
torrents.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
const send = require("@polka/send-type");
const TorrentSearchApi = require("torrent-search-api");
const headers = require("./headers").json;
const status = require("./status.js");
const warning = require("./warning").notorrents;
module.exports = async function torrents(req, res) {
try {
let json = JSON.stringify(req.body);
let {query = "1080p", category = "All", limit = 1} = JSON.parse(json);
// console.log(
// `{ "query": "${query}", "category": "${category}", "limit": ${limit}`
// );
let torrents = await TorrentSearchApi.search(query, category, limit);
//console.log('torrents: ', torrents);
send(res, status.success, torrents);
/*
const filtered = torrents.filter(
(x) => parseInt(x?.peers) >= 1 && parseInt(x?.seeds) >= 1
);
*/
/*if (!torrents || !torrents.length) {
send(res, status.empty, warning);
} else {
send(res, status.success, torrents, headers);
}*/
//return Promise.resolve(torrents);
} catch (err) {
send(res, status.fail, warning);
}
};