@innei/qbittorrent-browser
Version:
TypeScript api wrapper for qbittorrent using got
261 lines (260 loc) • 12.3 kB
TypeScript
import type { Jsonify } from "type-fest";
import type { AddTorrentOptions as NormalizedAddTorrentOptions, AllClientData, NormalizedTorrent, TorrentClient, TorrentClientConfig as BaseTorrentClientConfig, TorrentClientState } from "@ctrl/shared-torrent";
import type { AddMagnetOptions, AddTorrentOptions, BuildInfo, DownloadSpeed, Preferences, Torrent, TorrentCategories, TorrentFile, TorrentFilePriority, TorrentFilters, TorrentPeersResponse, TorrentPieceState, TorrentProperties, TorrentTrackers, UploadSpeed, WebSeed } from "./types.js";
interface TorrentClientConfig extends BaseTorrentClientConfig {
/**
* Custom fetch function to use for HTTP requests
* If not provided, will use the browser's native fetch
*/
fetch?: typeof fetch;
}
interface QBittorrentState extends TorrentClientState {
version?: {
version: string;
isVersion5OrHigher: boolean;
};
}
export declare class QBittorrent implements TorrentClient {
config: TorrentClientConfig;
state: QBittorrentState;
constructor(options?: Partial<TorrentClientConfig>);
/**
* Export the state of the client as JSON
*/
exportState(): Jsonify<QBittorrentState>;
/**
* @deprecated
*/
version(): Promise<string>;
/**
* Get application version
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-application-version}
*/
getAppVersion(): Promise<string>;
getApiVersion(): Promise<string>;
/**
* Get default save path
*/
getDefaultSavePath(): Promise<string>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-build-info}
*/
getBuildInfo(): Promise<BuildInfo>;
getTorrent(hash: string): Promise<NormalizedTorrent>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-torrent-download-limit}
*/
getTorrentDownloadLimit(hash: string | string[]): Promise<DownloadSpeed>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#set-torrent-download-limit}
*/
setTorrentDownloadLimit(hash: string | string[], limitBytesPerSecond: number): Promise<boolean>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-torrent-upload-limit}
*/
getTorrentUploadLimit(hash: string | string[]): Promise<UploadSpeed>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#set-torrent-upload-limit}
*/
setTorrentUploadLimit(hash: string | string[], limitBytesPerSecond: number): Promise<boolean>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-application-preferences}
*/
getPreferences(): Promise<Preferences>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#set-application-preferences}
*/
setPreferences(preferences: Partial<Preferences>): Promise<boolean>;
/**
* Torrents list
* @param hashes Filter by torrent hashes
* @param [filter] Filter torrent list
* @param category Get torrents with the given category (empty string means "without category"; no "category" parameter means "any category")
* @returns list of torrents
*/
listTorrents({ hashes, filter, category, sort, offset, reverse, tag, limit, isPrivate, includeTrackers, }?: {
hashes?: string | string[];
filter?: TorrentFilters;
sort?: string;
tag?: string;
category?: string;
offset?: number;
limit?: number;
reverse?: boolean;
/**
* Maps to `private` query parameter.
* Renamed to avoid conflict with `private` keyword.
*/
isPrivate?: boolean;
includeTrackers?: boolean;
}): Promise<Torrent[]>;
getAllData(): Promise<AllClientData>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-torrent-generic-properties}
*/
torrentProperties(hash: string): Promise<TorrentProperties>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-torrent-trackers}
*/
torrentTrackers(hash: string): Promise<TorrentTrackers[]>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-torrent-web-seeds}
*/
torrentWebSeeds(hash: string): Promise<WebSeed[]>;
torrentFiles(hash: string): Promise<TorrentFile[]>;
setFilePriority(hash: string, fileIds: string | string[], priority: TorrentFilePriority): Promise<boolean>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-torrent-pieces-states}
*/
torrentPieceStates(hash: string): Promise<TorrentPieceState[]>;
/**
* Torrents piece hashes
* @returns an array of hashes (strings) of all pieces (in order) of a specific torrent
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-torrent-pieces-hashes}
*/
torrentPieceHashes(hash: string): Promise<string[]>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#set-torrent-location}
*/
setTorrentLocation(hashes: string | string[] | "all", location: string): Promise<boolean>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#set-torrent-name}
*/
setTorrentName(hash: string, name: string): Promise<boolean>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-all-tags}
*/
getTags(): Promise<string[]>;
/**
* @param tags comma separated list
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#create-tags}
*/
createTags(tags: string): Promise<boolean>;
/**
* @param tags comma separated list
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#delete-tags}
*/
deleteTags(tags: string): Promise<boolean>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-all-categories}
*/
getCategories(): Promise<TorrentCategories>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#add-new-category}
*/
createCategory(category: string, savePath?: string): Promise<boolean>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#edit-category}
*/
editCategory(category: string, savePath?: string): Promise<boolean>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#remove-categories}
*/
removeCategory(categories: string): Promise<boolean>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#add-torrent-tags}
*/
addTorrentTags(hashes: string | string[] | "all", tags: string): Promise<boolean>;
/**
* if tags are not passed, removes all tags
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#remove-torrent-tags}
*/
removeTorrentTags(hashes: string | string[] | "all", tags?: string): Promise<boolean>;
/**
* helper function to remove torrent category
*/
resetTorrentCategory(hashes: string | string[] | "all"): Promise<boolean>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#set-torrent-category}
*/
setTorrentCategory(hashes: string | string[] | "all", category?: string): Promise<boolean>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#pause-torrents}
*/
stopTorrent(hashes: string | string[] | "all"): Promise<boolean>;
/**
* @deprecated Alias for {@link stopTorrent}.
*/
pauseTorrent(hashes: string | string[] | "all"): Promise<boolean>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#resume-torrents}
*/
startTorrent(hashes: string | string[] | "all"): Promise<boolean>;
/**
* @deprecated Alias for {@link startTorrent}.
*/
resumeTorrent(hashes: string | string[] | "all"): Promise<boolean>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#delete-torrents}
* @param deleteFiles (default: false) remove files from disk
*/
removeTorrent(hashes: string | string[] | "all", deleteFiles?: boolean): Promise<boolean>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#recheck-torrents}
*/
recheckTorrent(hashes: string | string[] | "all"): Promise<boolean>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#reannounce-torrents}
*/
reannounceTorrent(hashes: string | string[] | "all"): Promise<boolean>;
addTorrent(torrent: string | Uint8Array, options?: Partial<AddTorrentOptions>): Promise<boolean>;
normalizedAddTorrent(torrent: string | Uint8Array, options?: Partial<NormalizedAddTorrentOptions>): Promise<NormalizedTorrent>;
/**
* @param hash Hash for desired torrent
* @param oldPath id of the file to be renamed
* @param newPath new name to be assigned to the file
*/
renameFile(hash: string, oldPath: string, newPath: string): Promise<boolean>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#rename-folder}
*/
renameFolder(hash: string, oldPath: string, newPath: string): Promise<boolean>;
/**
* @param urls URLs separated with newlines
* @param options
*/
addMagnet(urls: string, options?: Partial<AddMagnetOptions>): Promise<boolean>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#add-trackers-to-torrent}
*/
addTrackers(hash: string, urls: string): Promise<boolean>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#edit-trackers}
*/
editTrackers(hash: string, origUrl: string, newUrl: string): Promise<boolean>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#remove-trackers}
*/
removeTrackers(hash: string, urls: string): Promise<boolean>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#increase-torrent-priority}
*/
queueUp(hashes: string | string[] | "all"): Promise<boolean>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#decrease-torrent-priority}
*/
queueDown(hashes: string | string[] | "all"): Promise<boolean>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#maximal-torrent-priority}
*/
topPriority(hashes: string | string[] | "all"): Promise<boolean>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#minimal-torrent-priority}
*/
bottomPriority(hashes: string | string[] | "all"): Promise<boolean>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-torrent-peers-data}
* @param rid - Response ID. If not provided, rid=0 will be assumed. If the given rid is
* different from the one of last server reply, full_update will be true (see the server reply details for more info)
*/
torrentPeers(hash: string, rid?: number): Promise<TorrentPeersResponse>;
/**
* {@link https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#login}
* Browser version: Uses 401/403 status codes for auth validation instead of cookie parsing
*/
login(): Promise<boolean>;
logout(): Promise<boolean>;
request<T>(path: string, method: "GET" | "POST", params?: Record<string, string | number>, body?: URLSearchParams | FormData, headers?: Record<string, string>, isJson?: boolean): Promise<T>;
private checkVersion;
}
export {};