Class: TeraBox

TeraBox(credentials)

new TeraBox(credentials)

Creates an instance of TeraBox
Parameters:
Name Type Description
credentials object The credentials object
Properties
Name Type Attributes Description
ndus string NDUS token (from cookie, used for authentication)
lang string <optional>
Language code (default: 'en')
appId string <optional>
Application ID (from frontend JS, default: '250528')
browserId string <optional>
Browser ID
host string <optional>
API host (default: 'https://terabox.com')
blockId string <optional>
Block ID (from frontend JS, default: '5910a591dd8fc18c32a8f3df4fdc1761')
userAgent string <optional>
User agent string
jsToken string <optional>
JS token (from frontend JS)
Source:

Methods

(async) delete(files) → {Promise.<boolean>}

Deletes one or more files or directories
Parameters:
Name Type Description
files Array.<(TeraBoxDirent|string)> An array of TeraBoxDirent instances or file paths to delete
Source:
Throws:
- Throws an error if an invalid file path is provided or the API call fails
Type
Error
Returns:
- Returns true regardless of success or failure
Type
Promise.<boolean>
Example
```js
// Use an instance of TeraBoxDirent
const files = await tb.list('/')
await tb.delete([files[0]])

// Use file paths directly
await tb.delete(['/path/to/file1.txt', '/path/to/file2.txt'])
```

(async) download(fileIds) → {Promise.<Array.<{id: number, link: string}>>}

Downloads one or more files
Parameters:
Name Type Description
fileIds Array.<(TeraBoxDirent|string|number)>
Source:
Throws:
- Throws an error if an invalid fileId is provided or the API call fails
Type
Error
Returns:
Type
Promise.<Array.<{id: number, link: string}>>
Example
```js
// Use an instance of TeraBoxDirent
const files = await tb.list('/')
await tb.download([files[0]])

// Use file IDs directly
await tb.download([1234])
```

(async) list(directoryopt) → {Promise.<Array.<TeraBoxDirent>>}

Fetches the list of dirents in the specified directory
Parameters:
Name Type Attributes Default Description
directory string <optional>
'/'
Source:
Throws:
- Throws an error if the API call fails
Type
Error
Returns:
Type
Promise.<Array.<TeraBoxDirent>>
Example
```js
await tb.list('/')
```

(async) move(files) → {Promise.<boolean>}

Moves one or more files to their specified paths
Parameters:
Name Type Description
files object An object mapping source paths to target paths
Source:
Throws:
- Throws an error if the API call fails
Type
Error
Returns:
- Returns true regardless of success or failure
Type
Promise.<boolean>
Example
const files = {
      '/path/to/source/file1.txt': '/path/to/destination/file1.txt',
      '/path/to/source/file2.txt': '/path/to/destination/file2.txt'
  }

(async) quota() → {object.<{used: number, total: number, free: number}>}

Fetches quota information (used, total, free space)
Source:
Throws:
- Throws an error if the API call fails
Type
Error
Returns:
Type
object.<{used: number, total: number, free: number}>
Example
```js
await tb.quota()
```

(async) stream(filePath, typeopt) → {Promise.<string>}

Streams a video file
Parameters:
Name Type Attributes Default Description
filePath TeraBoxDirent | string
type string <optional>
'M3U8_FLV_264_480' Stream quality (default is 'M3U8_FLV_264_480', while 'M3U8_FLV_264_360' is also available)
Source:
Throws:
- Throws an error if an invalid file path is provided or the API call fails
Type
Error
Returns:
- Returns the HLS M3U8 playlist
Type
Promise.<string>
Example
```js
// Use an instance of TeraBoxDirent
const files = await tb.list('/')
const file = files[0]
await file.stream('M3U8_FLV_264_480')

// Use file path directly
await tb.stream('/path/to/video.mp4', 'M3U8_FLV_264_480')
```

(async) upload(filePath, fileBody) → {Promise.<TeraBoxDirent>}

Uploads a file buffer to the specified path
Parameters:
Name Type Description
filePath string
fileBody Buffer
Source:
Throws:
- Throws an error if the API call fails
Type
Error
Returns:
Type
Promise.<TeraBoxDirent>
Example
```js
await tb.upload('/path/to/file.txt', fs.readFileSync('/path/to/file.txt'))
```