API wrapper, JavaScript SDK for jesec/flood
yarn add flood-api
import Api from 'flood-api'
const api = new Api({
baseUrl: 'http://localhost:3000/api',
username: 'user',
password: 'pass',
})
api.options.baseUrl
await api.client.connectionTest()
//-> { isConnected: true }
cookie | boolean whether to Set-Cookie if succeeded |
username | string |
password | string |
client | object |
level | number |
await api.auth.register(..)
{- "username": "string"
}
username required | string |
username | string |
password | string |
client | object |
level | number |
await api.auth.updateUser({ username: 'user' })
{ }
await api.client.getSettings()
{- "dht": true,
- "dhtPort": 0,
- "directoryDefault": "string",
- "networkHttpMaxOpen": 0,
- "networkLocalAddress": [
- "string"
], - "networkMaxOpenFiles": 0,
- "networkPortOpen": true,
- "networkPortRandom": true,
- "networkPortRange": "string",
- "piecesHashOnCompletion": true,
- "piecesMemoryMax": 0,
- "protocolPex": true,
- "throttleGlobalDownSpeed": 0,
- "throttleGlobalUpSpeed": 0,
- "throttleMaxPeersNormal": 0,
- "throttleMaxPeersSeed": 0,
- "throttleMaxDownloads": 0,
- "throttleMaxDownloadsGlobal": 0,
- "throttleMaxUploads": 0,
- "throttleMaxUploadsGlobal": 0,
- "throttleMinPeersNormal": 0,
- "throttleMinPeersSeed": 0,
- "trackersNumWant": 0
}
dht | boolean |
dhtPort | number |
directoryDefault | string |
networkHttpMaxOpen | number |
networkLocalAddress | Array of strings |
networkMaxOpenFiles | number |
networkPortOpen | boolean |
networkPortRandom | boolean |
networkPortRange | string |
piecesHashOnCompletion | boolean |
piecesMemoryMax | number |
protocolPex | boolean |
throttleGlobalDownSpeed | number |
throttleGlobalUpSpeed | number |
throttleMaxPeersNormal | number |
throttleMaxPeersSeed | number |
throttleMaxDownloads | number |
throttleMaxDownloadsGlobal | number |
throttleMaxUploads | number |
throttleMaxUploadsGlobal | number |
throttleMinPeersNormal | number |
throttleMinPeersSeed | number |
trackersNumWant | number |
await api.client.updateSettings({ .. })
{ }
await api.feedMonitor.list()
{- "feeds": [
- {
- "type": "feed",
- "_id": "string",
- "label": "string",
- "url": "string",
- "interval": 0,
- "count": 0
}
], - "rules": [
- {
- "type": "rule",
- "_id": "string",
- "label": "string",
- "feedIDs": [
- "string"
], - "field": "string",
- "match": "string",
- "exclude": "string",
- "destination": "string",
- "tags": [
- "string"
], - "startOnLoad": true,
- "isBasePath": true,
- "count": 0
}
]
}
id required | string |
type | string Value: "feed" |
_id | string |
label | string |
url | string |
interval | number |
count | number |
await api.feedMonitor.updateFeed({ id: '1', .. })
{ }
type | string Value: "feed" |
_id | string |
label | string |
url | string |
interval | number |
count | number |
await api.feedMonitor.addFeed({ data: { label, url, interval } })
{- "type": "feed",
- "_id": "string",
- "label": "string",
- "url": "string",
- "interval": 0,
- "count": 0
}
await api.feedMonitor.listRules()
[- {
- "type": "rule",
- "_id": "string",
- "label": "string",
- "feedIDs": [
- "string"
], - "field": "string",
- "match": "string",
- "exclude": "string",
- "destination": "string",
- "tags": [
- "string"
], - "startOnLoad": true,
- "isBasePath": true,
- "count": 0
}
]
type | string Value: "rule" |
_id | string |
label | string |
feedIDs | Array of strings |
field | string |
match | string |
exclude | string |
destination | string |
tags | Array of strings |
startOnLoad | boolean |
isBasePath | boolean |
count | number |
await api.feedMonitor.addRule({ .. })
{- "type": "rule",
- "_id": "string",
- "label": "string",
- "feedIDs": [
- "string"
], - "field": "string",
- "match": "string",
- "exclude": "string",
- "destination": "string",
- "tags": [
- "string"
], - "startOnLoad": true,
- "isBasePath": true,
- "count": 0
}
await api.listSettings()
{- "language": "string",
- "sortTorrents": {
- "direction": "desc",
- "property": { }
}, - "torrentListColumns": [
- { }
], - "torrentListColumnWidths": { },
- "torrentContextMenuActions": [
- { }
], - "torrentListViewSize": "condensed",
- "speedLimits": {
- "download": [
- 0
], - "upload": [
- 0
]
}, - "mountPoints": [
- "string"
], - "deleteTorrentData": true,
- "startTorrentsOnLoad": true,
- "torrentDestinations": [
- "string"
], - "UITagSelectorMode": "single",
- "UITorrentsAddTab": "by-url"
}
language | string |
object | |
torrentListColumns | Array of objects |
torrentListColumnWidths | object |
torrentContextMenuActions | Array of objects |
torrentListViewSize | string Enum: "condensed" "expanded" |
object | |
mountPoints | Array of strings |
deleteTorrentData | boolean |
startTorrentsOnLoad | boolean |
torrentDestinations | Array of strings |
UITagSelectorMode | string Enum: "single" "multi" |
UITorrentsAddTab | string Enum: "by-url" "by-file" "by-creation" |
await api.updateSettings({ .. })
{- "language": "string",
- "sortTorrents": {
- "direction": "desc",
- "property": { }
}, - "torrentListColumns": [
- { }
], - "torrentListColumnWidths": { },
- "torrentContextMenuActions": [
- { }
], - "torrentListViewSize": "condensed",
- "speedLimits": {
- "download": [
- 0
], - "upload": [
- 0
]
}, - "mountPoints": [
- "string"
], - "deleteTorrentData": true,
- "startTorrentsOnLoad": true,
- "torrentDestinations": [
- "string"
], - "UITagSelectorMode": "single",
- "UITorrentsAddTab": "by-url"
}
await api.getSetting({ property: '..' })
{- "language": "string",
- "sortTorrents": {
- "direction": "desc",
- "property": { }
}, - "torrentListColumns": [
- { }
], - "torrentListColumnWidths": { },
- "torrentContextMenuActions": [
- { }
], - "torrentListViewSize": "condensed",
- "speedLimits": {
- "download": [
- 0
], - "upload": [
- 0
]
}, - "mountPoints": [
- "string"
], - "deleteTorrentData": true,
- "startTorrentsOnLoad": true,
- "torrentDestinations": [
- "string"
], - "UITagSelectorMode": "single",
- "UITorrentsAddTab": "by-url"
}
It uses Server-Sent Events
List of Events
historySnapshot | string Enum: "FIVE_MINUTE" "THIRTY_MINUTE" "HOUR" "DAY" "WEEK" "MONTH" "YEAR" |
const es = api.activityStream() es.addEventListener('CLIENT_CONNECTIVITY_STATUS_CHANGE', e => console.log(e.data))
await api.torrents.list()
{- "id": 0,
- "torrents": {
- "property1": {
- "bytesDone": 0,
- "dateAdded": 0,
- "dateCreated": 0,
- "directory": "string",
- "downRate": 0,
- "downTotal": 0,
- "eta": 0,
- "hash": "string",
- "isPrivate": true,
- "isInitialSeeding": true,
- "isSequential": true,
- "message": "string",
- "name": "string",
- "peersConnected": 0,
- "peersTotal": 0,
- "percentComplete": 0,
- "priority": 0,
- "ratio": 0,
- "seedsConnected": 0,
- "seedsTotal": 0,
- "sizeBytes": 0,
- "status": [
- "checking"
], - "tags": [
- "string"
], - "trackerURIs": [
- "string"
], - "upRate": 0,
- "upTotal": 0
}, - "property2": {
- "bytesDone": 0,
- "dateAdded": 0,
- "dateCreated": 0,
- "directory": "string",
- "downRate": 0,
- "downTotal": 0,
- "eta": 0,
- "hash": "string",
- "isPrivate": true,
- "isInitialSeeding": true,
- "isSequential": true,
- "message": "string",
- "name": "string",
- "peersConnected": 0,
- "peersTotal": 0,
- "percentComplete": 0,
- "priority": 0,
- "ratio": 0,
- "seedsConnected": 0,
- "seedsTotal": 0,
- "sizeBytes": 0,
- "status": [
- "checking"
], - "tags": [
- "string"
], - "trackerURIs": [
- "string"
], - "upRate": 0,
- "upTotal": 0
}
}
}
destination: '' or '/absolute/path' # '' uses default directory returns [hash] Errors
{ code: -32602, message: "Could not create download: Info hash already used by another torrent." }
urls | Array of strings |
cookies | Array of strings |
destination | string |
tags | Array of strings |
isBasePath | boolean |
isCompleted | boolean |
isSequential | boolean |
isInitialSeeding | boolean |
start | boolean |
await api.torrents.addUrls({ .. })
[- "string"
]
files | Array of strings |
destination | string |
tags | Array of strings |
isBasePath | boolean |
isCompleted | boolean |
isSequential | boolean |
isInitialSeeding | boolean |
start | boolean |
await api.torrents.addFiles({ .. })
[- "string"
]
name | string |
sourcePath | string |
trackers | Array of strings |
comment | string |
infoSource | string |
isPrivate | boolean |
isInitialSeeding | boolean |
start | boolean |
tags | Array of strings |
await api.torrents.create({ .. })
{- "message": "string",
- "code": 0
}
hashes | Array of strings |
destination | string |
moveFiles | boolean |
isBasePath | boolean |
isCheckHash | boolean |
await api.torrents.move({ .. })
{- "message": "string",
- "code": 0
}
hashes | Array of strings |
isInitialSeeding | boolean |
await api.torrents.updateInitialSeeding({ .. })
{- "message": "string",
- "code": 0
}
Given
hello/
s01/
e01.nfo
e01.mkv
Returns
[
{ index: 0, path: 's01/e01.nfo', filename: 'e01.nfo' }
{ index: 1, path: 's01/e01.mkv', filename: 'e01.mkv' }
]
hash required | string |
await api.torrents.listContents({ .. })
[- {
- "index": 0,
- "path": "string",
- "filename": "string",
- "percentComplete": 0,
- "priority": 0,
- "sizeBytes": 0
}
]
hash required | string |
indices | Array of numbers Items Enum: 0 1 2 |
priority | number |
await api.torrents.updateContents({ .. })
{ }
contents: see List contents of a torrent
hash required | string |
await api.torrents.getDetails({ .. })
Indices must be exact same as the ones in getContentsToken, otherswise it will return unauthorized error.
Returns tar if indices are more than one, otherwise returns all kinds of type based on the content.
hash required | string |
indices required | string 'all' or indices of selected contents separated by ',' |
token | string 'Allows unauthenticated access if a valid content token is found in the query.' |
const files = await api.torrents.listContents({ hash }) const video = files.find(file => filename.endsWith('.mkv')) const indices = video.index const token = await api.torrents.getContentsToken({ hash, indices }) mpv 'http://localhost:3000/api/torrents/{hash}/contents/{indices}/data?token={token}' const nfo = files.find(file => filename.endsWith('.nfo')) const indices = nfo.index const nfoContent = await api.torrents.getContentsData({ hash, indices })