terabox-upload-tool 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025,
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,28 +1,25 @@
1
1
  # Terabox Upload Tool
2
2
 
3
- A simple and efficient Node.js library for uploading files to [TeraBox](https://www.terabox.com/wap) storage. This tool streamlines the process of file uploads while offering customization options such as directory selection.
3
+ A simple and efficient Node.js library for uploading files and fetching file list from [TeraBox](https://www.terabox.com/wap) storage. This tool streamlines the process of file uploads while offering customization options such as directory selection.
4
4
 
5
5
  ## Features
6
6
 
7
7
  * File Upload: Easily upload files to Terabox storage.
8
8
  * Custom Directory Support: Specify the directory where the file should be uploaded.
9
9
  * Progress Tracking: Monitor the upload progress in real-time.
10
-
10
+ * Fetch File List: Fetch file list from any directory.
11
11
 
12
12
  ## Coming Soon (Open for Collaboration)
13
13
 
14
- * Fetch Files: Retrieve the files stored in your Terabox account.
14
+ * Fetch Files: Retrieve the resources download URL and add URL Path in JSON object returned by exiting [fetchFileList() ](./lib/index.js)method .
15
15
  * Delete Files: Remove files from your Terabox storage directly using this library.
16
16
 
17
-
18
-
19
17
  ## Installation
20
18
 
21
19
  Install the package using npm:
22
20
 
23
21
  ```bash
24
22
  npm install terabox-upload-tool
25
-
26
23
  ```
27
24
 
28
25
  ## Getting Started
@@ -39,7 +36,9 @@ const credentials = {
39
36
  };
40
37
 
41
38
  ```
39
+
42
40
  ### Uploading a File
41
+
43
42
  To upload a file, create an instance of TeraboxUploader and specify the file path.
44
43
 
45
44
  #### Example: Save File to a Specific Directory
@@ -47,44 +46,56 @@ To upload a file, create an instance of TeraboxUploader and specify the file pat
47
46
  ```javascript
48
47
  const uploader = new TeraboxUploader(credentials);
49
48
 
50
- const filePath = './path/to/your/file.jpg';
49
+ async function uploadFile() {
50
+ try {
51
+ const result = await uploader.uploadFile(filePath, showProgress, '/myUploads');
52
+ if (result.success) {
53
+ console.log('File uploaded successfully!');
54
+ console.log('File details:', result.fileDetails);
55
+ } else {
56
+ console.log('Upload failed:', result.message);
57
+ }
58
+ } catch (error) {
59
+ console.log('An error occurred during the upload:', error.message);
60
+ }
61
+ }
51
62
 
52
- // Uploads to '/my-uploads'
53
- uploader.uploadFile(filePath, (uploaded, total) => {
54
- console.log(`Progress: ${(uploaded / total * 100).toFixed(2)}%`);
55
- }, '/my-uploads');
56
63
  ```
57
64
 
58
- #### Example: Save File to Root Directly
65
+ #### Example: Fetch a list of files from Terabox
59
66
 
60
67
  ```javascript
61
-
62
- // Uploads to '/'
63
- uploader.uploadFile(filePath, (uploaded, total) => {
64
- console.log(`Progress: ${(uploaded / total * 100).toFixed(2)}%`);
65
- }, '/my-uploads');
68
+ async function fetchFileList() {
69
+ try {
70
+ const fileList=await uploader.fetchFileList('/myUploads');
71
+ console.log('Files in your directory:', fileList);
72
+ } catch (error) {
73
+ console.log('Error fetching file list:', error.message);
74
+ }
75
+ }
66
76
  ```
67
77
 
68
- ## Future Enhancements (Open Collaboration)
78
+ Future Enhancements (Open Collaboration)
79
+
69
80
  We are actively seeking contributors to add the following features:
70
81
 
71
82
  1. Fetch Files:
72
- * Implement functionality to list files stored in Terabox directories.
73
- * Provide options to filter by file types, size, or date modified.
74
83
 
84
+ * Provide options to filter by file types, size, or date modified.
85
+ * Need to Implement add resouces URL in file list objects.
75
86
  2. Delete Files:
76
- * Enable users to delete specific files or directories from their Terabox storage.
77
- * Include safeguards like confirmation prompts before deletion.
78
87
 
88
+ * Enable users to delete specific files or directories from their Terabox storage.
89
+ * Include safeguards like confirmation prompts before deletion.
79
90
  3. Error Handling Enhancements:
80
- * Improve error messages for easier debugging and user guidance.
81
91
 
92
+ * Improve error messages for easier debugging and user guidance.
82
93
  4. Automated Tests:
83
- * Add test cases to ensure reliability and robustness.
84
94
 
95
+ * Add test cases to ensure reliability and robustness.
85
96
  5. Documentation Updates:
86
97
 
87
- * Expand guides with screenshots and example workflows.
98
+ * Expand guides with screenshots and example workflows.
88
99
 
89
100
  ## Contribution Guidelines
90
101
 
@@ -96,10 +107,10 @@ We welcome contributions from the community! Here’s how you can get started:
96
107
  4. Feel free to open issues for feature requests or bug reports.
97
108
 
98
109
  ## Resources for Developers
110
+
99
111
  * [Node.js File System Documentation](https://nodejs.org/api/fs.html)
100
112
  * [Chrome Dev-Tools (Networks)](https://developer.chrome.com/docs/devtools/network)
101
113
 
102
-
103
114
  <br>
104
115
 
105
116
  Terabox Node.js Library
@@ -146,12 +157,6 @@ Get the 'ndus' from cookies in the header section
146
157
  <br>
147
158
  <br>
148
159
 
149
-
150
-
151
-
152
160
  ## Licence
153
161
 
154
- This project is licensed under the [MIT License.]()
155
-
156
-
157
-
162
+ This project is licensed under the [MIT License.](./LICENSE)
@@ -0,0 +1,118 @@
1
+ // syscfg APIへのリクエスト
2
+ async function getSysCfg() {
3
+ const url = 'https://www.terabox.com/api/getsyscfg';
4
+ const params = {
5
+ app_id: '250528',
6
+ web: '1',
7
+ channel: 'dubox',
8
+ clienttype: '0',
9
+ jsToken: 'BDFC7E99221F980D72CA17B19C98F23E35D1C43EBD1B76F2CE493F27A1C2E7C71D7F637156999EF9A71106D82A4836DE040DA96397B95B7F95DDE4836EA0766B',
10
+ 'dp-logid': '18397400250736220038',
11
+ 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}]',
12
+ version: '0',
13
+ language_type: 'ja'
14
+ };
15
+
16
+ const response = await fetch(`${url}?${new URLSearchParams(params)}`, {
17
+ method: 'GET',
18
+ headers: {
19
+ 'Content-Type': 'application/json'
20
+ }
21
+ });
22
+
23
+ const data = await response.json();
24
+ return data;
25
+ }
26
+
27
+ // home info APIへのリクエスト
28
+ async function getHomeInfo() {
29
+ const url = 'https://www.terabox.com/api/home/info';
30
+ const params = {
31
+ app_id: '250528',
32
+ web: '1',
33
+ channel: 'dubox',
34
+ clienttype: '0',
35
+ jsToken: 'BDFC7E99221F980D72CA17B19C98F23E35D1C43EBD1B76F2CE493F27A1C2E7C71D7F637156999EF9A71106D82A4836DE040DA96397B95B7F95DDE4836EA0766B',
36
+ 'dp-logid': '18397400250736220039'
37
+ };
38
+
39
+ const response = await fetch(`${url}?${new URLSearchParams(params)}`, {
40
+ method: 'GET',
41
+ headers: {
42
+ 'Content-Type': 'application/json'
43
+ }
44
+ });
45
+
46
+ const data = await response.json();
47
+ return data;
48
+ }
49
+
50
+ // ダウンロードURL取得のための関数
51
+ async function getDownloadUrl(fidlist) {
52
+ const sysCfg = await getSysCfg();
53
+ const homeInfo = await getHomeInfo();
54
+
55
+ console.log('System Configuration:', sysCfg);
56
+ console.log('Home Info:', homeInfo);
57
+
58
+ const downloadUrl = 'https://www.terabox.com/api/download';
59
+
60
+ // ダウンロードパラメータの設定
61
+ const params = {
62
+ app_id: '250528',
63
+ web: '1',
64
+ channel: 'dubox',
65
+ clienttype: '0',
66
+ jsToken: 'BDFC7E99221F980D72CA17B19C98F23E35D1C43EBD1B76F2CE493F27A1C2E7C71D7F637156999EF9A71106D82A4836DE040DA96397B95B7F95DDE4836EA0766B',
67
+ 'dp-logid': '18397400250736220040',
68
+ fidlist: JSON.stringify(fidlist), // fidlistを渡す
69
+ type: 'dlink',
70
+ vip: '2',
71
+ sign: 'VeJPxoh1ryXIWRvdcBXzMXJvl9iJMry0sUyKk7FrD5ohO4wghBmZ7w==',
72
+ timestamp: '1737845700',
73
+ need_speed: '0',
74
+ bdstoken: 'bbc878665ecd53f583ce583d16deddd9'
75
+ };
76
+
77
+ // ダウンロードリクエスト送信
78
+ const response = await fetch(`${downloadUrl}?${new URLSearchParams(params)}`, {
79
+ method: 'GET',
80
+ headers: {
81
+ 'Content-Type': 'application/json'
82
+ }
83
+ });
84
+
85
+ const data = await response.json();
86
+
87
+ // ダウンロードリンクが存在する場合、リンクを返す
88
+ if (data.dlink && data.dlink.length > 0) {
89
+ return data.dlink[0].dlink;
90
+ } else {
91
+ throw new Error('Download link not found.');
92
+ }
93
+ }
94
+
95
+ // `dlFiles` 関数: ダウンロードリンクを返す
96
+ async function dlFiles(fidlist) {
97
+ try {
98
+ const downloadLink = await getDownloadUrl(fidlist);
99
+ return downloadLink;
100
+ } catch (error) {
101
+ console.error('Error:', error);
102
+ throw error; // エラーがあった場合は再度投げる
103
+ }
104
+ }
105
+
106
+ // 使用例
107
+ (async () => {
108
+ try {
109
+ const fidlist = [546136331131393]; // ダウンロード対象のファイルIDリスト
110
+ const downloadLink = await dlFiles(fidlist);
111
+ console.log('Download Link:', downloadLink);
112
+
113
+ // ダウンロードリンクが取得できたら、URLを返す
114
+ return downloadLink;
115
+ } catch (error) {
116
+ console.error('Error:', error);
117
+ }
118
+ })();
@@ -1,24 +1,57 @@
1
- const TeraboxUploader = require('terabox-upload-tool');
1
+ // Import the TeraboxUploader class from your library
2
+ const TeraboxUploader = require('./index'); // Make sure to use the correct path to your module
2
3
 
3
- // Set up credentials for your account
4
+ // Step 1: Set up your Terabox credentials
4
5
  const credentials = {
5
- ndus: 'valid_ndus',
6
- appId: 'valid_appId',
7
- uploadId: 'valid_uploadId'
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
8
9
  };
9
10
 
11
+ // Step 2: Create a new instance of the TeraboxUploader with your credentials
10
12
  const uploader = new TeraboxUploader(credentials);
11
13
 
12
- // Upload a file
13
- const filePath = './path/to/your/file.jpg';
14
+ // Step 3: Define the file you want to upload (replace with the path to your file)
15
+ const filePath = './path/to/your/file.txt'; // Example: './myDocuments/photo.jpg'
14
16
 
17
+ // Step 4: (Optional) Track upload progress with a simple callback function
18
+ // This will show how much of the file has been uploaded
19
+ const showProgress = (loaded, total) => {
20
+ const percentage = ((loaded / total) * 100).toFixed(2);
21
+ console.log(`Uploading... ${percentage}% complete`);
22
+ };
23
+
24
+ // Step 5: Upload the file
25
+ async function uploadFile() {
26
+ try {
27
+ // Upload the file to Terabox, specify a directory (optional)
28
+ const result = await uploader.uploadFile(filePath, showProgress, '/myUploads'); // Change '/myUploads' to your desired directory
29
+
30
+ // Check if the upload was successful
31
+ if (result.success) {
32
+ console.log('File uploaded successfully!');
33
+ console.log('File details:', result.fileDetails); // Show details of the uploaded file
34
+ } else {
35
+ console.log('Upload failed:', result.message); // Show error message
36
+ }
37
+ } catch (error) {
38
+ console.log('An error occurred during the upload:', error.message); // Handle any errors
39
+ }
40
+ }
41
+
42
+ // Step 6: Fetch a list of files from Terabox (optional)
43
+ async function fetchFileList() {
44
+ try {
45
+ // Get a list of files from your Terabox account
46
+ const fileList = await uploader.fetchFileList('/myUploads'); // Specify the directory to list files
47
+ console.log('Files in your directory:', fileList); // Show the list of files
48
+ } catch (error) {
49
+ console.log('Error fetching file list:', error.message); // Handle any errors
50
+ }
51
+ }
52
+
53
+ // Step 7: Call the functions to upload the file and/or fetch the file list
15
54
 
16
- // Save file in a specific directory, e.g., '/my-uploads'
17
- uploader.uploadFile(filePath, (uploaded, total) => {
18
- console.log(`Progress: ${(uploaded / total * 100).toFixed(2)}%`);
19
- }, '/my-uploads');
55
+ // uploadFile(); // Upload the file
20
56
 
21
- // Save file in the root directory (default behavior)
22
- uploader.uploadFile(filePath, (uploaded, total) => {
23
- console.log(`Progress: ${(uploaded / total * 100).toFixed(2)}%`);
24
- });
57
+ fetchFileList(); //Fetch files
package/lib/index.js CHANGED
@@ -2,10 +2,10 @@ const axios = require('axios');
2
2
  const path = require('path');
3
3
  const fs = require('fs');
4
4
  const FormData = require('form-data');
5
- const { buildUploadUrl, buildCreateUrl } = require('./utils');
5
+ const { buildUploadUrl, buildCreateUrl, buildListUrl } = require('./utils');
6
6
 
7
7
  /**
8
- * Class to handle Terabox file upload
8
+ * Class to handle Terabox file operations
9
9
  */
10
10
  class TeraboxUploader {
11
11
  constructor(credentials) {
@@ -26,6 +26,10 @@ class TeraboxUploader {
26
26
  * @param {string} filePath - Path to the file to be uploaded
27
27
  * @param {function} progressCallback - Optional callback to track upload progress
28
28
  * @param {string} [directory='/'] - Optional directory where the file will be saved on Terabox
29
+ * @returns {Promise<{success: boolean, message: string, fileDetails?: object}>} - A promise that resolves to an object indicating the result of the upload:
30
+ * - `success` (boolean): `true` if the upload was successful, `false` otherwise.
31
+ * - `message` (string): A message with the upload status (success or error).
32
+ * - `fileDetails` (optional object): The details of the file uploaded, returned only if the upload was successful.
29
33
  */
30
34
  async uploadFile(filePath, progressCallback, directory = '/') {
31
35
  try {
@@ -53,8 +57,6 @@ class TeraboxUploader {
53
57
  },
54
58
  });
55
59
 
56
- console.log('File chunk upload response:', postResponse.data);
57
-
58
60
  // Finalize the upload (Create call)
59
61
  const createUrl = buildCreateUrl();
60
62
  const createResponse = await axios.post(createUrl, new URLSearchParams({
@@ -71,9 +73,43 @@ class TeraboxUploader {
71
73
  },
72
74
  });
73
75
 
74
- console.log('Create response:', createResponse.data);
76
+ // Return success message
77
+ return {
78
+ success: true,
79
+ message: 'File uploaded successfully.',
80
+ fileDetails: createResponse.data,
81
+ };
82
+ } catch (error) {
83
+ console.error('Error during upload process:', error.response?.data || error.message || error);
84
+
85
+ // Return failure message
86
+ return {
87
+ success: false,
88
+ message: error.response?.data || error.message,
89
+ };
90
+ }
91
+ }
92
+
93
+
94
+ /**
95
+ * Fetches the file list from Terabox
96
+ * @param {string} directory - Directory to fetch the file list from (e.g., "/")
97
+ * @returns {Promise<object>} - JSON response from the API
98
+ */
99
+ async fetchFileList(directory = '/') {
100
+ try {
101
+ const listUrl = buildListUrl(this.credentials.appId, directory);
102
+
103
+ const response = await axios.get(listUrl, {
104
+ headers: {
105
+ Cookie: this.credentials.cookies,
106
+ },
107
+ });
108
+
109
+ return response.data;
75
110
  } catch (error) {
76
- console.error('Error during upload process:', error.response?.data || error.message);
111
+ console.error('Error fetching file list:', error.response?.data || error.message);
112
+ throw error;
77
113
  }
78
114
  }
79
115
  }
package/lib/utils.js CHANGED
@@ -17,4 +17,14 @@ function buildCreateUrl() {
17
17
  return 'https://www.1024terabox.com/api/create';
18
18
  }
19
19
 
20
- module.exports = { buildUploadUrl, buildCreateUrl };
20
+ /**
21
+ * Builds the URL for fetching the file list.
22
+ * @param {string} appId - The application ID
23
+ * @param {string} directory - The directory path to fetch the file list from
24
+ * @returns {string} - The file list URL
25
+ */
26
+ function buildListUrl(appId, directory) {
27
+ return `https://www.1024terabox.com/api/list?app_id=${appId}&web=1&channel=dubox&clienttype=0&order=time&desc=1&dir=${encodeURIComponent(directory)}&num=100&page=1&showempty=0`;
28
+ }
29
+
30
+ module.exports = { buildUploadUrl, buildCreateUrl, buildListUrl };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "terabox-upload-tool",
3
- "version": "1.0.0",
4
- "description": "A Node.js library to upload files to Terabox",
3
+ "version": "1.1.0",
4
+ "description": "git add",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"