@chahakshah/terabox-api 2.6.7 → 2.6.8
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/api.js +451 -451
- package/package.json +1 -1
package/api.js
CHANGED
|
@@ -19,7 +19,7 @@ import tls from 'node:tls';
|
|
|
19
19
|
* makeRemoteFPath('documents/', 'file.txt') // returns 'documents/file.txt'
|
|
20
20
|
* @ignore
|
|
21
21
|
*/
|
|
22
|
-
function makeRemoteFPath(sdir, sfile){
|
|
22
|
+
function makeRemoteFPath(sdir, sfile) {
|
|
23
23
|
const tdir = sdir.match(/\/$/) ? sdir : sdir + '/';
|
|
24
24
|
return tdir + sfile;
|
|
25
25
|
}
|
|
@@ -38,7 +38,7 @@ class FormUrlEncoded {
|
|
|
38
38
|
*/
|
|
39
39
|
constructor(params) {
|
|
40
40
|
this.data = new URLSearchParams();
|
|
41
|
-
if(typeof params === 'object' && params !== null){
|
|
41
|
+
if (typeof params === 'object' && params !== null) {
|
|
42
42
|
for (const [key, value] of Object.entries(params)) {
|
|
43
43
|
this.data.append(key, value);
|
|
44
44
|
}
|
|
@@ -50,7 +50,7 @@ class FormUrlEncoded {
|
|
|
50
50
|
* @param {string} value - The parameter value
|
|
51
51
|
* @returns {void}
|
|
52
52
|
*/
|
|
53
|
-
set(param, value){
|
|
53
|
+
set(param, value) {
|
|
54
54
|
this.data.set(param, value);
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
@@ -59,7 +59,7 @@ class FormUrlEncoded {
|
|
|
59
59
|
* @param {string} value - The parameter value
|
|
60
60
|
* @returns {void}
|
|
61
61
|
*/
|
|
62
|
-
append(param, value){
|
|
62
|
+
append(param, value) {
|
|
63
63
|
this.data.append(param, value);
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
@@ -67,7 +67,7 @@ class FormUrlEncoded {
|
|
|
67
67
|
* @param {string} param - The parameter name to remove
|
|
68
68
|
* @returns {void}
|
|
69
69
|
*/
|
|
70
|
-
delete(param){
|
|
70
|
+
delete(param) {
|
|
71
71
|
this.data.delete(param);
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
@@ -77,14 +77,14 @@ class FormUrlEncoded {
|
|
|
77
77
|
* @example
|
|
78
78
|
* form.str(); // returns "foo=bar&baz=qux"
|
|
79
79
|
*/
|
|
80
|
-
str(){
|
|
80
|
+
str() {
|
|
81
81
|
return this.data.toString().replace(/\+/g, '%20');
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
84
84
|
* Returns the underlying URLSearchParams object
|
|
85
85
|
* @returns {URLSearchParams} The native URLSearchParams instance
|
|
86
86
|
*/
|
|
87
|
-
url(){
|
|
87
|
+
url() {
|
|
88
88
|
return this.data;
|
|
89
89
|
}
|
|
90
90
|
}
|
|
@@ -110,21 +110,21 @@ function signDownload(s1, s2) {
|
|
|
110
110
|
const p = new Uint8Array(256);
|
|
111
111
|
const a = new Uint8Array(256);
|
|
112
112
|
const result = [];
|
|
113
|
-
|
|
113
|
+
|
|
114
114
|
// Key-scheduling algorithm (KSA)
|
|
115
115
|
// Initialize the permutation array with the secret key
|
|
116
116
|
Array.from({ length: 256 }, (_, i) => {
|
|
117
117
|
a[i] = s1.charCodeAt(i % s1.length);
|
|
118
118
|
p[i] = i;
|
|
119
119
|
});
|
|
120
|
-
|
|
120
|
+
|
|
121
121
|
// Scramble the permutation array using the key
|
|
122
122
|
let j = 0;
|
|
123
123
|
Array.from({ length: 256 }, (_, i) => {
|
|
124
124
|
j = (j + p[i] + a[i]) % 256;
|
|
125
125
|
[p[i], p[j]] = [p[j], p[i]]; // swap
|
|
126
126
|
});
|
|
127
|
-
|
|
127
|
+
|
|
128
128
|
// Pseudo-random generation algorithm (PRGA)
|
|
129
129
|
// Generate keystream and XOR with input data
|
|
130
130
|
let i = 0; j = 0;
|
|
@@ -135,7 +135,7 @@ function signDownload(s1, s2) {
|
|
|
135
135
|
const k = p[(p[i] + p[j]) % 256];
|
|
136
136
|
result.push(s2.charCodeAt(q) ^ k);
|
|
137
137
|
});
|
|
138
|
-
|
|
138
|
+
|
|
139
139
|
// Return the result as Base64
|
|
140
140
|
return Buffer.from(result).toString('base64');
|
|
141
141
|
}
|
|
@@ -158,8 +158,8 @@ function signDownload(s1, s2) {
|
|
|
158
158
|
* checkMd5val('z41d8cd98f00b204e9800998ecf8427e') // returns false (invalid character)
|
|
159
159
|
* checkMd5val('d41d8cd98f') // returns false (too short)
|
|
160
160
|
*/
|
|
161
|
-
function checkMd5val(md5){
|
|
162
|
-
if(typeof md5 !== 'string') return false;
|
|
161
|
+
function checkMd5val(md5) {
|
|
162
|
+
if (typeof md5 !== 'string') return false;
|
|
163
163
|
return /^[a-f0-9]{32}$/.test(md5);
|
|
164
164
|
}
|
|
165
165
|
|
|
@@ -210,25 +210,25 @@ function checkMd5arr(arr) {
|
|
|
210
210
|
function decodeMd5(md5) {
|
|
211
211
|
// Return unchanged if not 32 characters
|
|
212
212
|
if (md5.length !== 32) return md5;
|
|
213
|
-
|
|
213
|
+
|
|
214
214
|
// Restore character at position 9
|
|
215
215
|
const restoredHexChar = (md5.charCodeAt(9) - 'g'.charCodeAt(0)).toString(16);
|
|
216
216
|
const o = md5.slice(0, 9) + restoredHexChar + md5.slice(10);
|
|
217
|
-
|
|
217
|
+
|
|
218
218
|
// Apply XOR transformation to each character
|
|
219
219
|
let n = '';
|
|
220
220
|
for (let i = 0; i < o.length; i++) {
|
|
221
221
|
const orig = parseInt(o[i], 16) ^ (i & 15);
|
|
222
222
|
n += orig.toString(16);
|
|
223
223
|
}
|
|
224
|
-
|
|
224
|
+
|
|
225
225
|
// Reorder the bytes in the result
|
|
226
226
|
const e =
|
|
227
227
|
n.slice(8, 16) + // original bytes 8-15 (now first)
|
|
228
228
|
n.slice(0, 8) + // original bytes 0-7 (now second)
|
|
229
229
|
n.slice(24, 32) + // original bytes 24-31 (now third)
|
|
230
230
|
n.slice(16, 24); // original bytes 16-23 (now last)
|
|
231
|
-
|
|
231
|
+
|
|
232
232
|
return e;
|
|
233
233
|
}
|
|
234
234
|
|
|
@@ -258,7 +258,7 @@ function decodeMd5(md5) {
|
|
|
258
258
|
function changeBase64Type(str, mode = 1) {
|
|
259
259
|
return mode === 1
|
|
260
260
|
? str.replace(/\+/g, '-').replace(/\//g, '_') // to url-safe
|
|
261
|
-
: str.replace(/-/g,
|
|
261
|
+
: str.replace(/-/g, '+').replace(/_/g, '/'); // to standard
|
|
262
262
|
}
|
|
263
263
|
|
|
264
264
|
/**
|
|
@@ -290,19 +290,19 @@ function decryptAES(pp1, pp2) {
|
|
|
290
290
|
// Convert from URL-safe Base64 to standard Base64
|
|
291
291
|
pp1 = changeBase64Type(pp1, 2);
|
|
292
292
|
pp2 = changeBase64Type(pp2, 2);
|
|
293
|
-
|
|
293
|
+
|
|
294
294
|
// Extract ciphertext (after first 16 bytes) and IV (first 16 bytes)
|
|
295
295
|
const cipherText = pp1.substring(16);
|
|
296
296
|
const key = Buffer.from(pp2, 'utf8');
|
|
297
297
|
const iv = Buffer.from(pp1.substring(0, 16), 'utf8');
|
|
298
|
-
|
|
298
|
+
|
|
299
299
|
// Create decipher with AES-128-CBC algorithm
|
|
300
300
|
const decipher = crypto.createDecipheriv('aes-128-cbc', key, iv);
|
|
301
|
-
|
|
301
|
+
|
|
302
302
|
// Perform decryption
|
|
303
303
|
let decrypted = decipher.update(cipherText, 'base64', 'utf8');
|
|
304
304
|
decrypted += decipher.final('utf8');
|
|
305
|
-
|
|
305
|
+
|
|
306
306
|
return decrypted;
|
|
307
307
|
}
|
|
308
308
|
|
|
@@ -334,18 +334,18 @@ function encryptRSA(message, publicKeyPEM, mode = 1) {
|
|
|
334
334
|
// Mode 2: Apply MD5 hash and length padding
|
|
335
335
|
if (mode === 2) {
|
|
336
336
|
const md5 = crypto.createHash('md5').update(message).digest('hex');
|
|
337
|
-
message = md5 + (md5.length<10?'0':'') + md5.length;
|
|
337
|
+
message = md5 + (md5.length < 10 ? '0' : '') + md5.length;
|
|
338
338
|
}
|
|
339
|
-
|
|
339
|
+
|
|
340
340
|
// Convert message to Buffer
|
|
341
341
|
const buffer = Buffer.from(message, 'utf8');
|
|
342
|
-
|
|
342
|
+
|
|
343
343
|
// Perform RSA encryption
|
|
344
344
|
const encrypted = crypto.publicEncrypt({
|
|
345
345
|
key: publicKeyPEM,
|
|
346
346
|
padding: crypto.constants.RSA_PKCS1_PADDING,
|
|
347
347
|
}, buffer);
|
|
348
|
-
|
|
348
|
+
|
|
349
349
|
// Return as Base64 string
|
|
350
350
|
return encrypted.toString('base64');
|
|
351
351
|
}
|
|
@@ -376,7 +376,7 @@ function encryptRSA(message, publicKeyPEM, mode = 1) {
|
|
|
376
376
|
function prandGen(client = 'web', seval, encpwd, email, browserid = '', random) {
|
|
377
377
|
// Combine all parameters with hyphens
|
|
378
378
|
const combined = `${client}-${seval}-${encpwd}-${email}-${browserid}-${random}`;
|
|
379
|
-
|
|
379
|
+
|
|
380
380
|
// Generate SHA-1 hash and return as hex string
|
|
381
381
|
return crypto.createHash('sha1').update(combined).digest('hex');
|
|
382
382
|
}
|
|
@@ -418,17 +418,17 @@ class TeraBoxApp {
|
|
|
418
418
|
CheckMd5Val = checkMd5val;
|
|
419
419
|
CheckMd5Arr = checkMd5arr;
|
|
420
420
|
DecodeMd5 = decodeMd5;
|
|
421
|
-
|
|
421
|
+
|
|
422
422
|
// Encryption/Utility Methods 2
|
|
423
423
|
ChangeBase64Type = changeBase64Type;
|
|
424
424
|
DecryptAES = decryptAES;
|
|
425
425
|
EncryptRSA = encryptRSA;
|
|
426
426
|
PRandGen = prandGen;
|
|
427
|
-
|
|
427
|
+
|
|
428
428
|
// Constants
|
|
429
429
|
TERABOX_DOMAIN = 'terabox.com';
|
|
430
|
-
TERABOX_TIMEOUT =
|
|
431
|
-
|
|
430
|
+
TERABOX_TIMEOUT = 10000;
|
|
431
|
+
|
|
432
432
|
// app data
|
|
433
433
|
data = {
|
|
434
434
|
csrf: '',
|
|
@@ -438,7 +438,7 @@ class TeraBoxApp {
|
|
|
438
438
|
jsToken: '',
|
|
439
439
|
pubkey: '',
|
|
440
440
|
};
|
|
441
|
-
|
|
441
|
+
|
|
442
442
|
// Application parameters and configuration
|
|
443
443
|
params = {
|
|
444
444
|
whost: 'https://www.' + this.TERABOX_DOMAIN,
|
|
@@ -463,7 +463,7 @@ class TeraBoxApp {
|
|
|
463
463
|
space_available: Math.pow(1024, 3),
|
|
464
464
|
cursor: 'null',
|
|
465
465
|
};
|
|
466
|
-
|
|
466
|
+
|
|
467
467
|
/**
|
|
468
468
|
* Creates a new TeraBoxApp instance
|
|
469
469
|
* @param {string} authData - Authentication data (NDUS token)
|
|
@@ -472,14 +472,14 @@ class TeraBoxApp {
|
|
|
472
472
|
*/
|
|
473
473
|
constructor(authData, authType = 'ndus') {
|
|
474
474
|
this.params.cookie = `lang=${this.params.lang}`;
|
|
475
|
-
if(authType === 'ndus'){
|
|
475
|
+
if (authType === 'ndus') {
|
|
476
476
|
this.params.cookie += authData ? '; ndus=' + authData : '';
|
|
477
477
|
}
|
|
478
|
-
else{
|
|
478
|
+
else {
|
|
479
479
|
throw new Error('initTBApp', { cause: 'AuthType Not Supported!' });
|
|
480
480
|
}
|
|
481
481
|
}
|
|
482
|
-
|
|
482
|
+
|
|
483
483
|
/**
|
|
484
484
|
* Updates application data including tokens and user information
|
|
485
485
|
* @param {string} [customPath] - Custom path to use for the update request
|
|
@@ -488,24 +488,24 @@ class TeraBoxApp {
|
|
|
488
488
|
* @async
|
|
489
489
|
* @throws {Error} Throws error if request fails or parsing fails
|
|
490
490
|
*/
|
|
491
|
-
async updateAppData(customPath, retries = 4){
|
|
491
|
+
async updateAppData(customPath, retries = 4) {
|
|
492
492
|
const url = new URL(this.params.whost + (customPath ? `/${customPath}` : '/main'));
|
|
493
|
-
|
|
494
|
-
try{
|
|
493
|
+
|
|
494
|
+
try {
|
|
495
495
|
const req = await request(url, {
|
|
496
|
-
headers:{
|
|
496
|
+
headers: {
|
|
497
497
|
'User-Agent': this.params.ua,
|
|
498
498
|
'Cookie': this.params.cookie,
|
|
499
499
|
},
|
|
500
500
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT + 10000),
|
|
501
501
|
});
|
|
502
|
-
|
|
503
|
-
if(req.statusCode === 302){
|
|
504
|
-
if(req.headers.location === '/login'){
|
|
502
|
+
|
|
503
|
+
if (req.statusCode === 302) {
|
|
504
|
+
if (req.headers.location === '/login') {
|
|
505
505
|
req.headers.location = this.params.whost + '/login';
|
|
506
506
|
}
|
|
507
507
|
const newUrl = new URL(req.headers.location);
|
|
508
|
-
if(this.params.whost !== newUrl.origin){
|
|
508
|
+
if (this.params.whost !== newUrl.origin) {
|
|
509
509
|
this.params.whost = newUrl.origin;
|
|
510
510
|
console.warn(`[WARN] Default hostname changed to ${newUrl.origin}`);
|
|
511
511
|
}
|
|
@@ -513,59 +513,59 @@ class TeraBoxApp {
|
|
|
513
513
|
const finalUrl = toPathname + newUrl.search;
|
|
514
514
|
return await this.updateAppData(finalUrl, retries);
|
|
515
515
|
}
|
|
516
|
-
|
|
517
|
-
if(req.headers['set-cookie']){
|
|
516
|
+
|
|
517
|
+
if (req.headers['set-cookie']) {
|
|
518
518
|
const cJar = new CookieJar();
|
|
519
519
|
this.params.cookie.split(';').map(cookie => cJar.setCookieSync(cookie, this.params.whost));
|
|
520
|
-
if(typeof req.headers['set-cookie'] === 'string'){
|
|
520
|
+
if (typeof req.headers['set-cookie'] === 'string') {
|
|
521
521
|
req.headers['set-cookie'] = [req.headers['set-cookie']];
|
|
522
522
|
}
|
|
523
|
-
for(const cookie of req.headers['set-cookie']){
|
|
523
|
+
for (const cookie of req.headers['set-cookie']) {
|
|
524
524
|
cJar.setCookieSync(cookie.split('; ')[0], this.params.whost);
|
|
525
525
|
}
|
|
526
526
|
this.params.cookie = cJar.getCookiesSync(this.params.whost).map(cookie => cookie.cookieString()).join('; ');
|
|
527
527
|
}
|
|
528
|
-
|
|
528
|
+
|
|
529
529
|
const rdata = await req.body.text();
|
|
530
530
|
const tdataRegex = /<script>var templateData = (.*);<\/script>/;
|
|
531
531
|
const jsTokenRegex = /window.jsToken%20%3D%20a%7D%3Bfn%28%22(.*)%22%29/;
|
|
532
532
|
const tdata = rdata.match(tdataRegex) ? JSON.parse(rdata.match(tdataRegex)[1].split(';</script>')[0]) : {};
|
|
533
533
|
const isLoginReq = req.headers.location === '/login' ? true : false;
|
|
534
|
-
|
|
535
|
-
if(tdata.jsToken){
|
|
534
|
+
|
|
535
|
+
if (tdata.jsToken) {
|
|
536
536
|
tdata.jsToken = tdata.jsToken.match(/%28%22(.*)%22%29/)[1];
|
|
537
537
|
}
|
|
538
|
-
else if(rdata.match(jsTokenRegex)){
|
|
538
|
+
else if (rdata.match(jsTokenRegex)) {
|
|
539
539
|
tdata.jsToken = rdata.match(jsTokenRegex)[1];
|
|
540
540
|
}
|
|
541
|
-
else if(isLoginReq){
|
|
541
|
+
else if (isLoginReq) {
|
|
542
542
|
console.error('[ERROR] Failed to update jsToken [Login Required]');
|
|
543
543
|
}
|
|
544
|
-
|
|
545
|
-
if(req.headers.logid){
|
|
544
|
+
|
|
545
|
+
if (req.headers.logid) {
|
|
546
546
|
this.data.logid = req.headers.logid;
|
|
547
547
|
}
|
|
548
|
-
|
|
548
|
+
|
|
549
549
|
this.data.csrf = tdata.csrf || '';
|
|
550
550
|
this.data.pcftoken = tdata.pcftoken || '';
|
|
551
551
|
this.data.bdstoken = tdata.bdstoken || '';
|
|
552
552
|
this.data.jsToken = tdata.jsToken || '';
|
|
553
|
-
|
|
553
|
+
|
|
554
554
|
this.params.account_id = parseInt(tdata.uk) || 0;
|
|
555
|
-
if(typeof tdata.userVipIdentity === 'number' && tdata.userVipIdentity > 0){
|
|
555
|
+
if (typeof tdata.userVipIdentity === 'number' && tdata.userVipIdentity > 0) {
|
|
556
556
|
this.params.is_vip = true;
|
|
557
557
|
this.params.vip_type = 1;
|
|
558
558
|
}
|
|
559
|
-
|
|
559
|
+
|
|
560
560
|
return tdata;
|
|
561
561
|
}
|
|
562
|
-
catch(error){
|
|
563
|
-
if(error.name === 'TimeoutError' && retries > 0){
|
|
562
|
+
catch (error) {
|
|
563
|
+
if (error.name === 'TimeoutError' && retries > 0) {
|
|
564
564
|
await new Promise(resolve => setTimeout(resolve, 500));
|
|
565
565
|
return await this.updateAppData(customPath, retries - 1);
|
|
566
566
|
}
|
|
567
567
|
const errorPrefix = '[ERROR] Failed to update jsToken:';
|
|
568
|
-
if(error.name === 'TimeoutError'){
|
|
568
|
+
if (error.name === 'TimeoutError') {
|
|
569
569
|
console.error(errorPrefix, error.message);
|
|
570
570
|
return;
|
|
571
571
|
}
|
|
@@ -573,18 +573,18 @@ class TeraBoxApp {
|
|
|
573
573
|
console.error(errorPrefix, errorReturn);
|
|
574
574
|
}
|
|
575
575
|
}
|
|
576
|
-
|
|
576
|
+
|
|
577
577
|
/**
|
|
578
578
|
* Sets default VIP parameters
|
|
579
579
|
* @returns {void}
|
|
580
580
|
*/
|
|
581
|
-
setVipDefaults(){
|
|
581
|
+
setVipDefaults() {
|
|
582
582
|
this.params.is_vip = true;
|
|
583
583
|
this.params.vip_type = 1; // 1: VIP, 2: SVIP
|
|
584
584
|
this.params.space_total = Math.pow(1024, 3) * 2;
|
|
585
585
|
this.params.space_available = Math.pow(1024, 3) * 2;
|
|
586
586
|
}
|
|
587
|
-
|
|
587
|
+
|
|
588
588
|
/**
|
|
589
589
|
* Makes an API request with retry logic
|
|
590
590
|
* @param {string} req_url - The request URL (relative to whost)
|
|
@@ -594,23 +594,23 @@ class TeraBoxApp {
|
|
|
594
594
|
* @async
|
|
595
595
|
* @throws {Error} Throws error if all retries fail
|
|
596
596
|
*/
|
|
597
|
-
async doReq(req_url, req_options = {}, retries = 4){
|
|
597
|
+
async doReq(req_url, req_options = {}, retries = 4) {
|
|
598
598
|
const url = new URL(this.params.whost + req_url);
|
|
599
599
|
let reqm_options = structuredClone(req_options);
|
|
600
600
|
let req_headers = {};
|
|
601
|
-
|
|
602
|
-
if(reqm_options.headers){
|
|
601
|
+
|
|
602
|
+
if (reqm_options.headers) {
|
|
603
603
|
req_headers = reqm_options.headers;
|
|
604
604
|
delete reqm_options.headers;
|
|
605
605
|
}
|
|
606
|
-
|
|
606
|
+
|
|
607
607
|
const save_cookies = reqm_options.save_cookies;
|
|
608
608
|
delete reqm_options.save_cookies;
|
|
609
609
|
const silent_retry = reqm_options.silent_retry;
|
|
610
610
|
delete reqm_options.silent_retry;
|
|
611
611
|
const req_timeout = reqm_options.timeout ? reqm_options.timeout : this.TERABOX_TIMEOUT;
|
|
612
612
|
delete reqm_options.timeout;
|
|
613
|
-
|
|
613
|
+
|
|
614
614
|
try {
|
|
615
615
|
const options = {
|
|
616
616
|
headers: {
|
|
@@ -621,28 +621,28 @@ class TeraBoxApp {
|
|
|
621
621
|
...reqm_options,
|
|
622
622
|
signal: AbortSignal.timeout(req_timeout),
|
|
623
623
|
};
|
|
624
|
-
|
|
624
|
+
|
|
625
625
|
const req = await request(url, options);
|
|
626
|
-
|
|
627
|
-
if(save_cookies && req.headers['set-cookie']){
|
|
626
|
+
|
|
627
|
+
if (save_cookies && req.headers['set-cookie']) {
|
|
628
628
|
const cJar = new CookieJar();
|
|
629
629
|
this.params.cookie.split(';').map(cookie => cJar.setCookieSync(cookie, this.params.whost));
|
|
630
|
-
if(typeof req.headers['set-cookie'] === 'string'){
|
|
630
|
+
if (typeof req.headers['set-cookie'] === 'string') {
|
|
631
631
|
req.headers['set-cookie'] = [req.headers['set-cookie']];
|
|
632
632
|
}
|
|
633
|
-
for(const cookie of req.headers['set-cookie']){
|
|
633
|
+
for (const cookie of req.headers['set-cookie']) {
|
|
634
634
|
cJar.setCookieSync(cookie.split('; ')[0], this.params.whost);
|
|
635
635
|
}
|
|
636
636
|
this.params.cookie = cJar.getCookiesSync(this.params.whost).map(cookie => cookie.cookieString()).join('; ');
|
|
637
637
|
}
|
|
638
|
-
|
|
638
|
+
|
|
639
639
|
const rdata = await req.body.json();
|
|
640
640
|
return rdata;
|
|
641
641
|
}
|
|
642
|
-
catch(error){
|
|
642
|
+
catch (error) {
|
|
643
643
|
if (retries > 0) {
|
|
644
644
|
await new Promise(resolve => setTimeout(resolve, 500));
|
|
645
|
-
if(!silent_retry){
|
|
645
|
+
if (!silent_retry) {
|
|
646
646
|
console.error('[ERROR] DoReq:', req_url, '|', error.code, ':', error.message, '(retrying...)');
|
|
647
647
|
}
|
|
648
648
|
return await this.doReq(req_url, req_options, retries - 1);
|
|
@@ -650,14 +650,14 @@ class TeraBoxApp {
|
|
|
650
650
|
throw new Error('doReq', { cause: error });
|
|
651
651
|
}
|
|
652
652
|
}
|
|
653
|
-
|
|
653
|
+
|
|
654
654
|
/**
|
|
655
655
|
* Retrieves system configuration from the TeraBox API
|
|
656
656
|
* @returns {Promise<Object>} The system configuration JSON data
|
|
657
657
|
* @async
|
|
658
658
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
659
659
|
*/
|
|
660
|
-
async getSysCfg(){
|
|
660
|
+
async getSysCfg() {
|
|
661
661
|
const url = new URL(this.params.whost + '/api/getsyscfg');
|
|
662
662
|
url.search = new URLSearchParams({
|
|
663
663
|
clienttype: this.params.app.clienttype,
|
|
@@ -665,8 +665,8 @@ class TeraBoxApp {
|
|
|
665
665
|
cfg_category_keys: '[]',
|
|
666
666
|
version: 0,
|
|
667
667
|
});
|
|
668
|
-
|
|
669
|
-
try{
|
|
668
|
+
|
|
669
|
+
try {
|
|
670
670
|
const req = await request(url, {
|
|
671
671
|
headers: {
|
|
672
672
|
'User-Agent': this.params.ua,
|
|
@@ -674,29 +674,29 @@ class TeraBoxApp {
|
|
|
674
674
|
},
|
|
675
675
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
676
676
|
});
|
|
677
|
-
|
|
677
|
+
|
|
678
678
|
if (req.statusCode !== 200) {
|
|
679
679
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
680
680
|
}
|
|
681
|
-
|
|
681
|
+
|
|
682
682
|
const rdata = await req.body.json();
|
|
683
683
|
return rdata;
|
|
684
684
|
}
|
|
685
|
-
catch(error){
|
|
685
|
+
catch (error) {
|
|
686
686
|
throw new Error('getSysCfg', { cause: error });
|
|
687
687
|
}
|
|
688
688
|
}
|
|
689
|
-
|
|
689
|
+
|
|
690
690
|
/**
|
|
691
691
|
* Checks login status of the current session.
|
|
692
692
|
* @returns {Promise<CheckLoginResponse>} The login status JSON data.
|
|
693
693
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails.
|
|
694
694
|
* @async
|
|
695
695
|
*/
|
|
696
|
-
async checkLogin(){
|
|
696
|
+
async checkLogin() {
|
|
697
697
|
const url = new URL(this.params.whost + '/api/check/login');
|
|
698
|
-
|
|
699
|
-
try{
|
|
698
|
+
|
|
699
|
+
try {
|
|
700
700
|
const req = await request(url, {
|
|
701
701
|
headers: {
|
|
702
702
|
'User-Agent': this.params.ua,
|
|
@@ -704,30 +704,30 @@ class TeraBoxApp {
|
|
|
704
704
|
},
|
|
705
705
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
706
706
|
});
|
|
707
|
-
|
|
707
|
+
|
|
708
708
|
if (req.statusCode !== 200) {
|
|
709
709
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
710
710
|
}
|
|
711
|
-
|
|
711
|
+
|
|
712
712
|
const regionPrefix = req.headers['region-domain-prefix'];
|
|
713
|
-
if(regionPrefix){
|
|
713
|
+
if (regionPrefix) {
|
|
714
714
|
const newHostname = `https://${regionPrefix}.${this.TERABOX_DOMAIN}`;
|
|
715
715
|
console.warn(`[WARN] Default hostname changed to ${newHostname}`);
|
|
716
716
|
this.params.whost = new URL(newHostname).origin;
|
|
717
717
|
return await this.checkLogin();
|
|
718
718
|
}
|
|
719
|
-
|
|
719
|
+
|
|
720
720
|
const rdata = await req.body.json();
|
|
721
|
-
if(rdata.errno === 0){
|
|
721
|
+
if (rdata.errno === 0) {
|
|
722
722
|
this.params.account_id = rdata.uk;
|
|
723
723
|
}
|
|
724
724
|
return rdata;
|
|
725
725
|
}
|
|
726
|
-
catch(error){
|
|
726
|
+
catch (error) {
|
|
727
727
|
throw new Error('checkLogin', { cause: error });
|
|
728
728
|
}
|
|
729
729
|
}
|
|
730
|
-
|
|
730
|
+
|
|
731
731
|
/**
|
|
732
732
|
* Initiates the pre-login step for passport authentication
|
|
733
733
|
* @param {string} email - The user's email address
|
|
@@ -735,22 +735,22 @@ class TeraBoxApp {
|
|
|
735
735
|
* @async
|
|
736
736
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
737
737
|
*/
|
|
738
|
-
async passportPreLogin(email){
|
|
738
|
+
async passportPreLogin(email) {
|
|
739
739
|
const url = new URL(this.params.whost + '/passport/prelogin');
|
|
740
740
|
const authUrl = 'wap/outlogin/login';
|
|
741
|
-
|
|
742
|
-
try{
|
|
743
|
-
if(this.data.pcftoken === ''){
|
|
741
|
+
|
|
742
|
+
try {
|
|
743
|
+
if (this.data.pcftoken === '') {
|
|
744
744
|
await this.updateAppData(authUrl);
|
|
745
745
|
}
|
|
746
|
-
|
|
746
|
+
|
|
747
747
|
const formData = new this.FormUrlEncoded();
|
|
748
748
|
formData.append('client', 'web');
|
|
749
749
|
formData.append('pass_version', '2.8');
|
|
750
750
|
formData.append('clientfrom', 'h5');
|
|
751
751
|
formData.append('pcftoken', this.data.pcftoken);
|
|
752
752
|
formData.append('email', email);
|
|
753
|
-
|
|
753
|
+
|
|
754
754
|
const req = await request(url, {
|
|
755
755
|
method: 'POST',
|
|
756
756
|
headers: {
|
|
@@ -762,11 +762,11 @@ class TeraBoxApp {
|
|
|
762
762
|
body: formData.str(),
|
|
763
763
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
764
764
|
});
|
|
765
|
-
|
|
765
|
+
|
|
766
766
|
if (req.statusCode !== 200) {
|
|
767
767
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
768
768
|
}
|
|
769
|
-
|
|
769
|
+
|
|
770
770
|
const rdata = await req.body.json();
|
|
771
771
|
return rdata;
|
|
772
772
|
}
|
|
@@ -774,7 +774,7 @@ class TeraBoxApp {
|
|
|
774
774
|
throw new Error('passportPreLogin', { cause: error });
|
|
775
775
|
}
|
|
776
776
|
}
|
|
777
|
-
|
|
777
|
+
|
|
778
778
|
/**
|
|
779
779
|
* Completes the passport login process using preLoginData and password
|
|
780
780
|
* @param {Object} preLoginData - Data returned from passportPreLogin
|
|
@@ -787,21 +787,21 @@ class TeraBoxApp {
|
|
|
787
787
|
* @async
|
|
788
788
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
789
789
|
*/
|
|
790
|
-
async passportLogin(preLoginData, email, pass){
|
|
790
|
+
async passportLogin(preLoginData, email, pass) {
|
|
791
791
|
const url = new URL(this.params.whost + '/passport/login');
|
|
792
|
-
|
|
793
|
-
try{
|
|
794
|
-
if(this.data.pubkey === ''){
|
|
792
|
+
|
|
793
|
+
try {
|
|
794
|
+
if (this.data.pubkey === '') {
|
|
795
795
|
await this.getPublicKey();
|
|
796
796
|
}
|
|
797
|
-
|
|
797
|
+
|
|
798
798
|
const cJar = new CookieJar();
|
|
799
799
|
this.params.cookie.split(';').map(cookie => cJar.setCookieSync(cookie, this.params.whost));
|
|
800
800
|
const browserid = cJar.toJSON().cookies.find(c => c.key === 'browserid').value || '';
|
|
801
801
|
const encpwd = this.ChangeBase64Type(this.EncryptRSA(pass, this.data.pubkey, 2));
|
|
802
|
-
|
|
802
|
+
|
|
803
803
|
const prand = this.PRandGen('web', preLoginData.seval, encpwd, email, browserid, preLoginData.random);
|
|
804
|
-
|
|
804
|
+
|
|
805
805
|
const formData = new this.FormUrlEncoded();
|
|
806
806
|
formData.append('client', 'web');
|
|
807
807
|
formData.append('pass_version', '2.8');
|
|
@@ -813,7 +813,7 @@ class TeraBoxApp {
|
|
|
813
813
|
formData.append('seval', preLoginData.seval);
|
|
814
814
|
formData.append('random', preLoginData.random);
|
|
815
815
|
formData.append('timestamp', preLoginData.timestamp);
|
|
816
|
-
|
|
816
|
+
|
|
817
817
|
const req = await request(url, {
|
|
818
818
|
method: 'POST',
|
|
819
819
|
headers: {
|
|
@@ -825,17 +825,17 @@ class TeraBoxApp {
|
|
|
825
825
|
body: formData.str(),
|
|
826
826
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
827
827
|
});
|
|
828
|
-
|
|
828
|
+
|
|
829
829
|
if (req.statusCode !== 200) {
|
|
830
830
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
831
831
|
}
|
|
832
|
-
|
|
832
|
+
|
|
833
833
|
const rdata = await req.body.json();
|
|
834
|
-
if(rdata.code === 0){
|
|
835
|
-
if(typeof req.headers['set-cookie'] === 'string'){
|
|
834
|
+
if (rdata.code === 0) {
|
|
835
|
+
if (typeof req.headers['set-cookie'] === 'string') {
|
|
836
836
|
req.headers['set-cookie'] = [req.headers['set-cookie']];
|
|
837
837
|
}
|
|
838
|
-
for(const cookie of req.headers['set-cookie']){
|
|
838
|
+
for (const cookie of req.headers['set-cookie']) {
|
|
839
839
|
cJar.setCookieSync(cookie.split('; ')[0], this.params.whost);
|
|
840
840
|
}
|
|
841
841
|
const ndus = cJar.toJSON().cookies.find(c => c.key === 'ndus').value;
|
|
@@ -847,7 +847,7 @@ class TeraBoxApp {
|
|
|
847
847
|
throw new Error('passportLogin', { cause: error });
|
|
848
848
|
}
|
|
849
849
|
}
|
|
850
|
-
|
|
850
|
+
|
|
851
851
|
/**
|
|
852
852
|
* Sends a registration code to the specified email
|
|
853
853
|
* @param {string} email - The email address to send the code to
|
|
@@ -855,22 +855,22 @@ class TeraBoxApp {
|
|
|
855
855
|
* @async
|
|
856
856
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
857
857
|
*/
|
|
858
|
-
async regSendCode(email){
|
|
858
|
+
async regSendCode(email) {
|
|
859
859
|
const url = new URL(this.params.whost + '/passport/register_v4/sendcode');
|
|
860
860
|
const emailRegUrl = 'wap/outlogin/emailRegister';
|
|
861
|
-
|
|
862
|
-
try{
|
|
863
|
-
if(this.data.pcftoken === ''){
|
|
861
|
+
|
|
862
|
+
try {
|
|
863
|
+
if (this.data.pcftoken === '') {
|
|
864
864
|
await this.updateAppData(emailRegUrl);
|
|
865
865
|
}
|
|
866
|
-
|
|
866
|
+
|
|
867
867
|
const formData = new this.FormUrlEncoded();
|
|
868
868
|
formData.append('client', 'web');
|
|
869
869
|
formData.append('pass_version', '2.8');
|
|
870
870
|
formData.append('clientfrom', 'h5');
|
|
871
871
|
formData.append('pcftoken', this.data.pcftoken);
|
|
872
872
|
formData.append('email', email);
|
|
873
|
-
|
|
873
|
+
|
|
874
874
|
const req = await request(url, {
|
|
875
875
|
method: 'POST',
|
|
876
876
|
headers: {
|
|
@@ -881,11 +881,11 @@ class TeraBoxApp {
|
|
|
881
881
|
},
|
|
882
882
|
body: formData.str(),
|
|
883
883
|
});
|
|
884
|
-
|
|
884
|
+
|
|
885
885
|
if (req.statusCode !== 200) {
|
|
886
886
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
887
887
|
}
|
|
888
|
-
|
|
888
|
+
|
|
889
889
|
const rdata = await req.body.json();
|
|
890
890
|
// rdata.code: 0 - OK
|
|
891
891
|
// rdata.code: 10 - Email format invalid
|
|
@@ -897,7 +897,7 @@ class TeraBoxApp {
|
|
|
897
897
|
throw new Error('regSendCode', { cause: error });
|
|
898
898
|
}
|
|
899
899
|
}
|
|
900
|
-
|
|
900
|
+
|
|
901
901
|
/**
|
|
902
902
|
* Verifies the registration code received via email
|
|
903
903
|
* @param {string} regToken - Registration token from send code response
|
|
@@ -906,10 +906,10 @@ class TeraBoxApp {
|
|
|
906
906
|
* @async
|
|
907
907
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
908
908
|
*/
|
|
909
|
-
async regVerify(regToken, code){
|
|
909
|
+
async regVerify(regToken, code) {
|
|
910
910
|
const url = new URL(this.params.whost + '/passport/register_v4/verify');
|
|
911
|
-
|
|
912
|
-
try{
|
|
911
|
+
|
|
912
|
+
try {
|
|
913
913
|
const formData = new this.FormUrlEncoded();
|
|
914
914
|
formData.append('client', 'web');
|
|
915
915
|
formData.append('pass_version', '2.8');
|
|
@@ -917,7 +917,7 @@ class TeraBoxApp {
|
|
|
917
917
|
formData.append('pcftoken', this.data.pcftoken);
|
|
918
918
|
formData.append('token', regToken);
|
|
919
919
|
formData.append('code', code);
|
|
920
|
-
|
|
920
|
+
|
|
921
921
|
const req = await request(url, {
|
|
922
922
|
method: 'POST',
|
|
923
923
|
headers: {
|
|
@@ -928,11 +928,11 @@ class TeraBoxApp {
|
|
|
928
928
|
},
|
|
929
929
|
body: formData.str(),
|
|
930
930
|
});
|
|
931
|
-
|
|
931
|
+
|
|
932
932
|
if (req.statusCode !== 200) {
|
|
933
933
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
934
934
|
}
|
|
935
|
-
|
|
935
|
+
|
|
936
936
|
const rdata = await req.body.json();
|
|
937
937
|
// rdata.code: 0 - OK
|
|
938
938
|
// rdata.code: 59 - Email code is wrong
|
|
@@ -942,7 +942,7 @@ class TeraBoxApp {
|
|
|
942
942
|
throw new Error('regVerify', { cause: error });
|
|
943
943
|
}
|
|
944
944
|
}
|
|
945
|
-
|
|
945
|
+
|
|
946
946
|
/**
|
|
947
947
|
* Completes the registration process by setting a password
|
|
948
948
|
* @param {string} regToken - Registration token from verification step
|
|
@@ -951,20 +951,20 @@ class TeraBoxApp {
|
|
|
951
951
|
* @async
|
|
952
952
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
953
953
|
*/
|
|
954
|
-
async regFinish(regToken, pass){
|
|
954
|
+
async regFinish(regToken, pass) {
|
|
955
955
|
const url = new URL(this.params.whost + '/passport/register_v4/finish');
|
|
956
|
-
|
|
957
|
-
try{
|
|
958
|
-
if(this.data.pubkey === ''){
|
|
956
|
+
|
|
957
|
+
try {
|
|
958
|
+
if (this.data.pubkey === '') {
|
|
959
959
|
await this.getPublicKey();
|
|
960
960
|
}
|
|
961
|
-
|
|
962
|
-
if(typeof pass !== 'string' || pass.length < 6 || pass.length > 15 || !pass.match(/[a-z]/i)){
|
|
961
|
+
|
|
962
|
+
if (typeof pass !== 'string' || pass.length < 6 || pass.length > 15 || !pass.match(/[a-z]/i)) {
|
|
963
963
|
return { code: -2, logid: 0, msg: 'invalid password', };
|
|
964
964
|
}
|
|
965
|
-
|
|
965
|
+
|
|
966
966
|
const encpwd = this.ChangeBase64Type(this.EncryptRSA(pass, this.data.pubkey, 2));
|
|
967
|
-
|
|
967
|
+
|
|
968
968
|
const formData = new this.FormUrlEncoded();
|
|
969
969
|
formData.append('client', 'web');
|
|
970
970
|
formData.append('pass_version', '2.8');
|
|
@@ -972,7 +972,7 @@ class TeraBoxApp {
|
|
|
972
972
|
formData.append('pcftoken', this.data.pcftoken);
|
|
973
973
|
formData.append('token', regToken);
|
|
974
974
|
formData.append('pwd', encpwd);
|
|
975
|
-
|
|
975
|
+
|
|
976
976
|
const req = await request(url, {
|
|
977
977
|
method: 'POST',
|
|
978
978
|
headers: {
|
|
@@ -983,22 +983,22 @@ class TeraBoxApp {
|
|
|
983
983
|
},
|
|
984
984
|
body: formData.str(),
|
|
985
985
|
});
|
|
986
|
-
|
|
986
|
+
|
|
987
987
|
if (req.statusCode !== 200) {
|
|
988
988
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
989
989
|
}
|
|
990
|
-
|
|
990
|
+
|
|
991
991
|
const rdata = await req.body.json();
|
|
992
|
-
if(rdata.code === 0 && req.headers['set-cookie']){
|
|
992
|
+
if (rdata.code === 0 && req.headers['set-cookie']) {
|
|
993
993
|
const cJar = new CookieJar();
|
|
994
|
-
|
|
995
|
-
if(typeof req.headers['set-cookie'] === 'string'){
|
|
994
|
+
|
|
995
|
+
if (typeof req.headers['set-cookie'] === 'string') {
|
|
996
996
|
req.headers['set-cookie'] = [req.headers['set-cookie']];
|
|
997
997
|
}
|
|
998
|
-
for(const cookie of req.headers['set-cookie']){
|
|
998
|
+
for (const cookie of req.headers['set-cookie']) {
|
|
999
999
|
cJar.setCookieSync(cookie.split('; ')[0], this.params.whost);
|
|
1000
1000
|
}
|
|
1001
|
-
|
|
1001
|
+
|
|
1002
1002
|
const ndus = cJar.toJSON().cookies.find(c => c.key === 'ndus').value;
|
|
1003
1003
|
rdata.data.ndus = ndus;
|
|
1004
1004
|
}
|
|
@@ -1008,17 +1008,17 @@ class TeraBoxApp {
|
|
|
1008
1008
|
throw new Error('regFinish', { cause: error });
|
|
1009
1009
|
}
|
|
1010
1010
|
}
|
|
1011
|
-
|
|
1011
|
+
|
|
1012
1012
|
/**
|
|
1013
1013
|
* Retrieves passport user information for the current session
|
|
1014
1014
|
* @returns {Promise<Object>} The passport user info JSON (includes display_name)
|
|
1015
1015
|
* @async
|
|
1016
1016
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
1017
1017
|
*/
|
|
1018
|
-
async passportGetInfo(){
|
|
1018
|
+
async passportGetInfo() {
|
|
1019
1019
|
const url = new URL(this.params.whost + '/passport/get_info');
|
|
1020
|
-
|
|
1021
|
-
try{
|
|
1020
|
+
|
|
1021
|
+
try {
|
|
1022
1022
|
const req = await request(url, {
|
|
1023
1023
|
headers: {
|
|
1024
1024
|
'User-Agent': this.params.ua,
|
|
@@ -1026,13 +1026,13 @@ class TeraBoxApp {
|
|
|
1026
1026
|
},
|
|
1027
1027
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
1028
1028
|
});
|
|
1029
|
-
|
|
1029
|
+
|
|
1030
1030
|
if (req.statusCode !== 200) {
|
|
1031
1031
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
1032
1032
|
}
|
|
1033
|
-
|
|
1033
|
+
|
|
1034
1034
|
const rdata = await req.body.json();
|
|
1035
|
-
if(rdata.errno === 0){
|
|
1035
|
+
if (rdata.errno === 0) {
|
|
1036
1036
|
this.params.account_name = rdata.data.display_name;
|
|
1037
1037
|
}
|
|
1038
1038
|
return rdata;
|
|
@@ -1041,20 +1041,20 @@ class TeraBoxApp {
|
|
|
1041
1041
|
throw new Error('getPassport', { cause: error });
|
|
1042
1042
|
}
|
|
1043
1043
|
}
|
|
1044
|
-
|
|
1044
|
+
|
|
1045
1045
|
/**
|
|
1046
1046
|
* Fetches membership information for the current user
|
|
1047
1047
|
* @returns {Promise<Object>} The membership JSON (includes VIP status)
|
|
1048
1048
|
* @async
|
|
1049
1049
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
1050
1050
|
*/
|
|
1051
|
-
async userMembership(){
|
|
1051
|
+
async userMembership() {
|
|
1052
1052
|
const url = new URL(this.params.whost + '/rest/2.0/membership/proxy/user');
|
|
1053
1053
|
url.search = new URLSearchParams({
|
|
1054
1054
|
method: 'query',
|
|
1055
1055
|
});
|
|
1056
|
-
|
|
1057
|
-
try{
|
|
1056
|
+
|
|
1057
|
+
try {
|
|
1058
1058
|
const req = await request(url, {
|
|
1059
1059
|
headers: {
|
|
1060
1060
|
'User-Agent': this.params.ua,
|
|
@@ -1062,40 +1062,40 @@ class TeraBoxApp {
|
|
|
1062
1062
|
},
|
|
1063
1063
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
1064
1064
|
});
|
|
1065
|
-
|
|
1065
|
+
|
|
1066
1066
|
if (req.statusCode !== 200) {
|
|
1067
1067
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
1068
1068
|
}
|
|
1069
|
-
|
|
1069
|
+
|
|
1070
1070
|
const rdata = await req.body.json();
|
|
1071
|
-
if(rdata.error_code === 0){
|
|
1071
|
+
if (rdata.error_code === 0) {
|
|
1072
1072
|
this.params.is_vip = rdata.data.member_info.is_vip > 0 ? true : false;
|
|
1073
1073
|
// this.params.vip_type = this.params.is_vip ? 2 : 0;
|
|
1074
|
-
if(this.params.is_vip === 0){
|
|
1074
|
+
if (this.params.is_vip === 0) {
|
|
1075
1075
|
this.params.vip_type = 0;
|
|
1076
1076
|
}
|
|
1077
1077
|
}
|
|
1078
1078
|
return rdata;
|
|
1079
1079
|
}
|
|
1080
|
-
catch(error){
|
|
1080
|
+
catch (error) {
|
|
1081
1081
|
throw new Error('userMembership', { cause: error });
|
|
1082
1082
|
}
|
|
1083
1083
|
}
|
|
1084
|
-
|
|
1084
|
+
|
|
1085
1085
|
/**
|
|
1086
1086
|
* Retrieves current user information (username, VIP status)
|
|
1087
1087
|
* @returns {Promise<Object>} The user info JSON (includes records array)
|
|
1088
1088
|
* @async
|
|
1089
1089
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
1090
1090
|
*/
|
|
1091
|
-
async getCurrentUserInfo(){
|
|
1092
|
-
try{
|
|
1093
|
-
if(this.params.account_id === 0){
|
|
1091
|
+
async getCurrentUserInfo() {
|
|
1092
|
+
try {
|
|
1093
|
+
if (this.params.account_id === 0) {
|
|
1094
1094
|
await this.checkLogin();
|
|
1095
1095
|
}
|
|
1096
|
-
|
|
1096
|
+
|
|
1097
1097
|
const curUser = await this.getUserInfo(this.params.account_id);
|
|
1098
|
-
if(curUser.records.length > 0){
|
|
1098
|
+
if (curUser.records.length > 0) {
|
|
1099
1099
|
const thisUser = curUser.records[0];
|
|
1100
1100
|
this.params.account_name = thisUser.uname;
|
|
1101
1101
|
this.params.is_vip = thisUser.vip_type > 0 ? true : false;
|
|
@@ -1107,7 +1107,7 @@ class TeraBoxApp {
|
|
|
1107
1107
|
throw new Error('getCurrentUserInfo', { cause: error });
|
|
1108
1108
|
}
|
|
1109
1109
|
}
|
|
1110
|
-
|
|
1110
|
+
|
|
1111
1111
|
/**
|
|
1112
1112
|
* Retrieves information for a specific user ID
|
|
1113
1113
|
* @param {number|string} user_id - The user ID to look up
|
|
@@ -1115,7 +1115,7 @@ class TeraBoxApp {
|
|
|
1115
1115
|
* @async
|
|
1116
1116
|
* @throws {Error} Throws error if user_id is invalid, HTTP status is not 200, or request fails
|
|
1117
1117
|
*/
|
|
1118
|
-
async getUserInfo(user_id){
|
|
1118
|
+
async getUserInfo(user_id) {
|
|
1119
1119
|
user_id = parseInt(user_id);
|
|
1120
1120
|
const url = new URL(this.params.whost + '/api/user/getinfo');
|
|
1121
1121
|
url.search = new URLSearchParams({
|
|
@@ -1123,12 +1123,12 @@ class TeraBoxApp {
|
|
|
1123
1123
|
need_relation: 0,
|
|
1124
1124
|
need_secret_info: 1,
|
|
1125
1125
|
});
|
|
1126
|
-
|
|
1127
|
-
try{
|
|
1128
|
-
if(isNaN(user_id) || !Number.isSafeInteger(user_id)){
|
|
1126
|
+
|
|
1127
|
+
try {
|
|
1128
|
+
if (isNaN(user_id) || !Number.isSafeInteger(user_id)) {
|
|
1129
1129
|
throw new Error(`${user_id} is not user id`);
|
|
1130
1130
|
}
|
|
1131
|
-
|
|
1131
|
+
|
|
1132
1132
|
const req = await request(url, {
|
|
1133
1133
|
headers: {
|
|
1134
1134
|
'User-Agent': this.params.ua,
|
|
@@ -1136,11 +1136,11 @@ class TeraBoxApp {
|
|
|
1136
1136
|
},
|
|
1137
1137
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
1138
1138
|
});
|
|
1139
|
-
|
|
1139
|
+
|
|
1140
1140
|
if (req.statusCode !== 200) {
|
|
1141
1141
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
1142
1142
|
}
|
|
1143
|
-
|
|
1143
|
+
|
|
1144
1144
|
const rdata = await req.body.json();
|
|
1145
1145
|
return rdata;
|
|
1146
1146
|
}
|
|
@@ -1148,21 +1148,21 @@ class TeraBoxApp {
|
|
|
1148
1148
|
throw new Error('getUserInfo', { cause: error });
|
|
1149
1149
|
}
|
|
1150
1150
|
}
|
|
1151
|
-
|
|
1151
|
+
|
|
1152
1152
|
/**
|
|
1153
1153
|
* Retrieves storage quota information for the current account
|
|
1154
1154
|
* @returns {Promise<Object>} The quota JSON (includes total, used, available)
|
|
1155
1155
|
* @async
|
|
1156
1156
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
1157
1157
|
*/
|
|
1158
|
-
async getQuota(){
|
|
1158
|
+
async getQuota() {
|
|
1159
1159
|
const url = new URL(this.params.whost + '/api/quota');
|
|
1160
1160
|
url.search = new URLSearchParams({
|
|
1161
1161
|
checkexpire: 1,
|
|
1162
1162
|
checkfree: 1,
|
|
1163
1163
|
});
|
|
1164
|
-
|
|
1165
|
-
try{
|
|
1164
|
+
|
|
1165
|
+
try {
|
|
1166
1166
|
const req = await request(url, {
|
|
1167
1167
|
headers: {
|
|
1168
1168
|
'User-Agent': this.params.ua,
|
|
@@ -1170,13 +1170,13 @@ class TeraBoxApp {
|
|
|
1170
1170
|
},
|
|
1171
1171
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
1172
1172
|
});
|
|
1173
|
-
|
|
1173
|
+
|
|
1174
1174
|
if (req.statusCode !== 200) {
|
|
1175
1175
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
1176
1176
|
}
|
|
1177
|
-
|
|
1177
|
+
|
|
1178
1178
|
const rdata = await req.body.json();
|
|
1179
|
-
if(rdata.errno === 0){
|
|
1179
|
+
if (rdata.errno === 0) {
|
|
1180
1180
|
rdata.available = rdata.total - rdata.used;
|
|
1181
1181
|
this.params.space_available = rdata.available;
|
|
1182
1182
|
this.params.space_total = rdata.total;
|
|
@@ -1188,17 +1188,17 @@ class TeraBoxApp {
|
|
|
1188
1188
|
throw new Error('getQuota', { cause: error });
|
|
1189
1189
|
}
|
|
1190
1190
|
}
|
|
1191
|
-
|
|
1191
|
+
|
|
1192
1192
|
/**
|
|
1193
1193
|
* Retrieves the user's coins count (points)
|
|
1194
1194
|
* @returns {Promise<Object>} The coins count JSON (includes records of coin usage)
|
|
1195
1195
|
* @async
|
|
1196
1196
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
1197
1197
|
*/
|
|
1198
|
-
async getCoinsCount(){
|
|
1198
|
+
async getCoinsCount() {
|
|
1199
1199
|
const url = new URL(this.params.whost + '/rest/1.0/inte/system/getrecord');
|
|
1200
|
-
|
|
1201
|
-
try{
|
|
1200
|
+
|
|
1201
|
+
try {
|
|
1202
1202
|
const req = await request(url, {
|
|
1203
1203
|
headers: {
|
|
1204
1204
|
'User-Agent': this.params.ua,
|
|
@@ -1206,11 +1206,11 @@ class TeraBoxApp {
|
|
|
1206
1206
|
},
|
|
1207
1207
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
1208
1208
|
});
|
|
1209
|
-
|
|
1209
|
+
|
|
1210
1210
|
if (req.statusCode !== 200) {
|
|
1211
1211
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
1212
1212
|
}
|
|
1213
|
-
|
|
1213
|
+
|
|
1214
1214
|
const rdata = await req.body.json();
|
|
1215
1215
|
return rdata;
|
|
1216
1216
|
}
|
|
@@ -1218,7 +1218,7 @@ class TeraBoxApp {
|
|
|
1218
1218
|
throw new Error('getCoinsCount', { cause: error });
|
|
1219
1219
|
}
|
|
1220
1220
|
}
|
|
1221
|
-
|
|
1221
|
+
|
|
1222
1222
|
/**
|
|
1223
1223
|
* Retrieves the contents of a remote directory
|
|
1224
1224
|
* @param {string} remoteDir - Remote directory path to list
|
|
@@ -1227,10 +1227,10 @@ class TeraBoxApp {
|
|
|
1227
1227
|
* @async
|
|
1228
1228
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
1229
1229
|
*/
|
|
1230
|
-
async getRemoteDir(remoteDir, page = 1){
|
|
1230
|
+
async getRemoteDir(remoteDir, page = 1) {
|
|
1231
1231
|
const url = new URL(this.params.whost + '/api/list');
|
|
1232
|
-
|
|
1233
|
-
try{
|
|
1232
|
+
|
|
1233
|
+
try {
|
|
1234
1234
|
const formData = new this.FormUrlEncoded();
|
|
1235
1235
|
formData.append('order', 'name');
|
|
1236
1236
|
formData.append('desc', 0);
|
|
@@ -1238,7 +1238,7 @@ class TeraBoxApp {
|
|
|
1238
1238
|
formData.append('num', 20000);
|
|
1239
1239
|
formData.append('page', page);
|
|
1240
1240
|
formData.append('showempty', 0);
|
|
1241
|
-
|
|
1241
|
+
|
|
1242
1242
|
const req = await request(url, {
|
|
1243
1243
|
method: 'POST',
|
|
1244
1244
|
body: formData.str(),
|
|
@@ -1249,11 +1249,11 @@ class TeraBoxApp {
|
|
|
1249
1249
|
},
|
|
1250
1250
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
1251
1251
|
});
|
|
1252
|
-
|
|
1252
|
+
|
|
1253
1253
|
if (req.statusCode !== 200) {
|
|
1254
1254
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
1255
1255
|
}
|
|
1256
|
-
|
|
1256
|
+
|
|
1257
1257
|
const rdata = await req.body.json();
|
|
1258
1258
|
return rdata;
|
|
1259
1259
|
}
|
|
@@ -1261,7 +1261,7 @@ class TeraBoxApp {
|
|
|
1261
1261
|
throw new Error('getRemoteDir', { cause: error });
|
|
1262
1262
|
}
|
|
1263
1263
|
}
|
|
1264
|
-
|
|
1264
|
+
|
|
1265
1265
|
/**
|
|
1266
1266
|
* Retrieves the contents of a remote directory with specific file category
|
|
1267
1267
|
* @param {number} [categoryId=1] - selected category:
|
|
@@ -1278,10 +1278,10 @@ class TeraBoxApp {
|
|
|
1278
1278
|
* @async
|
|
1279
1279
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
1280
1280
|
*/
|
|
1281
|
-
async getCategoryList(categoryId = 1, remoteDir = '/', page = 1, order = 'name', desc = 0, num = 20000){
|
|
1281
|
+
async getCategoryList(categoryId = 1, remoteDir = '/', page = 1, order = 'name', desc = 0, num = 20000) {
|
|
1282
1282
|
const url = new URL(this.params.whost + '/api/categorylist');
|
|
1283
|
-
|
|
1284
|
-
try{
|
|
1283
|
+
|
|
1284
|
+
try {
|
|
1285
1285
|
const formData = new this.FormUrlEncoded();
|
|
1286
1286
|
formData.append('order', order);
|
|
1287
1287
|
formData.append('desc', desc);
|
|
@@ -1289,7 +1289,7 @@ class TeraBoxApp {
|
|
|
1289
1289
|
formData.append('num', num);
|
|
1290
1290
|
formData.append('page', page);
|
|
1291
1291
|
formData.append('category', categoryId);
|
|
1292
|
-
|
|
1292
|
+
|
|
1293
1293
|
const req = await request(url, {
|
|
1294
1294
|
method: 'POST',
|
|
1295
1295
|
body: formData.str(),
|
|
@@ -1300,11 +1300,11 @@ class TeraBoxApp {
|
|
|
1300
1300
|
},
|
|
1301
1301
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
1302
1302
|
});
|
|
1303
|
-
|
|
1303
|
+
|
|
1304
1304
|
if (req.statusCode !== 200) {
|
|
1305
1305
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
1306
1306
|
}
|
|
1307
|
-
|
|
1307
|
+
|
|
1308
1308
|
const rdata = await req.body.json();
|
|
1309
1309
|
return rdata;
|
|
1310
1310
|
}
|
|
@@ -1312,25 +1312,25 @@ class TeraBoxApp {
|
|
|
1312
1312
|
throw new Error('getCategoryList', { cause: error });
|
|
1313
1313
|
}
|
|
1314
1314
|
}
|
|
1315
|
-
|
|
1315
|
+
|
|
1316
1316
|
/**
|
|
1317
1317
|
* Retrieves the contents of the recycle bin
|
|
1318
1318
|
* @returns {Promise<Object>} The recycle bin listing JSON (includes entries array)
|
|
1319
1319
|
* @async
|
|
1320
1320
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
1321
1321
|
*/
|
|
1322
|
-
async getRecycleBin(page = 1){
|
|
1322
|
+
async getRecycleBin(page = 1) {
|
|
1323
1323
|
const url = new URL(this.params.whost + '/api/recycle/list');
|
|
1324
|
-
|
|
1325
|
-
try{
|
|
1324
|
+
|
|
1325
|
+
try {
|
|
1326
1326
|
url.search = new URLSearchParams({
|
|
1327
1327
|
// order: 'name',
|
|
1328
1328
|
desc: 0,
|
|
1329
1329
|
num: 20000,
|
|
1330
1330
|
page: page,
|
|
1331
1331
|
});
|
|
1332
|
-
|
|
1333
|
-
|
|
1332
|
+
|
|
1333
|
+
|
|
1334
1334
|
const req = await request(url, {
|
|
1335
1335
|
headers: {
|
|
1336
1336
|
'User-Agent': this.params.ua,
|
|
@@ -1338,11 +1338,11 @@ class TeraBoxApp {
|
|
|
1338
1338
|
},
|
|
1339
1339
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
1340
1340
|
});
|
|
1341
|
-
|
|
1341
|
+
|
|
1342
1342
|
if (req.statusCode !== 200) {
|
|
1343
1343
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
1344
1344
|
}
|
|
1345
|
-
|
|
1345
|
+
|
|
1346
1346
|
const rdata = await req.body.json();
|
|
1347
1347
|
return rdata;
|
|
1348
1348
|
}
|
|
@@ -1350,21 +1350,21 @@ class TeraBoxApp {
|
|
|
1350
1350
|
throw new Error('getRecycleBin', { cause: error });
|
|
1351
1351
|
}
|
|
1352
1352
|
}
|
|
1353
|
-
|
|
1353
|
+
|
|
1354
1354
|
/**
|
|
1355
1355
|
* Clears all items in the recycle bin
|
|
1356
1356
|
* @returns {Promise<Object>} The clear recycle bin response JSON
|
|
1357
1357
|
* @async
|
|
1358
1358
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
1359
1359
|
*/
|
|
1360
|
-
async clearRecycleBin(){
|
|
1360
|
+
async clearRecycleBin() {
|
|
1361
1361
|
const url = new URL(this.params.whost + '/api/recycle/clear');
|
|
1362
|
-
|
|
1363
|
-
try{
|
|
1362
|
+
|
|
1363
|
+
try {
|
|
1364
1364
|
url.search = new URLSearchParams({
|
|
1365
1365
|
'async': 1,
|
|
1366
1366
|
});
|
|
1367
|
-
|
|
1367
|
+
|
|
1368
1368
|
const req = await request(url, {
|
|
1369
1369
|
headers: {
|
|
1370
1370
|
'User-Agent': this.params.ua,
|
|
@@ -1372,11 +1372,11 @@ class TeraBoxApp {
|
|
|
1372
1372
|
},
|
|
1373
1373
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
1374
1374
|
});
|
|
1375
|
-
|
|
1375
|
+
|
|
1376
1376
|
if (req.statusCode !== 200) {
|
|
1377
1377
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
1378
1378
|
}
|
|
1379
|
-
|
|
1379
|
+
|
|
1380
1380
|
const rdata = await req.body.json();
|
|
1381
1381
|
return rdata;
|
|
1382
1382
|
}
|
|
@@ -1384,7 +1384,7 @@ class TeraBoxApp {
|
|
|
1384
1384
|
throw new Error('clearRecycleBin', { cause: error });
|
|
1385
1385
|
}
|
|
1386
1386
|
}
|
|
1387
|
-
|
|
1387
|
+
|
|
1388
1388
|
/**
|
|
1389
1389
|
* Initiates a precreate request for a file (reserve upload ID and pre-upload checks)
|
|
1390
1390
|
* @param {Object} data - File data including remote_dir, file, size, upload_id (optional), and hash info
|
|
@@ -1401,7 +1401,7 @@ class TeraBoxApp {
|
|
|
1401
1401
|
* @async
|
|
1402
1402
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
1403
1403
|
*/
|
|
1404
|
-
async precreateFile(data){
|
|
1404
|
+
async precreateFile(data) {
|
|
1405
1405
|
const formData = new this.FormUrlEncoded();
|
|
1406
1406
|
formData.append('path', makeRemoteFPath(data.remote_dir, data.file));
|
|
1407
1407
|
// formData.append('target_path', data.remote_dir);
|
|
@@ -1410,51 +1410,51 @@ class TeraBoxApp {
|
|
|
1410
1410
|
formData.append('file_limit_switch_v34', 'true');
|
|
1411
1411
|
formData.append('block_list', '[]');
|
|
1412
1412
|
formData.append('rtype', 2);
|
|
1413
|
-
|
|
1414
|
-
if(data.upload_id && typeof data.upload_id === 'string' && data.upload_id !== ''){
|
|
1413
|
+
|
|
1414
|
+
if (data.upload_id && typeof data.upload_id === 'string' && data.upload_id !== '') {
|
|
1415
1415
|
formData.append('uploadid', data.upload_id);
|
|
1416
1416
|
}
|
|
1417
|
-
|
|
1417
|
+
|
|
1418
1418
|
// check if has correct md5 values
|
|
1419
|
-
if(this.CheckMd5Val(data.hash.slice) && this.CheckMd5Val(data.hash.file)){
|
|
1419
|
+
if (this.CheckMd5Val(data.hash.slice) && this.CheckMd5Val(data.hash.file)) {
|
|
1420
1420
|
formData.append('content-md5', data.hash.file);
|
|
1421
1421
|
formData.append('slice-md5', data.hash.slice);
|
|
1422
1422
|
}
|
|
1423
|
-
|
|
1423
|
+
|
|
1424
1424
|
// check crc32int and ignore field for crc32 out of range
|
|
1425
|
-
if(Number.isSafeInteger(data.hash.crc32) && data.hash.crc32 >= 0 && data.hash.crc32 <= 0xFFFFFFFF){
|
|
1425
|
+
if (Number.isSafeInteger(data.hash.crc32) && data.hash.crc32 >= 0 && data.hash.crc32 <= 0xFFFFFFFF) {
|
|
1426
1426
|
formData.append('content-crc32', data.hash.crc32);
|
|
1427
1427
|
}
|
|
1428
|
-
|
|
1428
|
+
|
|
1429
1429
|
// check chunks hash
|
|
1430
|
-
if(!this.CheckMd5Arr(data.hash.chunks)){
|
|
1430
|
+
if (!this.CheckMd5Arr(data.hash.chunks)) {
|
|
1431
1431
|
const predefinedHash = ['5910a591dd8fc18c32a8f3df4fdc1761'];
|
|
1432
|
-
|
|
1433
|
-
if(data.size > 4 * 1024 * 1024){
|
|
1432
|
+
|
|
1433
|
+
if (data.size > 4 * 1024 * 1024) {
|
|
1434
1434
|
predefinedHash.push('a5fc157d78e6ad1c7e114b056c92821e');
|
|
1435
1435
|
}
|
|
1436
|
-
|
|
1436
|
+
|
|
1437
1437
|
formData.set('block_list', JSON.stringify(predefinedHash));
|
|
1438
1438
|
}
|
|
1439
|
-
else{
|
|
1439
|
+
else {
|
|
1440
1440
|
formData.set('block_list', JSON.stringify(data.hash.chunks));
|
|
1441
1441
|
}
|
|
1442
|
-
|
|
1442
|
+
|
|
1443
1443
|
// formData.append('local_ctime', '');
|
|
1444
1444
|
// formData.append('local_mtime', '');
|
|
1445
|
-
|
|
1445
|
+
|
|
1446
1446
|
const url = new URL(this.params.whost + '/api/precreate');
|
|
1447
|
-
|
|
1448
|
-
try{
|
|
1449
|
-
if(this.data.jsToken === ''){
|
|
1447
|
+
|
|
1448
|
+
try {
|
|
1449
|
+
if (this.data.jsToken === '') {
|
|
1450
1450
|
await this.updateAppData();
|
|
1451
1451
|
}
|
|
1452
|
-
|
|
1452
|
+
|
|
1453
1453
|
url.search = new URLSearchParams({
|
|
1454
1454
|
...this.params.app,
|
|
1455
1455
|
jsToken: this.data.jsToken,
|
|
1456
1456
|
});
|
|
1457
|
-
|
|
1457
|
+
|
|
1458
1458
|
const req = await request(url, {
|
|
1459
1459
|
method: 'POST',
|
|
1460
1460
|
body: formData.str(),
|
|
@@ -1465,15 +1465,15 @@ class TeraBoxApp {
|
|
|
1465
1465
|
},
|
|
1466
1466
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
1467
1467
|
});
|
|
1468
|
-
|
|
1468
|
+
|
|
1469
1469
|
if (req.statusCode !== 200) {
|
|
1470
1470
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
1471
1471
|
}
|
|
1472
|
-
|
|
1472
|
+
|
|
1473
1473
|
// uploadid = 'P1-' + BASE64(ServerLocalIP + ':' + ServerTime + ':' + RequestID)
|
|
1474
1474
|
const rdata = await req.body.json();
|
|
1475
1475
|
// rdata.errno: 4000023 - need verify
|
|
1476
|
-
if(rdata.errno === 4000023){
|
|
1476
|
+
if (rdata.errno === 4000023) {
|
|
1477
1477
|
await this.updateAppData();
|
|
1478
1478
|
return await this.precreateFile(data);
|
|
1479
1479
|
}
|
|
@@ -1483,7 +1483,7 @@ class TeraBoxApp {
|
|
|
1483
1483
|
throw new Error('precreateFile', { cause: error });
|
|
1484
1484
|
}
|
|
1485
1485
|
}
|
|
1486
|
-
|
|
1486
|
+
|
|
1487
1487
|
/**
|
|
1488
1488
|
* Attempts a rapid upload using existing file hashes (skip actual upload if file already on server)
|
|
1489
1489
|
* @param {Object} data - File data including remote_dir, file, size, and hash info
|
|
@@ -1499,9 +1499,9 @@ class TeraBoxApp {
|
|
|
1499
1499
|
* @async
|
|
1500
1500
|
* @throws {Error} Throws error if file size < 256KB, invalid hashes, HTTP status is not 200, or request fails
|
|
1501
1501
|
*/
|
|
1502
|
-
async rapidUpload(data){
|
|
1502
|
+
async rapidUpload(data) {
|
|
1503
1503
|
const formData = new this.FormUrlEncoded({
|
|
1504
|
-
path:
|
|
1504
|
+
path: makeRemoteFPath(data.remote_dir, data.file),
|
|
1505
1505
|
//target_path: data.remote_dir
|
|
1506
1506
|
'content-length': data.size,
|
|
1507
1507
|
'content-md5': data.hash.file,
|
|
@@ -1513,29 +1513,29 @@ class TeraBoxApp {
|
|
|
1513
1513
|
rtype: 2,
|
|
1514
1514
|
mode: 1,
|
|
1515
1515
|
});
|
|
1516
|
-
|
|
1517
|
-
if(!this.CheckMd5Val(data.hash.slice) || !this.CheckMd5Val(data.hash.file)){
|
|
1516
|
+
|
|
1517
|
+
if (!this.CheckMd5Val(data.hash.slice) || !this.CheckMd5Val(data.hash.file)) {
|
|
1518
1518
|
const badMD5 = new Error('Bad MD5 Slice Hash or MD5 File Hash');
|
|
1519
1519
|
throw new Error('rapidUpload', { cause: badMD5 });
|
|
1520
1520
|
}
|
|
1521
|
-
|
|
1522
|
-
if(!Number.isSafeInteger(data.hash.crc32) || data.hash.crc32 < 0 || data.hash.crc32 > 0xFFFFFFFF){
|
|
1521
|
+
|
|
1522
|
+
if (!Number.isSafeInteger(data.hash.crc32) || data.hash.crc32 < 0 || data.hash.crc32 > 0xFFFFFFFF) {
|
|
1523
1523
|
formData.delete('content-crc32');
|
|
1524
1524
|
}
|
|
1525
|
-
|
|
1526
|
-
if(!this.CheckMd5Arr(data.hash.chunks)){
|
|
1525
|
+
|
|
1526
|
+
if (!this.CheckMd5Arr(data.hash.chunks)) {
|
|
1527
1527
|
// use unsafe rapid upload if we don't have chunks hash
|
|
1528
1528
|
formData.delete('block_list');
|
|
1529
1529
|
formData.set('rtype', 3);
|
|
1530
1530
|
}
|
|
1531
|
-
|
|
1531
|
+
|
|
1532
1532
|
const url = new URL(this.params.whost + '/api/rapidupload');
|
|
1533
|
-
|
|
1534
|
-
try{
|
|
1535
|
-
if(data.size < 256 * 1024){
|
|
1533
|
+
|
|
1534
|
+
try {
|
|
1535
|
+
if (data.size < 256 * 1024) {
|
|
1536
1536
|
throw new Error('File size too small!');
|
|
1537
1537
|
}
|
|
1538
|
-
|
|
1538
|
+
|
|
1539
1539
|
const req = await request(url, {
|
|
1540
1540
|
method: 'POST',
|
|
1541
1541
|
body: formData.str(),
|
|
@@ -1546,11 +1546,11 @@ class TeraBoxApp {
|
|
|
1546
1546
|
},
|
|
1547
1547
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
1548
1548
|
});
|
|
1549
|
-
|
|
1549
|
+
|
|
1550
1550
|
if (req.statusCode !== 200) {
|
|
1551
1551
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
1552
1552
|
}
|
|
1553
|
-
|
|
1553
|
+
|
|
1554
1554
|
const rdata = await req.body.json();
|
|
1555
1555
|
// rdata.errno: 2 - already exist?
|
|
1556
1556
|
return rdata;
|
|
@@ -1559,7 +1559,7 @@ class TeraBoxApp {
|
|
|
1559
1559
|
throw new Error('rapidUpload', { cause: error });
|
|
1560
1560
|
}
|
|
1561
1561
|
}
|
|
1562
|
-
|
|
1562
|
+
|
|
1563
1563
|
/**
|
|
1564
1564
|
* Attempts a upload file from remote server
|
|
1565
1565
|
* @param {string} urls - Source urls (coma-separated)
|
|
@@ -1568,15 +1568,15 @@ class TeraBoxApp {
|
|
|
1568
1568
|
* @async
|
|
1569
1569
|
* @throws {Error} Throws error if HTTP status is not 200, or request fails
|
|
1570
1570
|
*/
|
|
1571
|
-
async remoteUpload(urls, remote_dir = '/Remote Upload'){
|
|
1571
|
+
async remoteUpload(urls, remote_dir = '/Remote Upload') {
|
|
1572
1572
|
const formData = new this.FormUrlEncoded({
|
|
1573
1573
|
urls: urls,
|
|
1574
1574
|
upload_to: remote_dir,
|
|
1575
1575
|
});
|
|
1576
|
-
|
|
1576
|
+
|
|
1577
1577
|
const url = new URL(this.params.whost + '/webmaster/remoteupload/submit');
|
|
1578
|
-
|
|
1579
|
-
try{
|
|
1578
|
+
|
|
1579
|
+
try {
|
|
1580
1580
|
const req = await request(url, {
|
|
1581
1581
|
method: 'POST',
|
|
1582
1582
|
body: formData.str(),
|
|
@@ -1587,11 +1587,11 @@ class TeraBoxApp {
|
|
|
1587
1587
|
},
|
|
1588
1588
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
1589
1589
|
});
|
|
1590
|
-
|
|
1590
|
+
|
|
1591
1591
|
if (req.statusCode !== 200) {
|
|
1592
1592
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
1593
1593
|
}
|
|
1594
|
-
|
|
1594
|
+
|
|
1595
1595
|
const rdata = await req.body.json();
|
|
1596
1596
|
return rdata;
|
|
1597
1597
|
}
|
|
@@ -1599,16 +1599,16 @@ class TeraBoxApp {
|
|
|
1599
1599
|
throw new Error('remoteUpload', { cause: error });
|
|
1600
1600
|
}
|
|
1601
1601
|
}
|
|
1602
|
-
|
|
1602
|
+
|
|
1603
1603
|
/**
|
|
1604
1604
|
* Retrieves an upload host endpoint to use for file uploads
|
|
1605
1605
|
* @returns {Promise<Object>} The upload host response JSON (includes host field)
|
|
1606
1606
|
* @async
|
|
1607
1607
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
1608
1608
|
*/
|
|
1609
|
-
async getUploadHost(){
|
|
1609
|
+
async getUploadHost() {
|
|
1610
1610
|
const url = new URL(this.params.whost + '/rest/2.0/pcs/file?method=locateupload');
|
|
1611
|
-
try{
|
|
1611
|
+
try {
|
|
1612
1612
|
const req = await request(url, {
|
|
1613
1613
|
headers: {
|
|
1614
1614
|
'User-Agent': this.params.ua,
|
|
@@ -1616,11 +1616,11 @@ class TeraBoxApp {
|
|
|
1616
1616
|
},
|
|
1617
1617
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
1618
1618
|
});
|
|
1619
|
-
|
|
1619
|
+
|
|
1620
1620
|
if (req.statusCode !== 200) {
|
|
1621
1621
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
1622
1622
|
}
|
|
1623
|
-
|
|
1623
|
+
|
|
1624
1624
|
const rdata = await req.body.json();
|
|
1625
1625
|
this.params.uhost = 'https://' + rdata.host;
|
|
1626
1626
|
return rdata;
|
|
@@ -1629,7 +1629,7 @@ class TeraBoxApp {
|
|
|
1629
1629
|
throw new Error('getUploadHost', { cause: error });
|
|
1630
1630
|
}
|
|
1631
1631
|
}
|
|
1632
|
-
|
|
1632
|
+
|
|
1633
1633
|
/**
|
|
1634
1634
|
* Uploads a single chunk (part) of a file
|
|
1635
1635
|
* @param {Object} data - File data including remote_dir, file, upload_id
|
|
@@ -1645,7 +1645,7 @@ class TeraBoxApp {
|
|
|
1645
1645
|
const timeoutAborter = new AbortController;
|
|
1646
1646
|
const timeoutId = setTimeout(() => { timeoutAborter.abort(); }, this.TERABOX_TIMEOUT);
|
|
1647
1647
|
externalAbort = externalAbort ? externalAbort : new AbortController().signal;
|
|
1648
|
-
|
|
1648
|
+
|
|
1649
1649
|
const url = new URL(`${this.params.uhost}/rest/2.0/pcs/superfile2`);
|
|
1650
1650
|
url.search = new URLSearchParams({
|
|
1651
1651
|
method: 'upload',
|
|
@@ -1656,10 +1656,10 @@ class TeraBoxApp {
|
|
|
1656
1656
|
// uploadsign: 0,
|
|
1657
1657
|
partseq: partseq,
|
|
1658
1658
|
});
|
|
1659
|
-
|
|
1659
|
+
|
|
1660
1660
|
const formData = new FormData();
|
|
1661
1661
|
formData.append('file', blob, 'blob');
|
|
1662
|
-
|
|
1662
|
+
|
|
1663
1663
|
const req = await request(url, {
|
|
1664
1664
|
method: 'POST',
|
|
1665
1665
|
body: formData,
|
|
@@ -1672,13 +1672,13 @@ class TeraBoxApp {
|
|
|
1672
1672
|
timeoutAborter.signal,
|
|
1673
1673
|
]),
|
|
1674
1674
|
});
|
|
1675
|
-
|
|
1675
|
+
|
|
1676
1676
|
clearTimeout(timeoutId);
|
|
1677
|
-
|
|
1677
|
+
|
|
1678
1678
|
if (req.statusCode !== 200) {
|
|
1679
|
-
throw new Error(`HTTP error! Status: ${
|
|
1679
|
+
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
1680
1680
|
}
|
|
1681
|
-
|
|
1681
|
+
|
|
1682
1682
|
const res = await req.body.json();
|
|
1683
1683
|
if (res.error_code) {
|
|
1684
1684
|
const uploadError = new Error(`Upload failed! Error Code #${res.error_code}`);
|
|
@@ -1687,7 +1687,7 @@ class TeraBoxApp {
|
|
|
1687
1687
|
}
|
|
1688
1688
|
return res;
|
|
1689
1689
|
}
|
|
1690
|
-
|
|
1690
|
+
|
|
1691
1691
|
/**
|
|
1692
1692
|
* Creates a new directory in the remote file system
|
|
1693
1693
|
* @param {string} remoteDir - The path of the directory to create
|
|
@@ -1695,15 +1695,15 @@ class TeraBoxApp {
|
|
|
1695
1695
|
* @async
|
|
1696
1696
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
1697
1697
|
*/
|
|
1698
|
-
async createDir(remoteDir){
|
|
1698
|
+
async createDir(remoteDir) {
|
|
1699
1699
|
const formData = new this.FormUrlEncoded();
|
|
1700
1700
|
formData.append('path', remoteDir);
|
|
1701
1701
|
formData.append('isdir', 1);
|
|
1702
1702
|
formData.append('block_list', '[]');
|
|
1703
|
-
|
|
1703
|
+
|
|
1704
1704
|
const url = new URL(this.params.whost + '/api/create?a=commit');
|
|
1705
|
-
|
|
1706
|
-
try{
|
|
1705
|
+
|
|
1706
|
+
try {
|
|
1707
1707
|
const req = await request(url, {
|
|
1708
1708
|
method: 'POST',
|
|
1709
1709
|
body: formData.str(),
|
|
@@ -1714,11 +1714,11 @@ class TeraBoxApp {
|
|
|
1714
1714
|
},
|
|
1715
1715
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
1716
1716
|
});
|
|
1717
|
-
|
|
1717
|
+
|
|
1718
1718
|
if (req.statusCode !== 200) {
|
|
1719
1719
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
1720
1720
|
}
|
|
1721
|
-
|
|
1721
|
+
|
|
1722
1722
|
const rdata = await req.body.json();
|
|
1723
1723
|
// rdata.errno: -7 - param path file name is invalid
|
|
1724
1724
|
return rdata;
|
|
@@ -1727,7 +1727,7 @@ class TeraBoxApp {
|
|
|
1727
1727
|
throw new Error('createFolder', { cause: error });
|
|
1728
1728
|
}
|
|
1729
1729
|
}
|
|
1730
|
-
|
|
1730
|
+
|
|
1731
1731
|
/**
|
|
1732
1732
|
* Creates a new file entry on the server after uploading chunks
|
|
1733
1733
|
* @param {Object} data - File data including remote_dir, file, size, hash, upload_id, and chunks
|
|
@@ -1744,28 +1744,28 @@ class TeraBoxApp {
|
|
|
1744
1744
|
* @async
|
|
1745
1745
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
1746
1746
|
*/
|
|
1747
|
-
async createFile(data){
|
|
1747
|
+
async createFile(data) {
|
|
1748
1748
|
const formData = new this.FormUrlEncoded();
|
|
1749
1749
|
formData.append('path', makeRemoteFPath(data.remote_dir, data.file));
|
|
1750
1750
|
// formData.append('isdir', 0);
|
|
1751
1751
|
formData.append('size', data.size);
|
|
1752
1752
|
formData.append('isdir', 0);
|
|
1753
|
-
|
|
1753
|
+
|
|
1754
1754
|
// check if has correct md5 values
|
|
1755
|
-
if(this.CheckMd5Val(data.hash.slice) && this.CheckMd5Val(data.hash.file)){
|
|
1755
|
+
if (this.CheckMd5Val(data.hash.slice) && this.CheckMd5Val(data.hash.file)) {
|
|
1756
1756
|
formData.append('content-md5', data.hash.file);
|
|
1757
1757
|
formData.append('slice-md5', data.hash.slice);
|
|
1758
1758
|
}
|
|
1759
|
-
|
|
1759
|
+
|
|
1760
1760
|
// check crc32int and ignore field for crc32 out of range
|
|
1761
|
-
if(Number.isSafeInteger(data.hash.crc32) && data.hash.crc32 >= 0 && data.hash.crc32 <= 0xFFFFFFFF){
|
|
1761
|
+
if (Number.isSafeInteger(data.hash.crc32) && data.hash.crc32 >= 0 && data.hash.crc32 <= 0xFFFFFFFF) {
|
|
1762
1762
|
formData.append('content-crc32', data.hash.crc32);
|
|
1763
1763
|
}
|
|
1764
|
-
|
|
1764
|
+
|
|
1765
1765
|
formData.append('block_list', JSON.stringify(data.hash.chunks));;
|
|
1766
1766
|
formData.append('uploadid', data.upload_id);
|
|
1767
1767
|
formData.append('rtype', 2);
|
|
1768
|
-
|
|
1768
|
+
|
|
1769
1769
|
// formData.append('local_ctime', '');
|
|
1770
1770
|
// formData.append('local_mtime', '');
|
|
1771
1771
|
// formData.append('zip_quality', '');
|
|
@@ -1773,10 +1773,10 @@ class TeraBoxApp {
|
|
|
1773
1773
|
// formData.append('is_revision', 0);
|
|
1774
1774
|
// formData.append('mode', 2); // 2 is Batch Upload
|
|
1775
1775
|
// formData.append('exif_info', exifJsonStr);
|
|
1776
|
-
|
|
1776
|
+
|
|
1777
1777
|
const url = new URL(this.params.whost + '/api/create');
|
|
1778
|
-
|
|
1779
|
-
try{
|
|
1778
|
+
|
|
1779
|
+
try {
|
|
1780
1780
|
const req = await request(url, {
|
|
1781
1781
|
method: 'POST',
|
|
1782
1782
|
body: formData.str(),
|
|
@@ -1787,21 +1787,21 @@ class TeraBoxApp {
|
|
|
1787
1787
|
},
|
|
1788
1788
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
1789
1789
|
});
|
|
1790
|
-
|
|
1790
|
+
|
|
1791
1791
|
if (req.statusCode !== 200) {
|
|
1792
1792
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
1793
1793
|
}
|
|
1794
|
-
|
|
1794
|
+
|
|
1795
1795
|
const rdata = await req.body.json();
|
|
1796
1796
|
// rdata.errno: 31355 - pcs service failed
|
|
1797
|
-
if(rdata.md5){
|
|
1797
|
+
if (rdata.md5) {
|
|
1798
1798
|
// encrypted etag
|
|
1799
1799
|
rdata.emd5 = rdata.md5;
|
|
1800
1800
|
// decrypted etag (without chunk count)
|
|
1801
1801
|
rdata.md5 = this.DecodeMd5(rdata.emd5);
|
|
1802
1802
|
// set custom etag
|
|
1803
1803
|
rdata.etag = rdata.md5;
|
|
1804
|
-
if(data.hash.chunks.length > 1){
|
|
1804
|
+
if (data.hash.chunks.length > 1) {
|
|
1805
1805
|
rdata.etag += '-' + data.hash.chunks.length;
|
|
1806
1806
|
}
|
|
1807
1807
|
}
|
|
@@ -1812,7 +1812,7 @@ class TeraBoxApp {
|
|
|
1812
1812
|
throw new Error('createFile', { cause: error });
|
|
1813
1813
|
}
|
|
1814
1814
|
}
|
|
1815
|
-
|
|
1815
|
+
|
|
1816
1816
|
/**
|
|
1817
1817
|
* Performs file management operations (delete, copy, move, rename)
|
|
1818
1818
|
* @param {string} operation - Operation type: 'delete', 'copy', 'move', 'rename'
|
|
@@ -1821,33 +1821,33 @@ class TeraBoxApp {
|
|
|
1821
1821
|
* @async
|
|
1822
1822
|
* @throws {Error} Throws error if fmparams is not an array, HTTP status is not 200, or request fails
|
|
1823
1823
|
*/
|
|
1824
|
-
async filemanager(operation, fmparams){
|
|
1824
|
+
async filemanager(operation, fmparams) {
|
|
1825
1825
|
// For Delete: ["/path1","path2.rar"]
|
|
1826
1826
|
// For Move: [{"path":"/myfolder/source.bin","dest":"/target/","newname":"newfilename.bin"}]
|
|
1827
1827
|
// For Copy same as move
|
|
1828
1828
|
// + "ondup": newcopy, overwrite (optional, skip by default)
|
|
1829
1829
|
// For rename [{"id":1111,"path":"/dir1/src.bin","newname":"myfile2.bin"}]
|
|
1830
|
-
|
|
1830
|
+
|
|
1831
1831
|
// operation - copy (file copy), move (file movement), rename (file renaming), and delete (file deletion)
|
|
1832
1832
|
// opera=copy: filelist: [{"path":"/hello/test.mp4","dest":"","newname":"test.mp4"}]
|
|
1833
1833
|
// opera=move: filelist: [{"path":"/test.mp4","dest":"/test_dir","newname":"test.mp4"}]
|
|
1834
1834
|
// opera=rename: filelist:[{"path":"/hello/test.mp4","newname":"test_one.mp4"}]
|
|
1835
1835
|
// opera=delete: filelist: ["/test.mp4"]
|
|
1836
|
-
|
|
1837
|
-
if(!Array.isArray(fmparams)){
|
|
1836
|
+
|
|
1837
|
+
if (!Array.isArray(fmparams)) {
|
|
1838
1838
|
throw new Error('filemanager', { cause: new Error('FS paths should be in array!') });
|
|
1839
1839
|
}
|
|
1840
|
-
|
|
1840
|
+
|
|
1841
1841
|
const url = new URL(this.params.whost + '/api/filemanager');
|
|
1842
|
-
|
|
1842
|
+
|
|
1843
1843
|
const formData = new this.FormUrlEncoded();
|
|
1844
1844
|
formData.append('filelist', JSON.stringify(fmparams));
|
|
1845
|
-
|
|
1846
|
-
try{
|
|
1847
|
-
if(this.data.jsToken === ''){
|
|
1845
|
+
|
|
1846
|
+
try {
|
|
1847
|
+
if (this.data.jsToken === '') {
|
|
1848
1848
|
await this.updateAppData();
|
|
1849
1849
|
}
|
|
1850
|
-
|
|
1850
|
+
|
|
1851
1851
|
url.search = new URLSearchParams({
|
|
1852
1852
|
...this.params.app,
|
|
1853
1853
|
jsToken: this.data.jsToken,
|
|
@@ -1855,7 +1855,7 @@ class TeraBoxApp {
|
|
|
1855
1855
|
onnest: 'fail',
|
|
1856
1856
|
opera: operation, // delete, copy, move, rename
|
|
1857
1857
|
});
|
|
1858
|
-
|
|
1858
|
+
|
|
1859
1859
|
const req = await request(url, {
|
|
1860
1860
|
method: 'POST',
|
|
1861
1861
|
body: formData.str(),
|
|
@@ -1866,13 +1866,13 @@ class TeraBoxApp {
|
|
|
1866
1866
|
},
|
|
1867
1867
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
1868
1868
|
});
|
|
1869
|
-
|
|
1869
|
+
|
|
1870
1870
|
if (req.statusCode !== 200) {
|
|
1871
1871
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
1872
1872
|
}
|
|
1873
|
-
|
|
1873
|
+
|
|
1874
1874
|
const rdata = await req.body.json();
|
|
1875
|
-
if(rdata.errno === 450016){
|
|
1875
|
+
if (rdata.errno === 450016) {
|
|
1876
1876
|
await this.updateAppData();
|
|
1877
1877
|
return await this.filemanager(operation, fmparams);
|
|
1878
1878
|
}
|
|
@@ -1882,23 +1882,23 @@ class TeraBoxApp {
|
|
|
1882
1882
|
throw new Error('filemanager', { cause: error });
|
|
1883
1883
|
}
|
|
1884
1884
|
}
|
|
1885
|
-
|
|
1885
|
+
|
|
1886
1886
|
/**
|
|
1887
1887
|
* Retrieves a list of shares created by the user
|
|
1888
1888
|
* @returns {Promise<Object>} The share list JSON (includes share entries)
|
|
1889
1889
|
* @async
|
|
1890
1890
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
1891
1891
|
*/
|
|
1892
|
-
async shareList(page = 1){
|
|
1892
|
+
async shareList(page = 1) {
|
|
1893
1893
|
const url = new URL(this.params.whost + '/share/teratransfer/sharelist');
|
|
1894
|
-
|
|
1895
|
-
try{
|
|
1894
|
+
|
|
1895
|
+
try {
|
|
1896
1896
|
url.search = new URLSearchParams({
|
|
1897
1897
|
// ...this.params.app,
|
|
1898
1898
|
page_size: 100,
|
|
1899
1899
|
page: page,
|
|
1900
1900
|
});
|
|
1901
|
-
|
|
1901
|
+
|
|
1902
1902
|
const req = await request(url, {
|
|
1903
1903
|
headers: {
|
|
1904
1904
|
'User-Agent': this.params.ua,
|
|
@@ -1906,7 +1906,7 @@ class TeraBoxApp {
|
|
|
1906
1906
|
},
|
|
1907
1907
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
1908
1908
|
});
|
|
1909
|
-
|
|
1909
|
+
|
|
1910
1910
|
const rdata = await req.body.json();
|
|
1911
1911
|
return rdata;
|
|
1912
1912
|
}
|
|
@@ -1914,7 +1914,7 @@ class TeraBoxApp {
|
|
|
1914
1914
|
throw new Error('shareList', { cause: error });
|
|
1915
1915
|
}
|
|
1916
1916
|
}
|
|
1917
|
-
|
|
1917
|
+
|
|
1918
1918
|
/**
|
|
1919
1919
|
* Sets sharing parameters (e.g., password, expiration) for specified files
|
|
1920
1920
|
* @param {Array<string>} filelist - Array of file paths to share
|
|
@@ -1924,31 +1924,31 @@ class TeraBoxApp {
|
|
|
1924
1924
|
* @async
|
|
1925
1925
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
1926
1926
|
*/
|
|
1927
|
-
async shareSet(filelist, pass = '', period = 0){
|
|
1927
|
+
async shareSet(filelist, pass = '', period = 0) {
|
|
1928
1928
|
const url = new URL(this.params.whost + '/share/pset');
|
|
1929
|
-
|
|
1930
|
-
try{
|
|
1929
|
+
|
|
1930
|
+
try {
|
|
1931
1931
|
url.search = new URLSearchParams({
|
|
1932
1932
|
// ...this.params.app,
|
|
1933
1933
|
});
|
|
1934
|
-
|
|
1934
|
+
|
|
1935
1935
|
filelist = Array.isArray(filelist) ? filelist : [];
|
|
1936
1936
|
filelist = JSON.stringify(filelist);
|
|
1937
|
-
|
|
1937
|
+
|
|
1938
1938
|
pass = typeof pass === 'string' && pass.match(/^[0-9a-z]{4}$/i) ? pass : '';
|
|
1939
1939
|
const schannel = pass !== '' ? 4 : 0;
|
|
1940
|
-
|
|
1940
|
+
|
|
1941
1941
|
// 0 - infinity, otherwise valid X days
|
|
1942
1942
|
period = parseInt(period);
|
|
1943
1943
|
period = !isNaN(period) && Number.isSafeInteger(period) ? period : 0;
|
|
1944
|
-
|
|
1944
|
+
|
|
1945
1945
|
const formData = new this.FormUrlEncoded();
|
|
1946
1946
|
formData.append('schannel', schannel);
|
|
1947
1947
|
formData.append('channel_list', '[]');
|
|
1948
1948
|
formData.append('period', period);
|
|
1949
1949
|
formData.append('path_list', filelist);
|
|
1950
1950
|
formData.append('pwd', pass);
|
|
1951
|
-
|
|
1951
|
+
|
|
1952
1952
|
const req = await request(url, {
|
|
1953
1953
|
headers: {
|
|
1954
1954
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
@@ -1959,7 +1959,7 @@ class TeraBoxApp {
|
|
|
1959
1959
|
body: formData.str(),
|
|
1960
1960
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
1961
1961
|
});
|
|
1962
|
-
|
|
1962
|
+
|
|
1963
1963
|
const rdata = await req.body.json();
|
|
1964
1964
|
return rdata;
|
|
1965
1965
|
}
|
|
@@ -1967,7 +1967,7 @@ class TeraBoxApp {
|
|
|
1967
1967
|
throw new Error('shareSet', { cause: error });
|
|
1968
1968
|
}
|
|
1969
1969
|
}
|
|
1970
|
-
|
|
1970
|
+
|
|
1971
1971
|
/**
|
|
1972
1972
|
* Cancels existing shares by share ID
|
|
1973
1973
|
* @param {Array<number>} [shareid_list=[]] - Array of share IDs to cancel
|
|
@@ -1975,20 +1975,20 @@ class TeraBoxApp {
|
|
|
1975
1975
|
* @async
|
|
1976
1976
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
1977
1977
|
*/
|
|
1978
|
-
async shareCancel(shareid_list = []){
|
|
1978
|
+
async shareCancel(shareid_list = []) {
|
|
1979
1979
|
const url = new URL(this.params.whost + '/share/cancel');
|
|
1980
|
-
|
|
1981
|
-
try{
|
|
1980
|
+
|
|
1981
|
+
try {
|
|
1982
1982
|
url.search = new URLSearchParams({
|
|
1983
1983
|
// ...this.params.app,
|
|
1984
1984
|
});
|
|
1985
|
-
|
|
1985
|
+
|
|
1986
1986
|
shareid_list = Array.isArray(shareid_list) ? shareid_list : [];
|
|
1987
1987
|
shareid_list = JSON.stringify(shareid_list);
|
|
1988
|
-
|
|
1988
|
+
|
|
1989
1989
|
const formData = new this.FormUrlEncoded();
|
|
1990
1990
|
formData.append('shareid_list', shareid_list);
|
|
1991
|
-
|
|
1991
|
+
|
|
1992
1992
|
const req = await request(url, {
|
|
1993
1993
|
headers: {
|
|
1994
1994
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
@@ -1999,7 +1999,7 @@ class TeraBoxApp {
|
|
|
1999
1999
|
body: formData.str(),
|
|
2000
2000
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
2001
2001
|
});
|
|
2002
|
-
|
|
2002
|
+
|
|
2003
2003
|
const rdata = await req.body.json();
|
|
2004
2004
|
return rdata;
|
|
2005
2005
|
}
|
|
@@ -2007,7 +2007,7 @@ class TeraBoxApp {
|
|
|
2007
2007
|
throw new Error('shareCancel', { cause: error });
|
|
2008
2008
|
}
|
|
2009
2009
|
}
|
|
2010
|
-
|
|
2010
|
+
|
|
2011
2011
|
/**
|
|
2012
2012
|
* Retrieves information for a shortened URL share
|
|
2013
2013
|
* @param {string} shortUrl - The short url: after "surl="
|
|
@@ -2015,16 +2015,16 @@ class TeraBoxApp {
|
|
|
2015
2015
|
* @async
|
|
2016
2016
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
2017
2017
|
*/
|
|
2018
|
-
async shortUrlInfo(shortUrl){
|
|
2018
|
+
async shortUrlInfo(shortUrl) {
|
|
2019
2019
|
const url = new URL(this.params.whost + '/api/shorturlinfo');
|
|
2020
|
-
|
|
2021
|
-
try{
|
|
2020
|
+
|
|
2021
|
+
try {
|
|
2022
2022
|
url.search = new URLSearchParams({
|
|
2023
2023
|
//...this.params.app,
|
|
2024
2024
|
shorturl: '1' + shortUrl,
|
|
2025
2025
|
root: 1,
|
|
2026
2026
|
});
|
|
2027
|
-
|
|
2027
|
+
|
|
2028
2028
|
const connector = buildConnector({ ciphers: tls.DEFAULT_CIPHERS + ':!ECDHE-RSA-AES128-SHA' });
|
|
2029
2029
|
const client = new Client(this.params.whost, { connect: connector });
|
|
2030
2030
|
const req = await request(url, {
|
|
@@ -2036,11 +2036,11 @@ class TeraBoxApp {
|
|
|
2036
2036
|
dispatcher: client,
|
|
2037
2037
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
2038
2038
|
});
|
|
2039
|
-
|
|
2039
|
+
|
|
2040
2040
|
if (req.statusCode !== 200) {
|
|
2041
2041
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
2042
2042
|
}
|
|
2043
|
-
|
|
2043
|
+
|
|
2044
2044
|
const rdata = await req.body.json();
|
|
2045
2045
|
return rdata;
|
|
2046
2046
|
}
|
|
@@ -2048,7 +2048,7 @@ class TeraBoxApp {
|
|
|
2048
2048
|
throw new Error('shortUrlInfo', { cause: error });
|
|
2049
2049
|
}
|
|
2050
2050
|
}
|
|
2051
|
-
|
|
2051
|
+
|
|
2052
2052
|
/**
|
|
2053
2053
|
* Lists files under a shortened URL share
|
|
2054
2054
|
* @param {string} shortUrl - The short url: after "surl="
|
|
@@ -2058,15 +2058,15 @@ class TeraBoxApp {
|
|
|
2058
2058
|
* @async
|
|
2059
2059
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
2060
2060
|
*/
|
|
2061
|
-
async shortUrlList(shortUrl, remoteDir = '', page = 1){
|
|
2061
|
+
async shortUrlList(shortUrl, remoteDir = '', page = 1) {
|
|
2062
2062
|
const url = new URL(this.params.whost + '/share/list');
|
|
2063
2063
|
remoteDir = remoteDir || '';
|
|
2064
|
-
|
|
2065
|
-
try{
|
|
2066
|
-
if(this.data.jsToken === ''){
|
|
2064
|
+
|
|
2065
|
+
try {
|
|
2066
|
+
if (this.data.jsToken === '') {
|
|
2067
2067
|
await this.updateAppData();
|
|
2068
2068
|
}
|
|
2069
|
-
|
|
2069
|
+
|
|
2070
2070
|
url.search = new URLSearchParams({
|
|
2071
2071
|
...this.params.app,
|
|
2072
2072
|
jsToken: this.data.jsToken,
|
|
@@ -2077,11 +2077,11 @@ class TeraBoxApp {
|
|
|
2077
2077
|
dir: remoteDir,
|
|
2078
2078
|
page: page,
|
|
2079
2079
|
});
|
|
2080
|
-
|
|
2081
|
-
if(remoteDir === ''){
|
|
2080
|
+
|
|
2081
|
+
if (remoteDir === '') {
|
|
2082
2082
|
url.searchParams.append('root', '1');
|
|
2083
2083
|
}
|
|
2084
|
-
|
|
2084
|
+
|
|
2085
2085
|
const connector = buildConnector({ ciphers: tls.DEFAULT_CIPHERS + ':!ECDHE-RSA-AES128-SHA' });
|
|
2086
2086
|
const client = new Client(this.params.whost, { connect: connector });
|
|
2087
2087
|
const req = await request(url, {
|
|
@@ -2093,14 +2093,14 @@ class TeraBoxApp {
|
|
|
2093
2093
|
dispatcher: client,
|
|
2094
2094
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
2095
2095
|
});
|
|
2096
|
-
|
|
2096
|
+
|
|
2097
2097
|
if (req.statusCode !== 200) {
|
|
2098
2098
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
2099
2099
|
}
|
|
2100
|
-
|
|
2100
|
+
|
|
2101
2101
|
const rdata = await req.body.json();
|
|
2102
2102
|
// rdata.errno: 4000020 - need verify
|
|
2103
|
-
if(rdata.errno === 4000020){
|
|
2103
|
+
if (rdata.errno === 4000020) {
|
|
2104
2104
|
await this.updateAppData();
|
|
2105
2105
|
return await this.shortUrlList(shortUrl, remoteDir, page);
|
|
2106
2106
|
}
|
|
@@ -2110,21 +2110,21 @@ class TeraBoxApp {
|
|
|
2110
2110
|
throw new Error('shortUrlList', { cause: error });
|
|
2111
2111
|
}
|
|
2112
2112
|
}
|
|
2113
|
-
|
|
2113
|
+
|
|
2114
2114
|
/**
|
|
2115
2115
|
* Retrieves file difference (delta) information for synchronization
|
|
2116
2116
|
* @returns {Promise<Object>} The file diff JSON (includes entries, request_id, has_more flag)
|
|
2117
2117
|
* @async
|
|
2118
2118
|
* @throws {Error} Throws error if HTTP status is not 200, request fails, or on recursive errors
|
|
2119
2119
|
*/
|
|
2120
|
-
async fileDiff(){
|
|
2120
|
+
async fileDiff() {
|
|
2121
2121
|
const formData = new this.FormUrlEncoded();
|
|
2122
2122
|
formData.append('cursor', this.params.cursor);
|
|
2123
|
-
if(this.params.cursor === 'null'){
|
|
2123
|
+
if (this.params.cursor === 'null') {
|
|
2124
2124
|
formData.append('c', 'full');
|
|
2125
2125
|
}
|
|
2126
2126
|
formData.append('action', 'manual');
|
|
2127
|
-
|
|
2127
|
+
|
|
2128
2128
|
const url = new URL(this.params.whost + '/api/filediff');
|
|
2129
2129
|
url.search = new URLSearchParams({
|
|
2130
2130
|
...this.params.app,
|
|
@@ -2136,8 +2136,8 @@ class TeraBoxApp {
|
|
|
2136
2136
|
// lang: this.params.lang,
|
|
2137
2137
|
// logid: '',
|
|
2138
2138
|
});
|
|
2139
|
-
|
|
2140
|
-
try{
|
|
2139
|
+
|
|
2140
|
+
try {
|
|
2141
2141
|
const req = await request(url, {
|
|
2142
2142
|
method: 'POST',
|
|
2143
2143
|
body: formData.str(),
|
|
@@ -2148,21 +2148,21 @@ class TeraBoxApp {
|
|
|
2148
2148
|
},
|
|
2149
2149
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
2150
2150
|
});
|
|
2151
|
-
|
|
2151
|
+
|
|
2152
2152
|
if (req.statusCode !== 200) {
|
|
2153
2153
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
2154
2154
|
}
|
|
2155
|
-
|
|
2155
|
+
|
|
2156
2156
|
const rdata = await req.body.json();
|
|
2157
|
-
if(rdata.errno === 0){
|
|
2157
|
+
if (rdata.errno === 0) {
|
|
2158
2158
|
this.params.cursor = rdata.cursor;
|
|
2159
|
-
if(!Array.isArray(rdata.request_id)){
|
|
2160
|
-
rdata.request_id = [
|
|
2159
|
+
if (!Array.isArray(rdata.request_id)) {
|
|
2160
|
+
rdata.request_id = [rdata.request_id];
|
|
2161
2161
|
}
|
|
2162
|
-
if(rdata.has_more){
|
|
2162
|
+
if (rdata.has_more) {
|
|
2163
2163
|
// Extra FileDiff request...
|
|
2164
2164
|
const rFileDiff = await this.fileDiff();
|
|
2165
|
-
if(rFileDiff.errno === 0){
|
|
2165
|
+
if (rFileDiff.errno === 0) {
|
|
2166
2166
|
rdata.reset = rFileDiff.reset;
|
|
2167
2167
|
rdata.request_id = rdata.request_id.concat(rFileDiff.request_id);
|
|
2168
2168
|
rdata.entries = Object.assign({}, rdata.entries, rFileDiff.entries);
|
|
@@ -2177,23 +2177,23 @@ class TeraBoxApp {
|
|
|
2177
2177
|
throw new Error('fileDiff', { cause: error });
|
|
2178
2178
|
}
|
|
2179
2179
|
}
|
|
2180
|
-
|
|
2180
|
+
|
|
2181
2181
|
/**
|
|
2182
2182
|
* Generates a PAN token for subsequent API requests
|
|
2183
2183
|
* @returns {Promise<Object>} The PAN token response JSON (includes pan token and expire)
|
|
2184
2184
|
* @async
|
|
2185
2185
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
2186
2186
|
*/
|
|
2187
|
-
async genPanToken(){
|
|
2187
|
+
async genPanToken() {
|
|
2188
2188
|
const url = new URL(this.params.whost + '/api/pantoken');
|
|
2189
|
-
|
|
2190
|
-
try{
|
|
2189
|
+
|
|
2190
|
+
try {
|
|
2191
2191
|
url.search = new URLSearchParams({
|
|
2192
2192
|
...this.params.app,
|
|
2193
2193
|
lang: this.params.lang,
|
|
2194
2194
|
u: 'https://www.terabox.com',
|
|
2195
2195
|
});
|
|
2196
|
-
|
|
2196
|
+
|
|
2197
2197
|
const req = await request(url, {
|
|
2198
2198
|
headers: {
|
|
2199
2199
|
'User-Agent': this.params.ua,
|
|
@@ -2201,11 +2201,11 @@ class TeraBoxApp {
|
|
|
2201
2201
|
},
|
|
2202
2202
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
2203
2203
|
});
|
|
2204
|
-
|
|
2204
|
+
|
|
2205
2205
|
if (req.statusCode !== 200) {
|
|
2206
2206
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
2207
2207
|
}
|
|
2208
|
-
|
|
2208
|
+
|
|
2209
2209
|
const rdata = await req.body.json();
|
|
2210
2210
|
return rdata;
|
|
2211
2211
|
}
|
|
@@ -2213,17 +2213,17 @@ class TeraBoxApp {
|
|
|
2213
2213
|
throw new Error('genPanToken', { cause: error });
|
|
2214
2214
|
}
|
|
2215
2215
|
}
|
|
2216
|
-
|
|
2216
|
+
|
|
2217
2217
|
/**
|
|
2218
2218
|
* Retrieves home page information (user info, sign data)
|
|
2219
2219
|
* @returns {Promise<Object>} The home info JSON (includes sign1, sign3, data.signb)
|
|
2220
2220
|
* @async
|
|
2221
2221
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
2222
2222
|
*/
|
|
2223
|
-
async getHomeInfo(){
|
|
2223
|
+
async getHomeInfo() {
|
|
2224
2224
|
const url = new URL(this.params.whost + '/api/home/info');
|
|
2225
|
-
|
|
2226
|
-
try{
|
|
2225
|
+
|
|
2226
|
+
try {
|
|
2227
2227
|
const req = await request(url, {
|
|
2228
2228
|
headers: {
|
|
2229
2229
|
'User-Agent': this.params.ua,
|
|
@@ -2231,13 +2231,13 @@ class TeraBoxApp {
|
|
|
2231
2231
|
},
|
|
2232
2232
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
2233
2233
|
});
|
|
2234
|
-
|
|
2234
|
+
|
|
2235
2235
|
if (req.statusCode !== 200) {
|
|
2236
2236
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
2237
2237
|
}
|
|
2238
|
-
|
|
2238
|
+
|
|
2239
2239
|
const rdata = await req.body.json();
|
|
2240
|
-
if(rdata.errno === 0){
|
|
2240
|
+
if (rdata.errno === 0) {
|
|
2241
2241
|
rdata.data.signb = this.SignDownload(rdata.data.sign3, rdata.data.sign1);
|
|
2242
2242
|
}
|
|
2243
2243
|
return rdata;
|
|
@@ -2246,7 +2246,7 @@ class TeraBoxApp {
|
|
|
2246
2246
|
throw new Error('getHomeInfo', { cause: error });
|
|
2247
2247
|
}
|
|
2248
2248
|
}
|
|
2249
|
-
|
|
2249
|
+
|
|
2250
2250
|
/**
|
|
2251
2251
|
* Initiates a download request for specified file IDs
|
|
2252
2252
|
* @param {Array<number>} fs_ids - Array of file system IDs to download
|
|
@@ -2255,15 +2255,15 @@ class TeraBoxApp {
|
|
|
2255
2255
|
* @async
|
|
2256
2256
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
2257
2257
|
*/
|
|
2258
|
-
async download(fs_ids){
|
|
2258
|
+
async download(fs_ids) {
|
|
2259
2259
|
const url = new URL(this.params.whost + '/api/download');
|
|
2260
|
-
|
|
2261
|
-
try{
|
|
2260
|
+
|
|
2261
|
+
try {
|
|
2262
2262
|
const homeInfo = await this.getHomeInfo();
|
|
2263
|
-
if(homeInfo.errno !== 0){
|
|
2263
|
+
if (homeInfo.errno !== 0) {
|
|
2264
2264
|
throw new Error('API error! Bad HomeInfo response');
|
|
2265
2265
|
}
|
|
2266
|
-
|
|
2266
|
+
|
|
2267
2267
|
const formData = new this.FormUrlEncoded({
|
|
2268
2268
|
fidlist: JSON.stringify(fs_ids),
|
|
2269
2269
|
type: 'dlink',
|
|
@@ -2272,7 +2272,7 @@ class TeraBoxApp {
|
|
|
2272
2272
|
timestamp: homeInfo.data.timestamp,
|
|
2273
2273
|
need_speed: 1, // Premium speed?..
|
|
2274
2274
|
});
|
|
2275
|
-
|
|
2275
|
+
|
|
2276
2276
|
const req = await request(url, {
|
|
2277
2277
|
method: 'POST',
|
|
2278
2278
|
body: formData.str(),
|
|
@@ -2283,11 +2283,11 @@ class TeraBoxApp {
|
|
|
2283
2283
|
},
|
|
2284
2284
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
2285
2285
|
});
|
|
2286
|
-
|
|
2286
|
+
|
|
2287
2287
|
if (req.statusCode !== 200) {
|
|
2288
2288
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
2289
2289
|
}
|
|
2290
|
-
|
|
2290
|
+
|
|
2291
2291
|
const rdata = await req.body.json();
|
|
2292
2292
|
return rdata;
|
|
2293
2293
|
}
|
|
@@ -2295,7 +2295,7 @@ class TeraBoxApp {
|
|
|
2295
2295
|
throw new Error('download', { cause: error });
|
|
2296
2296
|
}
|
|
2297
2297
|
}
|
|
2298
|
-
|
|
2298
|
+
|
|
2299
2299
|
/**
|
|
2300
2300
|
* Retrieves the streaming contents of a remote file
|
|
2301
2301
|
* @param {string} remotePath - Remote video file
|
|
@@ -2311,15 +2311,15 @@ class TeraBoxApp {
|
|
|
2311
2311
|
* @async
|
|
2312
2312
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
2313
2313
|
*/
|
|
2314
|
-
async getStream(remotePath = '/video.mp4', type = 'M3U8_AUTO_480'){
|
|
2314
|
+
async getStream(remotePath = '/video.mp4', type = 'M3U8_AUTO_480') {
|
|
2315
2315
|
const url = new URL(this.params.whost + '/api/streaming');
|
|
2316
|
-
|
|
2317
|
-
try{
|
|
2316
|
+
|
|
2317
|
+
try {
|
|
2318
2318
|
const formData = new this.FormUrlEncoded();
|
|
2319
2319
|
formData.append('path', remotePath);
|
|
2320
2320
|
formData.append('type', type);
|
|
2321
2321
|
formData.append('vip', 2);
|
|
2322
|
-
|
|
2322
|
+
|
|
2323
2323
|
const req = await request(url, {
|
|
2324
2324
|
method: 'POST',
|
|
2325
2325
|
body: formData.str(),
|
|
@@ -2330,11 +2330,11 @@ class TeraBoxApp {
|
|
|
2330
2330
|
},
|
|
2331
2331
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
2332
2332
|
});
|
|
2333
|
-
|
|
2333
|
+
|
|
2334
2334
|
if (req.statusCode !== 200) {
|
|
2335
2335
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
2336
2336
|
}
|
|
2337
|
-
|
|
2337
|
+
|
|
2338
2338
|
const rdata = await req.body.json();
|
|
2339
2339
|
return rdata;
|
|
2340
2340
|
}
|
|
@@ -2342,7 +2342,7 @@ class TeraBoxApp {
|
|
|
2342
2342
|
throw new Error('getStream', { cause: error });
|
|
2343
2343
|
}
|
|
2344
2344
|
}
|
|
2345
|
-
|
|
2345
|
+
|
|
2346
2346
|
/**
|
|
2347
2347
|
* Retrieves metadata for specified remote files
|
|
2348
2348
|
* @param {Array<Object>} remote_file_list - Array of file descriptor objects { fs_id, path, etc. }
|
|
@@ -2350,16 +2350,16 @@ class TeraBoxApp {
|
|
|
2350
2350
|
* @async
|
|
2351
2351
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
2352
2352
|
*/
|
|
2353
|
-
async getFileMeta(remote_file_list){
|
|
2353
|
+
async getFileMeta(remote_file_list) {
|
|
2354
2354
|
const url = new URL(this.params.whost + '/api/filemetas');
|
|
2355
|
-
|
|
2356
|
-
try{
|
|
2355
|
+
|
|
2356
|
+
try {
|
|
2357
2357
|
const formData = new this.FormUrlEncoded({
|
|
2358
2358
|
dlink: 1,
|
|
2359
2359
|
origin: 'dlna',
|
|
2360
2360
|
target: JSON.stringify(remote_file_list),
|
|
2361
2361
|
});
|
|
2362
|
-
|
|
2362
|
+
|
|
2363
2363
|
const req = await request(url, {
|
|
2364
2364
|
method: 'POST',
|
|
2365
2365
|
body: formData.str(),
|
|
@@ -2370,11 +2370,11 @@ class TeraBoxApp {
|
|
|
2370
2370
|
},
|
|
2371
2371
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
2372
2372
|
});
|
|
2373
|
-
|
|
2373
|
+
|
|
2374
2374
|
if (req.statusCode !== 200) {
|
|
2375
2375
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
2376
2376
|
}
|
|
2377
|
-
|
|
2377
|
+
|
|
2378
2378
|
const rdata = await req.body.json();
|
|
2379
2379
|
return rdata;
|
|
2380
2380
|
}
|
|
@@ -2382,7 +2382,7 @@ class TeraBoxApp {
|
|
|
2382
2382
|
throw new Error('getFileMeta', { cause: error });
|
|
2383
2383
|
}
|
|
2384
2384
|
}
|
|
2385
|
-
|
|
2385
|
+
|
|
2386
2386
|
/**
|
|
2387
2387
|
* Retrieves a list of recent uploads for the account
|
|
2388
2388
|
* @param {number} [page=1] - Page number for pagination
|
|
@@ -2390,17 +2390,17 @@ class TeraBoxApp {
|
|
|
2390
2390
|
* @async
|
|
2391
2391
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
2392
2392
|
*/
|
|
2393
|
-
async getRecentUploads(page = 1){
|
|
2393
|
+
async getRecentUploads(page = 1) {
|
|
2394
2394
|
const url = new URL(this.params.whost + '/rest/recent/listall');
|
|
2395
|
-
|
|
2396
|
-
try{
|
|
2395
|
+
|
|
2396
|
+
try {
|
|
2397
2397
|
url.search = new URLSearchParams({
|
|
2398
2398
|
...this.params.app,
|
|
2399
|
-
version:
|
|
2399
|
+
version: this.params.ver_android,
|
|
2400
2400
|
// num: 20000, ???
|
|
2401
2401
|
// page: page, // ???
|
|
2402
2402
|
});
|
|
2403
|
-
|
|
2403
|
+
|
|
2404
2404
|
const req = await request(url, {
|
|
2405
2405
|
method: 'GET',
|
|
2406
2406
|
headers: {
|
|
@@ -2409,11 +2409,11 @@ class TeraBoxApp {
|
|
|
2409
2409
|
},
|
|
2410
2410
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
2411
2411
|
});
|
|
2412
|
-
|
|
2412
|
+
|
|
2413
2413
|
if (req.statusCode !== 200) {
|
|
2414
2414
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
2415
2415
|
}
|
|
2416
|
-
|
|
2416
|
+
|
|
2417
2417
|
const rdata = await req.body.json();
|
|
2418
2418
|
return rdata;
|
|
2419
2419
|
}
|
|
@@ -2421,7 +2421,7 @@ class TeraBoxApp {
|
|
|
2421
2421
|
throw new Error('getRecentUploads', { cause: error });
|
|
2422
2422
|
}
|
|
2423
2423
|
}
|
|
2424
|
-
|
|
2424
|
+
|
|
2425
2425
|
/**
|
|
2426
2426
|
* Queries transfer information for a shared URL
|
|
2427
2427
|
* <br>
|
|
@@ -2434,25 +2434,25 @@ class TeraBoxApp {
|
|
|
2434
2434
|
* @async
|
|
2435
2435
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
2436
2436
|
*/
|
|
2437
|
-
async querySurlTransfer(shareId, fromUk){
|
|
2437
|
+
async querySurlTransfer(shareId, fromUk) {
|
|
2438
2438
|
const url = new URL(this.params.whost + '/share/querysurltransfer');
|
|
2439
|
-
|
|
2440
|
-
try{
|
|
2441
|
-
if(this.data.jsToken === ''){
|
|
2439
|
+
|
|
2440
|
+
try {
|
|
2441
|
+
if (this.data.jsToken === '') {
|
|
2442
2442
|
await this.updateAppData();
|
|
2443
2443
|
}
|
|
2444
|
-
|
|
2444
|
+
|
|
2445
2445
|
url.search = new URLSearchParams({
|
|
2446
2446
|
...this.params.app,
|
|
2447
2447
|
jsToken: this.data.jsToken,
|
|
2448
2448
|
'dp-logid': this.data.logid,
|
|
2449
2449
|
bdstoken: this.data.bdstoken,
|
|
2450
2450
|
});
|
|
2451
|
-
|
|
2451
|
+
|
|
2452
2452
|
const formData = new this.FormUrlEncoded();
|
|
2453
2453
|
formData.append('sid', shareId);
|
|
2454
2454
|
formData.append('suk', fromUk);
|
|
2455
|
-
|
|
2455
|
+
|
|
2456
2456
|
const req = await request(url, {
|
|
2457
2457
|
method: 'POST',
|
|
2458
2458
|
body: formData.str(),
|
|
@@ -2464,11 +2464,11 @@ class TeraBoxApp {
|
|
|
2464
2464
|
},
|
|
2465
2465
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
2466
2466
|
});
|
|
2467
|
-
|
|
2467
|
+
|
|
2468
2468
|
if (req.statusCode !== 200) {
|
|
2469
2469
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
2470
2470
|
}
|
|
2471
|
-
|
|
2471
|
+
|
|
2472
2472
|
const rdata = await req.body.json();
|
|
2473
2473
|
return rdata;
|
|
2474
2474
|
}
|
|
@@ -2476,7 +2476,7 @@ class TeraBoxApp {
|
|
|
2476
2476
|
throw new Error('querySurlTransfer', { cause: error });
|
|
2477
2477
|
}
|
|
2478
2478
|
}
|
|
2479
|
-
|
|
2479
|
+
|
|
2480
2480
|
/**
|
|
2481
2481
|
* Transfers (saves) shared files to the user's account
|
|
2482
2482
|
* <br>
|
|
@@ -2493,14 +2493,14 @@ class TeraBoxApp {
|
|
|
2493
2493
|
* @async
|
|
2494
2494
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
2495
2495
|
*/
|
|
2496
|
-
async shareTransfer(shareId, fromUk, fsIds, destPath = '/', options = {}){
|
|
2496
|
+
async shareTransfer(shareId, fromUk, fsIds, destPath = '/', options = {}) {
|
|
2497
2497
|
const url = new URL(this.params.whost + '/share/transfer');
|
|
2498
|
-
|
|
2499
|
-
try{
|
|
2500
|
-
if(this.data.jsToken === ''){
|
|
2498
|
+
|
|
2499
|
+
try {
|
|
2500
|
+
if (this.data.jsToken === '') {
|
|
2501
2501
|
await this.updateAppData();
|
|
2502
2502
|
}
|
|
2503
|
-
|
|
2503
|
+
|
|
2504
2504
|
url.search = new URLSearchParams({
|
|
2505
2505
|
...this.params.app,
|
|
2506
2506
|
jsToken: this.data.jsToken,
|
|
@@ -2510,11 +2510,11 @@ class TeraBoxApp {
|
|
|
2510
2510
|
shareid: shareId,
|
|
2511
2511
|
from: fromUk,
|
|
2512
2512
|
});
|
|
2513
|
-
|
|
2513
|
+
|
|
2514
2514
|
const formData = new this.FormUrlEncoded();
|
|
2515
2515
|
formData.append('fsidlist', JSON.stringify(fsIds));
|
|
2516
2516
|
formData.append('path', destPath);
|
|
2517
|
-
|
|
2517
|
+
|
|
2518
2518
|
const req = await request(url, {
|
|
2519
2519
|
method: 'POST',
|
|
2520
2520
|
body: formData.str(),
|
|
@@ -2526,14 +2526,14 @@ class TeraBoxApp {
|
|
|
2526
2526
|
},
|
|
2527
2527
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
2528
2528
|
});
|
|
2529
|
-
|
|
2529
|
+
|
|
2530
2530
|
if (req.statusCode !== 200) {
|
|
2531
2531
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
2532
2532
|
}
|
|
2533
|
-
|
|
2533
|
+
|
|
2534
2534
|
const rdata = await req.body.json();
|
|
2535
2535
|
// Handle verification errors by refreshing token and retrying
|
|
2536
|
-
if(rdata.errno === 400810){
|
|
2536
|
+
if (rdata.errno === 400810) {
|
|
2537
2537
|
await this.updateAppData();
|
|
2538
2538
|
return await this.shareTransfer(shareId, fromUk, fsIds, destPath, options);
|
|
2539
2539
|
}
|
|
@@ -2543,17 +2543,17 @@ class TeraBoxApp {
|
|
|
2543
2543
|
throw new Error('shareTransfer', { cause: error });
|
|
2544
2544
|
}
|
|
2545
2545
|
}
|
|
2546
|
-
|
|
2546
|
+
|
|
2547
2547
|
/**
|
|
2548
2548
|
* Retrieves the RSA public key from the server for encryption
|
|
2549
2549
|
* @returns {Promise<Object>} The public key response JSON (includes pp1 and pp2)
|
|
2550
2550
|
* @async
|
|
2551
2551
|
* @throws {Error} Throws error if HTTP status is not 200 or request fails
|
|
2552
2552
|
*/
|
|
2553
|
-
async getPublicKey(){
|
|
2553
|
+
async getPublicKey() {
|
|
2554
2554
|
const url = new URL(this.params.whost + '/passport/getpubkey');
|
|
2555
|
-
|
|
2556
|
-
try{
|
|
2555
|
+
|
|
2556
|
+
try {
|
|
2557
2557
|
const req = await request(url, {
|
|
2558
2558
|
method: 'GET',
|
|
2559
2559
|
headers: {
|
|
@@ -2561,17 +2561,17 @@ class TeraBoxApp {
|
|
|
2561
2561
|
},
|
|
2562
2562
|
signal: AbortSignal.timeout(this.TERABOX_TIMEOUT),
|
|
2563
2563
|
});
|
|
2564
|
-
|
|
2564
|
+
|
|
2565
2565
|
if (req.statusCode !== 200) {
|
|
2566
2566
|
throw new Error(`HTTP error! Status: ${req.statusCode}`);
|
|
2567
2567
|
}
|
|
2568
|
-
|
|
2568
|
+
|
|
2569
2569
|
const rdata = await req.body.json();
|
|
2570
|
-
|
|
2571
|
-
if(rdata.code === 0){
|
|
2570
|
+
|
|
2571
|
+
if (rdata.code === 0) {
|
|
2572
2572
|
this.data.pubkey = this.DecryptAES(rdata.data.pp1, rdata.data.pp2);
|
|
2573
2573
|
}
|
|
2574
|
-
|
|
2574
|
+
|
|
2575
2575
|
return rdata;
|
|
2576
2576
|
}
|
|
2577
2577
|
catch (error) {
|