TeraBoxApp

api~ TeraBoxApp

TeraBoxApp API client class Provides a comprehensive interface for interacting with TeraBox services, including encryption utilities, API request handling, and session management.

Constructor

new TeraBoxApp(authData, authTypeopt)

Description:
  • Creates a new TeraBoxApp instance
Source:
Properties:
Name Type Description
FormUrlEncoded FormUrlEncoded Form URL encoding utility
SignDownload signDownload Download signature generator
CheckMd5Val checkMd5val MD5 hash validator (single)
CheckMd5Arr checkMd5arr MD5 hash validator (array)
DecodeMd5 decodeMd5 Custom MD5 transformation
ChangeBase64Type changeBase64Type Base64 format converter
DecryptAES decryptAES AES decryption utility
EncryptRSA encryptRSA RSA encryption utility
PRandGen prandGen Pseudo-random hash generator
TERABOX_DOMAIN string Default TeraBox domain
TERABOX_TIMEOUT number Default API timeout (10 seconds)
data Object Application data including tokens and keys
Properties
Name Type Description
csrf string CSRF token
logid string Log ID
pcftoken string PCF token
bdstoken string BDS token
jsToken string JavaScript token
pubkey string Public key
params TeraBoxAppParams Application parameters and configuration
Parameters:
Name Type Attributes Default Description
authData string Authentication data (NDUS token)
authType string <optional>
'ndus' Authentication type (currently only 'ndus' supported)
Throws:
Throws error if authType is not supported
Type
Error

Methods

(async) updateAppData(customPathopt, retriesopt) → {Promise.<Object>}

Description:
  • Updates application data including tokens and user information
Source:
Parameters:
Name Type Attributes Default Description
customPath string <optional>
Custom path to use for the update request
retries number <optional>
4 Number of retry attempts
Throws:
Throws error if request fails or parsing fails
Type
Error
Returns:
The updated template data
Type
Promise.<Object>

setVipDefaults() → {void}

Description:
  • Sets default VIP parameters
Source:
Returns:
Type
void

(async) doReq(req_url, req_optionsopt, retriesopt) → {Promise.<Object>}

Description:
  • Makes an API request with retry logic
Source:
Parameters:
Name Type Attributes Default Description
req_url string The request URL (relative to whost)
req_options Object <optional>
{} Request options (headers, body, etc.)
retries number <optional>
4 Number of retry attempts
Throws:
Throws error if all retries fail
Type
Error
Returns:
The JSON-parsed response data
Type
Promise.<Object>

(async) getSysCfg() → {Promise.<Object>}

Description:
  • Retrieves system configuration from the TeraBox API
Source:
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The system configuration JSON data
Type
Promise.<Object>

(async) checkLogin() → {Promise.<CheckLoginResponse>}

Description:
  • Checks login status of the current session.
Source:
Throws:
Throws error if HTTP status is not 200 or request fails.
Type
Error
Returns:
The login status JSON data.
Type
Promise.<CheckLoginResponse>

(async) passportPreLogin(email) → {Promise.<Object>}

Description:
  • Initiates the pre-login step for passport authentication
Source:
Parameters:
Name Type Description
email string The user's email address
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The pre-login data JSON (includes seval, random, timestamp)
Type
Promise.<Object>

(async) passportLogin(preLoginData, email, pass) → {Promise.<Object>}

Description:
  • Completes the passport login process using preLoginData and password
Source:
Parameters:
Name Type Description
preLoginData Object Data returned from passportPreLogin
Properties
Name Type Description
seval string The seval value from pre-login.
random string The random value from pre-login.
timestamp number The timestamp from pre-login.
email string The user's email address
pass string The user's plaintext password
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The login response JSON (includes ndus token on success)
Type
Promise.<Object>

(async) regSendCode(email) → {Promise.<Object>}

Description:
  • Sends a registration code to the specified email
Source:
Parameters:
Name Type Description
email string The email address to send the code to
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The send code response JSON (includes code and message)
Type
Promise.<Object>

