Unifile

Unifile

Source:

Methods

use(connector)

Source:

Adds a new connector into Unifile. Once a connector has been register with this function, it can be used with all the commands.

Parameters:
Name Type Description
connector Connector

A connector implementing all of Unifile functions

getInfos(session, connectorName) → {ConnectorInfos}

Source:

Get all the info you need about a connector

Parameters:
Name Type Description
session Object

Object where session data will be stored

connectorName string

Name of the connector

Returns:

all the infos about this connector

Type
ConnectorInfos

listConnectors() → {Array.<string>}

Source:

List all the connectors currently used in this instance of Unifile

Returns:

an array of connectors names

Type
Array.<string>

login(session, connectorName, credentials) → {external:Promise.<(string|null)>}

Source:

Log a connector in a distant service. This must be called before any access to the service or an error will be thrown. The result of a successful login attempt will be saved in the session.

Parameters:
Name Type Description
session Object

Object where session data will be stored

connectorName string

Name of the connector

credentials Credentials | string

Service credentials (user/password or OAuth code) or a authenticated URL to connect to the service.

Returns:

a promise of OAuth token if the service uses it or null

Type
external:Promise.<(string|null)>

setAccessToken(session, connectorName, token) → {external:Promise.<(string|null)>}

Source:

Log a connector by directly using a OAuth token. You don't have to call the method if you use the login() method. This is only in the case you got a token from anothe source (CLI, app,...) This must be called before any access to the service or an error will be thrown. The result of a successful login attempt will be saved in the session.

Parameters:
Name Type Description
session Object

Object where session data will be stored

connectorName string

Name of the connector

token string

Service access token generated by OAuth

Returns:

a promise of OAuth token if the service uses it or null

Type
external:Promise.<(string|null)>

clearAccessToken(session, connectorName) → {external:Promise.<null>}

Source:

Log out from a connector. After that you won't be able to make any request until you log in again.

Parameters:
Name Type Description
session Object

Object where session data will be stored

connectorName string

Name of the connector

Returns:

an empty promise.

Type
external:Promise.<null>

getAuthorizeURL(session, connectorName) → {external:Promise.<string>}

Source:

Get the URL of the authorization endpoint for an OAuth service.

Parameters:
Name Type Description
session Object

Object where session data will be stored

connectorName string

Name of the connector

Returns:

a promise of the authorization URL

Type
external:Promise.<string>

readdir(session, connectorName, path) → {external:Promise.<Array.<FileInfos>>}

Source:
See:
  • FileInfos to get the properties of the return objects

Reads the content of a directory.

Parameters:
Name Type Description
session Object

Object where session data will be stored

connectorName string

Name of the connector

path string

Path of the directory to read. Must be relative to the root of the service.

Returns:

a promise of an array of FileInfos

Type
external:Promise.<Array.<FileInfos>>

stat(session, connectorName, path) → {external:Promise.<FileInfos>}

Source:
See:
  • FileInfos to get the properties of the return object

Give information about a file or directory.

Parameters:
Name Type Description
session Object

Object where session data will be stored

connectorName string

Name of the connector

path string

Path of the object to stat. Must be relative to the root of the service.

Returns:

a promise of FileInfos

Type
external:Promise.<FileInfos>

mkdir(session, connectorName, path) → {external:Promise.<null>}

Source:

Create a directory.

Parameters:
Name Type Description
session Object

Object where session data will be stored

connectorName string

Name of the connector

path string

Path of the directory to create. Must be relative to the root of the service.

Returns:

an empty promise

Type
external:Promise.<null>

writeFile(session, connectorName, path, content) → {external:Promise.<null>}

Source:

Write content to a file.

Parameters:
Name Type Description
session Object

Object where session data will be stored

connectorName string

Name of the connector

path string

Path of the file to write. Must be relative to the root of the service.

content string

Content to write into the file

Returns:

an empty promise.

Type
external:Promise.<null>

createWriteStream(session, connectorName, path) → {external:WritableStream}

Source:

Create a write stream to a file.

Parameters:
Name Type Description
session Object

Object where session data will be stored

connectorName string

Name of the connector

path string

Path of the file to write. Must be relative to the root of the service.

Returns:

a writable stream into the file

Type
external:WritableStream

readFile(session, connectorName, path) → {external:Promise.<string>}

Source:

Read the content of the file.

Parameters:
Name Type Description
session Object

Object where session data will be stored

connectorName string

Name of the connector

path string

Path of the file to read. Must be relative to the root of the service.

Returns:

a promise of the content of the file

Type
external:Promise.<string>

createReadStream(session, connectorName, path) → {external:ReadableStream}

Source:

Create a read stream to a file.

Parameters:
Name Type Description
session Object

Object where session data will be stored

connectorName string

Name of the connector

path string

Path of the file to read. Must be relative to the root of the service.

Returns:

a readable stream from the file

Type
external:ReadableStream

rename(session, connectorName, source, destination) → {external:Promise.<null>}

Source:

Rename a file.

Parameters:
Name Type Description
session Object

Object where session data will be stored

connectorName string

Name of the connector

source string

Path to the file to rename. Must be relative to the root of the service.

destination string

New path to give to the file. Must be relative to the root of the service.

Returns:

an empty promise.

Type
external:Promise.<null>
Source:

Unlink (delete) a file.

Parameters:
Name Type Description
session Object

Object where session data will be stored

connectorName string

Name of the connector

path string

Path of the file to delete. Must be relative to the root of the service.

Returns:

an empty promise.

Type
external:Promise.<null>

rmdir(session, connectorName, path) → {external:Promise.<null>}

Source:

Remove a directory.

Parameters:
Name Type Description
session Object

Object where session data will be stored

connectorName string

Name of the connector

path string

Path of the directory to delete. Must be relative to the root of the service.

Returns:

an empty promise.

Type
external:Promise.<null>

batch(session, connectorName, actions, messageopt) → {external:Promise.<null>}

Source:

Execute batch operation. Available actions are UNLINK, RMDIR, RENAME, MKDIR and WRITEFILE.

Parameters:
Name Type Attributes Description
session Object

Object where session data will be stored

connectorName string

Name of the connector

actions Array.<Object>

Array of actions to execute in this batch.

Properties
Name Type Attributes Description
name string

Name of this action.

path string

Path parameter for this action.

destination string <optional>

Destination parameter for this action.

content string <optional>

Content parameter for this action.

message string <optional>

Message to describe this batch

Returns:

an empty promise.

Type
external:Promise.<null>