all-debrid-api 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/AllDebridClient.js +55 -78
- package/package.json +2 -2
package/lib/AllDebridClient.js
CHANGED
|
@@ -1,37 +1,35 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const fs = require('fs')
|
|
4
|
-
const
|
|
4
|
+
const axios = require('axios')
|
|
5
5
|
|
|
6
6
|
class AllDebridClient {
|
|
7
7
|
|
|
8
8
|
constructor (token, defaultOptions = {}) {
|
|
9
|
-
|
|
10
9
|
this.token = token
|
|
10
|
+
this.ip = defaultOptions.ip
|
|
11
11
|
this.base_agent = defaultOptions.base_agent || 'node-all-debrid'
|
|
12
|
-
this.base_url = defaultOptions.base_url || 'https://api.alldebrid.com
|
|
12
|
+
this.base_url = defaultOptions.base_url || 'https://api.alldebrid.com'
|
|
13
13
|
this.defaultOptions = defaultOptions
|
|
14
|
+
delete this.defaultOptions.ip
|
|
14
15
|
delete this.defaultOptions.base_agent
|
|
15
16
|
delete this.defaultOptions.base_url
|
|
16
17
|
this._initMethods()
|
|
17
|
-
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
_readFile (path) {
|
|
21
|
-
|
|
22
21
|
return fs.createReadStream(path)
|
|
23
|
-
|
|
24
22
|
}
|
|
25
23
|
|
|
26
24
|
_request (endpoint, o = {}) {
|
|
27
|
-
|
|
28
25
|
const url = this.base_url + endpoint
|
|
29
26
|
|
|
30
|
-
const options =
|
|
27
|
+
const options = { ...this.defaultOptions }
|
|
31
28
|
options.url = url
|
|
32
29
|
options.json = true
|
|
33
|
-
options.
|
|
34
|
-
options.
|
|
30
|
+
options.params = o.params || {}
|
|
31
|
+
options.params.ip = this.ip
|
|
32
|
+
options.params.agent = this.base_agent
|
|
35
33
|
options.headers = options.headers || {}
|
|
36
34
|
options.headers['Authorization'] = 'Bearer ' + this.token
|
|
37
35
|
|
|
@@ -39,29 +37,9 @@ class AllDebridClient {
|
|
|
39
37
|
options[i] = o[i]
|
|
40
38
|
}
|
|
41
39
|
|
|
42
|
-
return
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (error) {
|
|
46
|
-
reject(error)
|
|
47
|
-
} else {
|
|
48
|
-
if (typeof body !== 'undefined') {
|
|
49
|
-
if (options.binary) body = JSON.parse(body)
|
|
50
|
-
if (body.status === 'error') {
|
|
51
|
-
reject(body.error)
|
|
52
|
-
} else {
|
|
53
|
-
resolve(body)
|
|
54
|
-
}
|
|
55
|
-
} else if (response.statusCode === 200) {
|
|
56
|
-
resolve()
|
|
57
|
-
} else {
|
|
58
|
-
reject()
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
})
|
|
64
|
-
|
|
40
|
+
return axios.request(options)
|
|
41
|
+
.then(response => response.data)
|
|
42
|
+
.catch(error => Promise.reject(error?.response?.data || error))
|
|
65
43
|
}
|
|
66
44
|
|
|
67
45
|
_get (endpoint, options = {}) {
|
|
@@ -77,11 +55,11 @@ class AllDebridClient {
|
|
|
77
55
|
_initMethods () {
|
|
78
56
|
this.pin = {
|
|
79
57
|
get: () => {
|
|
80
|
-
return this._get('pin/get')
|
|
58
|
+
return this._get('/v4.1/pin/get')
|
|
81
59
|
},
|
|
82
60
|
check: (check, pin) => {
|
|
83
|
-
return this._get('pin/check', {
|
|
84
|
-
|
|
61
|
+
return this._get('/v4/pin/check', {
|
|
62
|
+
params: {
|
|
85
63
|
check,
|
|
86
64
|
pin
|
|
87
65
|
}
|
|
@@ -91,94 +69,94 @@ class AllDebridClient {
|
|
|
91
69
|
|
|
92
70
|
this.hosts = {
|
|
93
71
|
supported: (hostsOnly = null) => {
|
|
94
|
-
return this._get('hosts', {
|
|
95
|
-
|
|
72
|
+
return this._get('/v4/hosts', {
|
|
73
|
+
params: {
|
|
96
74
|
hostsOnly
|
|
97
75
|
}
|
|
98
76
|
})
|
|
99
77
|
},
|
|
100
78
|
domains: () => {
|
|
101
|
-
return this._get('hosts/domains')
|
|
79
|
+
return this._get('/v4/hosts/domains')
|
|
102
80
|
},
|
|
103
81
|
regexp: () => {
|
|
104
|
-
return this._get('hosts/regexp')
|
|
82
|
+
return this._get('/v4/hosts/regexp')
|
|
105
83
|
},
|
|
106
84
|
priority: () => {
|
|
107
|
-
return this._get('hosts/priority')
|
|
85
|
+
return this._get('/v4/hosts/priority')
|
|
108
86
|
},
|
|
109
87
|
}
|
|
110
88
|
|
|
111
89
|
this.user = {
|
|
112
90
|
info: () => {
|
|
113
|
-
return this._get('user')
|
|
91
|
+
return this._get('/v4/user')
|
|
114
92
|
},
|
|
115
93
|
hosts: (hostsOnly = null) => {
|
|
116
|
-
return this._get('user/hosts', {
|
|
117
|
-
|
|
94
|
+
return this._get('/v4.1/user/hosts', {
|
|
95
|
+
params: {
|
|
118
96
|
hostsOnly
|
|
119
97
|
}
|
|
120
98
|
})
|
|
121
99
|
},
|
|
122
100
|
links: () => {
|
|
123
|
-
return this._get('user/links')
|
|
101
|
+
return this._get('/v4/user/links')
|
|
124
102
|
},
|
|
125
103
|
saveLink: (link) => {
|
|
126
|
-
return this._get('user/links/save', {
|
|
127
|
-
|
|
104
|
+
return this._get('/v4/user/links/save', {
|
|
105
|
+
params: {
|
|
128
106
|
link
|
|
129
107
|
}
|
|
130
108
|
})
|
|
131
109
|
},
|
|
132
110
|
deleteLink: (link) => {
|
|
133
|
-
return this._get('user/links/delete', {
|
|
134
|
-
|
|
111
|
+
return this._get('/v4/user/links/delete', {
|
|
112
|
+
params: {
|
|
135
113
|
link
|
|
136
114
|
}
|
|
137
115
|
})
|
|
138
116
|
},
|
|
139
117
|
recentLinks: () => {
|
|
140
|
-
return this._get('user/history')
|
|
118
|
+
return this._get('/v4/user/history')
|
|
141
119
|
},
|
|
142
120
|
purgeRecentLinks: () => {
|
|
143
|
-
return this._get('user/history/delete')
|
|
121
|
+
return this._get('/v4/user/history/delete')
|
|
144
122
|
}
|
|
145
123
|
}
|
|
146
124
|
|
|
147
125
|
this.link = {
|
|
148
126
|
infos: (link, password = null) => {
|
|
149
|
-
return this._get('link/infos', {
|
|
150
|
-
|
|
127
|
+
return this._get('/v4/link/infos', {
|
|
128
|
+
params: {
|
|
151
129
|
link,
|
|
152
130
|
password
|
|
153
131
|
}
|
|
154
132
|
})
|
|
155
133
|
},
|
|
156
134
|
redirector: (link) => {
|
|
157
|
-
return this._get('link/redirector', {
|
|
158
|
-
|
|
135
|
+
return this._get('/v4/link/redirector', {
|
|
136
|
+
params: {
|
|
159
137
|
link
|
|
160
138
|
}
|
|
161
139
|
})
|
|
162
140
|
},
|
|
163
141
|
unlock: (link, password = null) => {
|
|
164
|
-
return this._get('link/unlock', {
|
|
165
|
-
|
|
142
|
+
return this._get('/v4/link/unlock', {
|
|
143
|
+
params: {
|
|
166
144
|
link,
|
|
167
145
|
password
|
|
168
146
|
}
|
|
169
147
|
})
|
|
170
148
|
},
|
|
171
149
|
streaming: (id, stream) => {
|
|
172
|
-
return this._get('link/streaming', {
|
|
173
|
-
|
|
150
|
+
return this._get('/v4/link/streaming', {
|
|
151
|
+
params: {
|
|
174
152
|
id,
|
|
175
153
|
stream
|
|
176
154
|
}
|
|
177
155
|
})
|
|
178
156
|
},
|
|
179
157
|
delayed: (id) => {
|
|
180
|
-
return this._get('link/delayed', {
|
|
181
|
-
|
|
158
|
+
return this._get('/v4/link/delayed', {
|
|
159
|
+
params: {
|
|
182
160
|
id
|
|
183
161
|
}
|
|
184
162
|
})
|
|
@@ -187,48 +165,47 @@ class AllDebridClient {
|
|
|
187
165
|
|
|
188
166
|
this.magnet = {
|
|
189
167
|
upload: (magnets) => {
|
|
190
|
-
return this._post('magnet/upload', {
|
|
191
|
-
|
|
168
|
+
return this._post('/v4/magnet/upload', {
|
|
169
|
+
data: {
|
|
192
170
|
magnets
|
|
171
|
+
},
|
|
172
|
+
headers: {
|
|
173
|
+
'Content-Type': 'multipart/form-data'
|
|
193
174
|
}
|
|
194
175
|
})
|
|
195
176
|
},
|
|
196
177
|
uploadFile: (file) => {
|
|
197
178
|
const stream = (file.Readable) ? file : this._readFile(file)
|
|
198
|
-
return this._post('magnet/upload/file', {
|
|
199
|
-
|
|
179
|
+
return this._post('/v4/magnet/upload/file', {
|
|
180
|
+
data: {
|
|
200
181
|
files: [stream],
|
|
182
|
+
},
|
|
183
|
+
headers: {
|
|
184
|
+
'Content-Type': 'multipart/form-data'
|
|
201
185
|
}
|
|
202
186
|
})
|
|
203
187
|
},
|
|
204
188
|
status: (id) => {
|
|
205
|
-
return this._get('magnet/status', {
|
|
206
|
-
|
|
189
|
+
return this._get('/v4.1/magnet/status', {
|
|
190
|
+
params: {
|
|
207
191
|
id
|
|
208
192
|
}
|
|
209
193
|
})
|
|
210
194
|
},
|
|
211
195
|
delete: (id) => {
|
|
212
|
-
return this._get('magnet/delete', {
|
|
213
|
-
|
|
196
|
+
return this._get('/v4/magnet/delete', {
|
|
197
|
+
params: {
|
|
214
198
|
id
|
|
215
199
|
}
|
|
216
200
|
})
|
|
217
201
|
},
|
|
218
202
|
restart: (id) => {
|
|
219
|
-
return this._get('magnet/restart', {
|
|
220
|
-
|
|
203
|
+
return this._get('/v4/magnet/restart', {
|
|
204
|
+
params: {
|
|
221
205
|
id
|
|
222
206
|
}
|
|
223
207
|
})
|
|
224
208
|
},
|
|
225
|
-
instant: (magnets) => {
|
|
226
|
-
return this._post('magnet/instant', {
|
|
227
|
-
form: {
|
|
228
|
-
magnets
|
|
229
|
-
}
|
|
230
|
-
})
|
|
231
|
-
},
|
|
232
209
|
}
|
|
233
210
|
|
|
234
211
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "all-debrid-api",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Node AllDebrid API wrapper",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"directories": {
|
|
@@ -21,6 +21,6 @@
|
|
|
21
21
|
},
|
|
22
22
|
"homepage": "https://github.com/TheBeastLT/node-all-debrid#readme",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"
|
|
24
|
+
"axios": "^1.13.2"
|
|
25
25
|
}
|
|
26
26
|
}
|