terabox-upload-tool 1.3.1 → 1.4.1
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/README.md +43 -205
- package/lib/helpers/download/download.js +16 -33
- package/lib/helpers/download/downloadHelper.js +40 -120
- package/lib/helpers/fileDelete.js +4 -17
- package/lib/helpers/fileMove.js +4 -17
- package/lib/helpers/getShortUrl.js +30 -44
- package/lib/helpers/utils.js +9 -29
- package/lib/index.js +96 -162
- package/package.json +1 -1
- package/test_all.js +79 -0
- package/examples/createfolder.js +0 -27
- package/examples/dl-test.js +0 -97
- package/examples/example.js +0 -59
package/examples/dl-test.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
async function getDownloadLink(fidlist, { jstoken, appid, sign, timestamp, bdstoken }) {
|
|
2
|
-
const apiUrls = {
|
|
3
|
-
sysCfg: 'https://www.terabox.com/api/getsyscfg',
|
|
4
|
-
homeInfo: 'https://www.terabox.com/api/home/info',
|
|
5
|
-
download: 'https://www.terabox.com/api/download'
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
const dpLogIds = {
|
|
9
|
-
sysCfg: '18397400250736220038',
|
|
10
|
-
homeInfo: '18397400250736220039',
|
|
11
|
-
download: '18397400250736220040'
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const appParams = {
|
|
15
|
-
app_id: appid,
|
|
16
|
-
web: '1',
|
|
17
|
-
channel: 'dubox',
|
|
18
|
-
clienttype: '0',
|
|
19
|
-
jsToken: jstoken,
|
|
20
|
-
version: '0',
|
|
21
|
-
language_type: 'ja'
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const downloadParams = {
|
|
25
|
-
sign,
|
|
26
|
-
timestamp,
|
|
27
|
-
need_speed: '0',
|
|
28
|
-
vip: '2',
|
|
29
|
-
bdstoken
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
// sysCfg API
|
|
34
|
-
const sysCfgResponse = await fetch(`${apiUrls.sysCfg}?${new URLSearchParams({
|
|
35
|
-
...appParams,
|
|
36
|
-
'dp-logid': dpLogIds.sysCfg,
|
|
37
|
-
cfg_category_keys: '[{"cfg_category_key":"web_download_to_pc_exp_flow_new","cfg_version":1},{"cfg_category_key":"web_download_to_pc","cfg_version":1}]'
|
|
38
|
-
})}`, {
|
|
39
|
-
method: 'GET',
|
|
40
|
-
headers: { 'Content-Type': 'application/json' }
|
|
41
|
-
});
|
|
42
|
-
const sysCfg = await sysCfgResponse.json();
|
|
43
|
-
console.log('System Configuration:', sysCfg);
|
|
44
|
-
|
|
45
|
-
// homeInfo API
|
|
46
|
-
const homeInfoResponse = await fetch(`${apiUrls.homeInfo}?${new URLSearchParams({
|
|
47
|
-
...appParams,
|
|
48
|
-
'dp-logid': dpLogIds.homeInfo
|
|
49
|
-
})}`, {
|
|
50
|
-
method: 'GET',
|
|
51
|
-
headers: { 'Content-Type': 'application/json' }
|
|
52
|
-
});
|
|
53
|
-
const homeInfo = await homeInfoResponse.json();
|
|
54
|
-
console.log('Home Info:', homeInfo);
|
|
55
|
-
|
|
56
|
-
// download API
|
|
57
|
-
const downloadResponse = await fetch(`${apiUrls.download}?${new URLSearchParams({
|
|
58
|
-
...appParams,
|
|
59
|
-
'dp-logid': dpLogIds.download,
|
|
60
|
-
fidlist: JSON.stringify(fidlist),
|
|
61
|
-
type: 'dlink',
|
|
62
|
-
...downloadParams
|
|
63
|
-
})}`, {
|
|
64
|
-
method: 'GET',
|
|
65
|
-
headers: { 'Content-Type': 'application/json' }
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
const downloadData = await downloadResponse.json();
|
|
69
|
-
if (downloadData.dlink && downloadData.dlink.length > 0) {
|
|
70
|
-
return downloadData.dlink[0].dlink;
|
|
71
|
-
} else {
|
|
72
|
-
throw new Error('Download link not found.');
|
|
73
|
-
}
|
|
74
|
-
} catch (error) {
|
|
75
|
-
console.error('Error:', error);
|
|
76
|
-
throw error;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// 使用例
|
|
81
|
-
(async () => {
|
|
82
|
-
try {
|
|
83
|
-
const fidlist = [217911186381995]; // ダウンロード対象のファイルIDリスト
|
|
84
|
-
const params = {
|
|
85
|
-
jstoken: '3F3649BB89A2A6A09BB50936F9C72BF1D8AD957C2C90DFD89F8213A3150FB8BCCDEB94CC4F3F3D863287FE9BCA60922AF06C81F36045A823C1DD16CF69961185',
|
|
86
|
-
appid: '250528',
|
|
87
|
-
sign: '9BIWaJUNH2mrAjROBAjPpwF0/WLwaTnXJEbm3pJV43xiH8fwL33T1g==',
|
|
88
|
-
timestamp: '1738037365',
|
|
89
|
-
bdstoken: '43bfe2c66a09d4e4561d68d6f4f10340'
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const downloadLink = await getDownloadLink(fidlist, params);
|
|
93
|
-
console.log('Download Link:', downloadLink);
|
|
94
|
-
} catch (error) {
|
|
95
|
-
console.error('Error:', error);
|
|
96
|
-
}
|
|
97
|
-
})();
|
package/examples/example.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
// Import the TeraboxUploader class from your library
|
|
2
|
-
const TeraboxUploader = require('./index'); // Make sure to use the correct path to your module
|
|
3
|
-
|
|
4
|
-
// Step 1: Set up your Terabox credentials
|
|
5
|
-
const credentials = {
|
|
6
|
-
ndus: 'your-ndus-token', // Replace with your actual ndus token
|
|
7
|
-
appId: 'your-app-id', // Replace with your actual appId
|
|
8
|
-
uploadId: 'your-upload-id', // Replace with your actual uploadId
|
|
9
|
-
jsToken: 'your-js-token', // Replace with your jsToken
|
|
10
|
-
browserId: 'your-browser-id' // Replace with your browserId
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
// Step 2: Create a new instance of the TeraboxUploader with your credentials
|
|
14
|
-
const uploader = new TeraboxUploader(credentials);
|
|
15
|
-
|
|
16
|
-
// Step 3: Define the file you want to upload (replace with the path to your file)
|
|
17
|
-
const filePath = './path/to/your/file.txt'; // Example: './myDocuments/photo.jpg'
|
|
18
|
-
|
|
19
|
-
// Step 4: (Optional) Track upload progress with a simple callback function
|
|
20
|
-
// This will show how much of the file has been uploaded
|
|
21
|
-
const showProgress = (loaded, total) => {
|
|
22
|
-
const percentage = ((loaded / total) * 100).toFixed(2);
|
|
23
|
-
console.log(`Uploading... ${percentage}% complete`);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// Step 5: Upload the file
|
|
27
|
-
async function uploadFile() {
|
|
28
|
-
try {
|
|
29
|
-
// Upload the file to Terabox, specify a directory (optional)
|
|
30
|
-
const result = await uploader.uploadFile(filePath, showProgress, '/myUploads'); // Change '/myUploads' to your desired directory
|
|
31
|
-
|
|
32
|
-
// Check if the upload was successful
|
|
33
|
-
if (result.success) {
|
|
34
|
-
console.log('File uploaded successfully!');
|
|
35
|
-
console.log('File details:', result.fileDetails); // Show details of the uploaded file
|
|
36
|
-
} else {
|
|
37
|
-
console.log('Upload failed:', result.message); // Show error message
|
|
38
|
-
}
|
|
39
|
-
} catch (error) {
|
|
40
|
-
console.log('An error occurred during the upload:', error.message); // Handle any errors
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Step 6: Fetch a list of files from Terabox (optional)
|
|
45
|
-
async function fetchFileList() {
|
|
46
|
-
try {
|
|
47
|
-
// Get a list of files from your Terabox account
|
|
48
|
-
const fileList = await uploader.fetchFileList('/myUploads'); // Specify the directory to list files
|
|
49
|
-
console.log('Files in your directory:', fileList); // Show the list of files
|
|
50
|
-
} catch (error) {
|
|
51
|
-
console.log('Error fetching file list:', error.message); // Handle any errors
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Step 7: Call the functions to upload the file and/or fetch the file list
|
|
56
|
-
|
|
57
|
-
// uploadFile(); // Upload the file
|
|
58
|
-
|
|
59
|
-
fetchFileList(); //Fetch files
|