(async) regVerify(regToken, code) → {Promise.<Object>}

Description:
  • Verifies the registration code received via email
Source:
Parameters:
Name Type Description
regToken string Registration token from send code response
code string | number The verification code sent to email
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The verification response JSON
Type
Promise.<Object>

(async) regFinish(regToken, pass) → {Promise.<Object>}

Description:
  • Completes the registration process by setting a password
Source:
Parameters:
Name Type Description
regToken string Registration token from verification step
pass string The new password to set, length is 6-15 and contains at least 1 Latin letter
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The finish registration response JSON (includes ndus token on success)
Type
Promise.<Object>

(async) passportGetInfo() → {Promise.<Object>}

Description:
  • Retrieves passport user information for the current session
Source:
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The passport user info JSON (includes display_name)
Type
Promise.<Object>

(async) userMembership() → {Promise.<Object>}

Description:
  • Fetches membership information for the current user
Source:
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The membership JSON (includes VIP status)
Type
Promise.<Object>

(async) getCurrentUserInfo() → {Promise.<Object>}

Description:
  • Retrieves current user information (username, VIP status)
Source:
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The user info JSON (includes records array)
Type
Promise.<Object>

(async) getUserInfo(user_id) → {Promise.<Object>}

Description:
  • Retrieves information for a specific user ID
Source:
Parameters:
Name Type Description
user_id number | string The user ID to look up
Throws:
Throws error if user_id is invalid, HTTP status is not 200, or request fails
Type
Error
Returns:
The user info JSON (includes data)
Type
Promise.<Object>

(async) getQuota() → {Promise.<Object>}

Description:
  • Retrieves storage quota information for the current account
Source:
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The quota JSON (includes total, used, available)
Type
Promise.<Object>

(async) getCoinsCount() → {Promise.<Object>}

Description:
  • Retrieves the user's coins count (points)
Source:
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The coins count JSON (includes records of coin usage)
Type
Promise.<Object>

(async) getRemoteDir(remoteDir, pageopt) → {Promise.<Object>}

Description:
  • Retrieves the contents of a remote directory
Source:
Parameters:
Name Type Attributes Default Description
remoteDir string Remote directory path to list
page number <optional>
1 Page number for pagination
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The directory listing JSON (includes entries array)
Type
Promise.<Object>

(async) getCategoryList(categoryIdopt, remoteDir, pageopt) → {Promise.<Object>}

Description:
  • Retrieves the contents of a remote directory with specific file category
Source:
Parameters:
Name Type Attributes Default Description
categoryId number <optional>
1 selected category:
1: video
2: audio
3: pictures
4: documents
5: apps
6: other
7: torrent
remoteDir string / Remote directory path to list
page number <optional>
1 Page number for pagination
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The directory listing JSON (includes entries array)
Type
Promise.<Object>

(async) getRecycleBin() → {Promise.<Object>}

Description:
  • Retrieves the contents of the recycle bin
Source:
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The recycle bin listing JSON (includes entries array)
Type
Promise.<Object>

(async) clearRecycleBin() → {Promise.<Object>}

Description:
  • Clears all items in the recycle bin
Source:
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The clear recycle bin response JSON
Type
Promise.<Object>

(async) precreateFile(data) → {Promise.<Object>}

Description:
  • Initiates a precreate request for a file (reserve upload ID and pre-upload checks)
Source:
Parameters:
Name Type Description
data Object File data including remote_dir, file, size, upload_id (optional), and hash info
Properties
Name Type Attributes Description
remote_dir string Remote directory path
file string Filename
size number File size in bytes
upload_id string <optional>
Existing upload ID for resuming
hash Object Hash information
Properties
Name Type Description
file string MD5 hash of full file
slice string MD5 hash of first slice
crc32 number CRC32 value
chunks Array.<string> Array of MD5 chunk hashes
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The precreate response JSON (includes upload_id, etc.)
Type
Promise.<Object>

