Flood API (1.0.3)

API wrapper, JavaScript SDK for jesec/flood

Getting Started

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 }

Auth

Authenticates a user

Request Body schema: application/json
username
required
string
password
required
string

Responses

Request samples

await api.auth.authenticate({
  username: 'user',
  password: 'pass'
})

Response samples

Content type
application/json
No sample

Registers a user

query Parameters
cookie
boolean

whether to Set-Cookie if succeeded

Request Body schema: application/json
username
string
password
string
client
object
level
number

Responses

Request samples

await api.auth.register(..)

Response samples

Content type
application/json
Example
{
  • "username": "string"
}

Verifies the session

Responses

Request samples

await api.auth.verify()

Response samples

Content type
application/json
{
  • "initialUser": true,
  • "username": "string",
  • "level": 0
}

Clear the session

Responses

Request samples

await api.auth.logout()

Lists all users

Responses

Request samples

await api.auth.listUsers()

Response samples

Content type
application/json
[
  • {
    }
]

Deletes a user

path Parameters
username
required
string

Responses

Request samples

await api.auth.deleteUser({ username: 'user' })

Response samples

Content type
application/json
{
  • "username": "string"
}

Updates a user

path Parameters
username
required
string
Request Body schema: application/json
username
string
password
string
client
object
level
number

Responses

Request samples

await api.auth.updateUser({
  username: 'user'
})

Response samples

Content type
application/json
{ }

Client

Tests connection to the torrent client

Responses

Request samples

await api.client.connectionTest()

Response samples

Content type
application/json
{
  • "isConnected": true
}

Gets settings of torrent client

Responses

Request samples

await api.client.getSettings()

Response samples

Content type
application/json
{
  • "dht": true,
  • "dhtPort": 0,
  • "directoryDefault": "string",
  • "networkHttpMaxOpen": 0,
  • "networkLocalAddress": [
    ],
  • "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
}

Updates settings of torrent client

Request Body schema: application/json
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

Responses

Request samples

await api.client.updateSettings({
  ..
})

Response samples

Content type
application/json
{ }

Feeds

Lists all feeds and rules

Responses

Request samples

await api.feedMonitor.list()

Response samples

Content type
application/json
{
  • "feeds": [
    ],
  • "rules": [
    ]
}

Deletes a feed or rule

path Parameters
id
required
string

Responses

Request samples

await api.feedMonitor.delete({
  id: '1',
})

Response samples

Content type
application/json
{ }

Lists all feeds

path Parameters
id
required
string

Responses

Request samples

await api.feedMonitor.listFeeds({
  id: '1,2'
})

Response samples

Content type
application/json
[
  • {
    }
]

Updates a feed

path Parameters
id
required
string
Request Body schema: application/json
type
string
Value: "feed"
_id
string
label
string
url
string
interval
number
count
number

Responses

Request samples

await api.feedMonitor.updateFeed({
  id: '1',
  ..
})

Response samples

Content type
application/json
{ }

Adds a feed

Request Body schema:
type
string
Value: "feed"
_id
string
label
string
url
string
interval
number
count
number

Responses

Request samples

await api.feedMonitor.addFeed({
  data: {
    label,
    url,
    interval
  }
})

Response samples

Content type
application/json
{
  • "type": "feed",
  • "_id": "string",
  • "label": "string",
  • "url": "string",
  • "interval": 0,
  • "count": 0
}

Lists all feed items

path Parameters
id
required
string
query Parameters
search
string

Responses

Request samples

await api.feedMonitor.listFeedItems({
  id: '1'
})

Response samples

Content type
application/json
[
  • {
    }
]

Lists all rules

Responses

Request samples

await api.feedMonitor.listRules()

Response samples

Content type
application/json
[
  • {
    }
]

Adds a rule

Request Body schema: application/json
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

Responses

Request samples

await api.feedMonitor.addRule({
  ..
})

Response samples

Content type
application/json
{
  • "type": "rule",
  • "_id": "string",
  • "label": "string",
  • "feedIDs": [
    ],
  • "field": "string",
  • "match": "string",
  • "exclude": "string",
  • "destination": "string",
  • "tags": [
    ],
  • "startOnLoad": true,
  • "isBasePath": true,
  • "count": 0
}

Flood

Lists a directory

Responses

Request samples

await api.listDirectory()

Response samples

Content type
application/json
{ }

Lists transfer history

query Parameters
snapshot
string
Enum: "FIVE_MINUTE" "THIRTY_MINUTE" "HOUR" "DAY" "WEEK" "MONTH" "YEAR"

Responses

Request samples

await api.listHistory()

Response samples

Content type
application/json
{ }

Lists all notifications

