new TeraBox(credentials)
Creates an instance of TeraBox
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
credentials |
object | The credentials object
Properties
|
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 |
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)> |
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> |
'/' |
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 |
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)
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) |
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 |
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'))
```