(async) rapidUpload(data) → {Promise.<Object>}

Description:
  • Attempts a rapid upload using existing file hashes (skip actual upload if file already on server)
Source:
Parameters:
Name Type Description
data Object File data including remote_dir, file, size, and hash info
Properties
Name Type Description
remote_dir string Remote directory path
file string Filename
size number File size in bytes
hash Object Hash information
Properties
Name Type Attributes Description
file string MD5 hash of full file
slice string MD5 hash of first slice
crc32 number CRC32 value
chunks Array.<string> <optional>
Array of MD5 chunk hashes
Throws:
Throws error if file size < 256KB, invalid hashes, HTTP status is not 200, or request fails
Type
Error
Returns:
The rapid upload response JSON (indicates success or fallback)
Type
Promise.<Object>

(async) remoteUpload(urls, remote_dir) → {Promise.<Object>}

Description:
  • Attempts a upload file from remote server
Source:
Parameters:
Name Type Default Description
urls string Source urls (coma-separated)
remote_dir string /Remote Upload Remote directory path
Throws:
Throws error if HTTP status is not 200, or request fails
Type
Error
Returns:
The remote upload response JSON (indicates success or fallback)
Type
Promise.<Object>

(async) getUploadHost() → {Promise.<Object>}

Description:
  • Retrieves an upload host endpoint to use for file uploads
Source:
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The upload host response JSON (includes host field)
Type
Promise.<Object>

(async) uploadChunk(data, partseq, blob, reqHandleropt, externalAbortopt) → {Promise.<Object>}

Description:
  • Uploads a single chunk (part) of a file
Source:
Parameters:
Name Type Attributes Description
data Object File data including remote_dir, file, upload_id
partseq number The sequence number of this chunk (0-based)
blob Blob | Buffer The binary data of the chunk
reqHandler function <optional>
Optional request progress handler
externalAbort AbortSignal <optional>
Optional external abort signal
Throws:
Throws error if HTTP status is not 200, chunk upload fails, or request times out
Type
Error
Returns:
The upload chunk response JSON (includes MD5 for chunk)
Type
Promise.<Object>

(async) createDir(remoteDir) → {Promise.<Object>}

Description:
  • Creates a new directory in the remote file system
Source:
Parameters:
Name Type Description
remoteDir string The path of the directory to create
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The create directory response JSON
Type
Promise.<Object>

(async) createFile(data) → {Promise.<Object>}

Description:
  • Creates a new file entry on the server after uploading chunks
Source:
Parameters:
Name Type Description
data Object File data including remote_dir, file, size, hash, upload_id, and chunks
Properties
Name Type Description
remote_dir string Remote directory path
file string Filename
size number File size in bytes
hash Object Hash information
Properties
Name Type Description
file string MD5 hash of full file
slice string MD5 hash of first slice
crc32 number CRC32 value
chunks Array.<string> Array of MD5 chunk hashes
upload_id string Upload ID obtained from precreate
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The create file response JSON (includes MD5 and ETag)
Type
Promise.<Object>

(async) filemanager(operation, fmparams) → {Promise.<Object>}

Description:
  • Performs file management operations (delete, copy, move, rename)
Source:
Parameters:
Name Type Description
operation string Operation type: 'delete', 'copy', 'move', 'rename'
fmparams Array Parameters for the operation (array of paths or objects)
Throws:
Throws error if fmparams is not an array, HTTP status is not 200, or request fails
Type
Error
Returns:
The file manager response JSON
Type
Promise.<Object>

(async) shareList() → {Promise.<Object>}

Description:
  • Retrieves a list of shares created by the user
Source:
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The share list JSON (includes share entries)
Type
Promise.<Object>

(async) shareSet(filelist, passopt, periodopt) → {Promise.<Object>}

Description:
  • Sets sharing parameters (e.g., password, expiration) for specified files
