Methods
use(connector)
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}
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>}
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)>}
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)>}
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>}
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>}
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>>}
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>}
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>}
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>}
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}
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
readFile(session, connectorName, path) → {external:Promise.<string>}
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}
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
rename(session, connectorName, source, destination) → {external:Promise.<null>}
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>
unlink(session, connectorName, path) → {external:Promise.<null>}
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>}
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>}
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
|
|||||||||||||||||||||
message |
string |
<optional> |
Message to describe this batch |
Returns:
an empty promise.
- Type
- external:Promise.<null>