-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
65 lines (57 loc) · 1.15 KB
/
index.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
const torrent = require('torrent-project-api')
const express = require('express')
const app = express()
app.get('/magnet', (req, res) => {
const keyword = req.query.q
if (!keyword) {
return res.send({
type: 'Error',
data: [{
code: 103,
message: 'need keyword'
}]
})
}
const options = {
limit: 1,
order: 'best'
}
torrent.search(keyword, options, (err, result) => {
if (err) {
return res.send({
type: 'Error',
data: [{
code: 102,
message: err.toString()
}]
})
}
if (result.total <= 0) {
return res.send({
type: 'Error',
data: [{
code: 404,
message: '没有找到相关磁力链接'
}]
})
}
torrent.magnet(result.torrents[0], (err, link) => {
if (err) {
return res.send({
type: 'Error',
data: [{
code: 102,
message: err.toString()
}]
})
}
return res.send({
type: 'Text',
data: [link]
})
})
})
})
app.listen(3000, () => {
console.log('listening on port 3000!')
})