Source:
Parameters:
Name Type Attributes Default Description
filelist Array.<string> Array of file paths to share
pass string <optional>
'' Optional 4-character alphanumeric password
period number <optional>
0 Sharing period in days (0 for no expiration)
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The share set response JSON (includes share IDs)
Type
Promise.<Object>

(async) shareCancel(shareid_listopt) → {Promise.<Object>}

Description:
  • Cancels existing shares by share ID
Source:
Parameters:
Name Type Attributes Default Description
shareid_list Array.<number> <optional>
[] Array of share IDs to cancel
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The share cancel response JSON
Type
Promise.<Object>

(async) shortUrlInfo(shortUrl) → {Promise.<Object>}

Description:
  • Retrieves information for a shortened URL share
Source:
Parameters:
Name Type Description
shortUrl string The short url: after "surl="
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The short URL info JSON (includes file list, permissions)
Type
Promise.<Object>

(async) shortUrlList(shortUrl, remoteDiropt, pageopt) → {Promise.<Object>}

Description:
  • Lists files under a shortened URL share
Source:
Parameters:
Name Type Attributes Default Description
shortUrl string The short url: after "surl="
remoteDir string <optional>
'' Remote directory under share (empty for root)
page number <optional>
1 Page number for pagination
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The short URL file list JSON (includes entries array)
Type
Promise.<Object>

(async) fileDiff() → {Promise.<Object>}

Description:
  • Retrieves file difference (delta) information for synchronization
Source:
Throws:
Throws error if HTTP status is not 200, request fails, or on recursive errors
Type
Error
Returns:
The file diff JSON (includes entries, request_id, has_more flag)
Type
Promise.<Object>

(async) genPanToken() → {Promise.<Object>}

Description:
  • Generates a PAN token for subsequent API requests
Source:
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The PAN token response JSON (includes pan token and expire)
Type
Promise.<Object>

(async) getHomeInfo() → {Promise.<Object>}

Description:
  • Retrieves home page information (user info, sign data)
Source:
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The home info JSON (includes sign1, sign3, data.signb)
Type
Promise.<Object>

(async) download(fs_ids, signb) → {Promise.<Object>}

Description:
  • Initiates a download request for specified file IDs
Source:
Parameters:
Name Type Description
fs_ids Array.<number> Array of file system IDs to download
signb string Base64-encoded signature from getHomeInfo
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The download response JSON (includes dlink URLs)
Type
Promise.<Object>

(async) getStream(remotePath, type) → {Promise.<Object>}

Description:
  • Retrieves the streaming contents of a remote file
Source:
Parameters:
Name Type Default Description
remotePath string /video.mp4 Remote video file
type string M3U8_AUTO_480 Streaming type:
M3U8_FLV_264_480
M3U8_AUTO_240
M3U8_AUTO_360
M3U8_AUTO_480
M3U8_AUTO_720
M3U8_AUTO_1080
M3U8_SUBTITLE_SRT
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
m3u8 playlist, or JSON with error
Type
Promise.<Object>

(async) getFileMeta(remote_file_list) → {Promise.<Object>}

Description:
  • Retrieves metadata for specified remote files
Source:
Parameters:
Name Type Description
remote_file_list Array.<Object> Array of file descriptor objects { fs_id, path, etc. }
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The file metadata JSON (includes size, md5, etc.)
Type
Promise.<Object>

(async) getRecentUploads(pageopt) → {Promise.<Object>}

Description:
  • Retrieves a list of recent uploads for the account
Source:
Parameters:
Name Type Attributes Default Description
page number <optional>
1 Page number for pagination
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The recent uploads JSON (includes records array)
Type
Promise.<Object>

(async) getPublicKey() → {Promise.<Object>}

Description:
  • Retrieves the RSA public key from the server for encryption
Source:
Throws:
Throws error if HTTP status is not 200 or request fails
Type
Error
Returns:
The public key response JSON (includes pp1 and pp2)
Type
Promise.<Object>