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