query Parameters
id
string
limit
required
number
start
required
number
allNotifications
boolean

Responses

Request samples

await api.listNotifications()

Response samples

Content type
application/json
{
  • "notifications": { },
  • "count": { }
}

Deletes notifications

Responses

Request samples

await api.deleteNotifications()

Response samples

Content type
application/json
{
  • "message": "string",
  • "code": 0
}

Lists all Flood settings

Responses

Request samples

await api.listSettings()

Response samples

Content type
application/json
{
  • "language": "string",
  • "sortTorrents": {
    },
  • "torrentListColumns": [
    ],
  • "torrentListColumnWidths": { },
  • "torrentContextMenuActions": [
    ],
  • "torrentListViewSize": "condensed",
  • "speedLimits": {
    },
  • "mountPoints": [
    ],
  • "deleteTorrentData": true,
  • "startTorrentsOnLoad": true,
  • "torrentDestinations": [
    ],
  • "UITagSelectorMode": "single",
  • "UITorrentsAddTab": "by-url"
}

Updates Flood settings

Request Body schema: application/json
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"

Responses

Request samples

await api.updateSettings({
  ..
})

Response samples

Content type
application/json
{
  • "language": "string",
  • "sortTorrents": {
    },
  • "torrentListColumns": [
    ],
  • "torrentListColumnWidths": { },
  • "torrentContextMenuActions": [
    ],
  • "torrentListViewSize": "condensed",
  • "speedLimits": {
    },
  • "mountPoints": [
    ],
  • "deleteTorrentData": true,
  • "startTorrentsOnLoad": true,
  • "torrentDestinations": [
    ],
  • "UITagSelectorMode": "single",
  • "UITorrentsAddTab": "by-url"
}

Gets a Flood setting

path Parameters
property
required
string

Responses

Request samples

await api.getSetting({
  property: '..'
})

Response samples

Content type
application/json
{
  • "language": "string",
  • "sortTorrents": {
    },
  • "torrentListColumns": [
    ],
  • "torrentListColumnWidths": { },
  • "torrentContextMenuActions": [
    ],
  • "torrentListViewSize": "condensed",
  • "speedLimits": {
    },
  • "mountPoints": [
    ],
  • "deleteTorrentData": true,
  • "startTorrentsOnLoad": true,
  • "torrentDestinations": [
    ],
  • "UITagSelectorMode": "single",
  • "UITorrentsAddTab": "by-url"
}

Subscribes to activity stream

It uses Server-Sent Events

List of Events

  • CLIENT_CONNECTIVITY_STATUS_CHANGE
  • TRANSFER_HISTORY_FULL_UPDATE
  • DISK_USAGE_CHANGE
  • TORRENT_LIST_FULL_UPDATE
  • TAXONOMY_FULL_UPDATE
  • TRANSFER_SUMMARY_FULL_UPDATE
  • NOTIFICATION_COUNT_CHANGE
query Parameters
historySnapshot
string
Enum: "FIVE_MINUTE" "THIRTY_MINUTE" "HOUR" "DAY" "WEEK" "MONTH" "YEAR"

Responses

Request samples

const es = api.activityStream()
es.addEventListener('CLIENT_CONNECTIVITY_STATUS_CHANGE', e => console.log(e.data))

Torrents

Lists all torrents

Responses

Request samples

await api.torrents.list()

Response samples

Content type
application/json
{
  • "id": 0,
  • "torrents": {
    }
}

Adds torrents by URLs

destination: '' or '/absolute/path' # '' uses default directory returns [hash] Errors

  • 403: { "code": "EACCES", "message": "Permission denied" } jesec/rtorrent only
    • 500: { code: -32602, message: "Could not create download: Info hash already used by another torrent." }
Request Body schema: application/json
urls
Array of strings
cookies
Array of strings
destination
string
tags
Array of strings
isBasePath
boolean
isCompleted
boolean
isSequential
boolean
isInitialSeeding
boolean
start
boolean

Responses

Request samples

await api.torrents.addUrls({
  ..
})

Response samples

Content type
application/json
[
  • "string"
]

Adds torrents by files

Request Body schema: application/json
files
Array of strings
destination
string
tags
Array of strings
isBasePath
boolean
isCompleted
boolean
isSequential
boolean
isInitialSeeding
boolean
start
boolean

Responses

Request samples

await api.torrents.addFiles({
  ..
})

Response samples

Content type
application/json
[
  • "string"
]

Creates a torrent

Request Body schema: application/json
name
string
sourcePath
string
trackers
Array of strings
comment
string
infoSource
string
isPrivate
boolean
isInitialSeeding
boolean
start
boolean
tags
Array of strings

Responses

Request samples

await api.torrents.create({
  ..
})

Response samples

Content type
application/json
{
  • "message": "string",
  • "code": 0
}

Starts torrents

Request Body schema: application/json
hashes
Array of strings

Responses

Request samples

await api.torrents.start({
  ..
})

Response samples

Content type
application/json
{
  • "message": "string",
  • "code": 0
}

Stops torrents

Request Body schema: application/json
hashes
Array of strings

Responses

Request samples

await api.torrents.stop({
  ..
})

Response samples

Content type
application/json
{
  • "message": "string",
  • "code": 0
}

Hash checks torrents

Request Body schema: application/json
hashes
Array of strings

Responses

Request samples

await api.torrents.checkHash({
  ..
})

Response samples

Content type
application/json
{
  • "message": "string",
  • "code": 0
}

Moves torrents

Request Body schema: application/json
hashes
Array of strings
destination
string
moveFiles
boolean
isBasePath
boolean
isCheckHash
boolean

Responses

Request samples

await api.torrents.move({
  ..
})

Response samples

Content type
application/json
{
  • "message": "string",
  • "code": 0
}

Deletes torrents

Request Body schema: application/json
hashes
Array of strings
deleteData
boolean

Responses

Request samples

await api.torrents.delete({
  ..
})

Response samples

Content type
application/json
{
  • "message": "string",
  • "code": 0
}

Reannounces torrents

Request Body schema: application/json
hashes
Array of strings

Responses

Request samples

await api.torrents.reannounce({
  ..
})

Response samples

Content type
application/json
{
  • "message": "string",
  • "code": 0
}

Updates initial seeding mode of torrents

Request Body schema: application/json
hashes
Array of strings
isInitialSeeding
boolean

Responses

Request samples

await api.torrents.updateInitialSeeding({
  ..
})

Response samples

Content type
application/json
{
  • "message": "string",
  • "code": 0
}

Updates priority of torrents

Request Body schema: application/json
hashes
Array of strings
priority
number
Enum: 0 1 2 3

Responses

Request samples

await api.torrents.updatePriority({
  ..
})

Updates sequential mode of torrents

Request Body schema: application/json
hashes
Array of strings
isSequential
boolean

Responses

Request samples

await api.torrents.updateSequential({
  ..
})

Updates tags of torrents

Request Body schema: application/json
hashes
Array of strings
tags
Array of strings

Responses

Request samples

await api.torrents.updateTags({
  ..
})

Response samples

Content type
application/json
{
  • "message": "string",
  • "code": 0
}

Updates trackers of torrents

Request Body schema: application/json
hashes
Array of strings
trackers
Array of strings

Responses

Request samples

await api.torrents.updateTrackers({
  ..
})

Response samples

Content type
application/json
{
  • "message": "string",
  • "code": 0
}

Gets .torrent files

path Parameters
hashes
required
string

Hash of a torrent, or hashes of torrents (split by ,)

Responses

Request samples

await api.torrents.getMetainfo({
  hashes: 'a,b'
})

Response samples

Content type
application/json
{ }

List contents of a torrent

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' }
]
path Parameters
hash
required
string

Responses

Request samples

await api.torrents.listContents({
  ..
})

Response samples

Content type
application/json
[
  • {
    }
]

Updates properties of contents of a torrent

path Parameters
hash
required
string
Request Body schema: application/json
indices
Array of numbers
Items Enum: 0 1 2
priority
number

Responses

Request samples

await api.torrents.updateContents({
  ..
})

Response samples

Content type
application/json
{ }

Gets retrieval token of contents of a torrent

path Parameters
hash
required
string
indices
required
string

'all' or indices of selected contents separated by ','

Responses

Request samples

const token = await api.torrents.getContentsToken({ hash, indices: '0,1' })

Gets details of a torrent

path Parameters
hash
required
string

Responses

Request samples

await api.torrents.getDetails({
  ..
})

Response samples

Content type
application/json
No sample

Gets mediainfo of a torrent

path Parameters
hash
required
string

Responses

Request samples

await api.torrents.getMediaInfo({
  ..
})

Response samples

Content type
application/json
{ }

Lists peers of a torrent

path Parameters
hash
required
string

Responses

Request samples

await api.torrents.listPeers({
  ..
})

Lists trackers of a torrent

path Parameters
hash
required
string

Responses

Request samples

await api.torrents.listTrackers({
  ..
})

Response samples

Content type
application/json
{
  • "message": "string",
  • "code": 0
}

Gets downloaded data of contents of a torrent

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.

path Parameters
hash
required
string
indices
required
string

'all' or indices of selected contents separated by ','

query Parameters
token
string

'Allows unauthenticated access if a valid content token is found in the query.'

Responses

Request samples

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 })