From 302bb8a483d0d42702cd67d401eac7efadbd5617 Mon Sep 17 00:00:00 2001 From: Nicolas GIRARDIN Date: Fri, 26 Oct 2018 20:43:35 +0200 Subject: [PATCH] Added type definitions for torrent-search-api --- types/torrent-search-api/index.d.ts | 90 +++++++++++++++ .../torrent-search-api-tests.ts | 107 ++++++++++++++++++ types/torrent-search-api/tsconfig.json | 16 +++ types/torrent-search-api/tslint.json | 1 + 4 files changed, 214 insertions(+) create mode 100644 types/torrent-search-api/index.d.ts create mode 100644 types/torrent-search-api/torrent-search-api-tests.ts create mode 100644 types/torrent-search-api/tsconfig.json create mode 100644 types/torrent-search-api/tslint.json diff --git a/types/torrent-search-api/index.d.ts b/types/torrent-search-api/index.d.ts new file mode 100644 index 0000000000..904cdbe4ac --- /dev/null +++ b/types/torrent-search-api/index.d.ts @@ -0,0 +1,90 @@ +// Type definitions for torrent-search-api 2.0 +// Project: https://github.com/JimmyLaurent/torrent-search-api#readme +// Definitions by: Nicolas Girardin +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export interface Torrent { + title: string; + time: string; + size: string; + magnet: string; + desc: string; + provider: string; +} + +export interface TorrentProvider { + name: string; + baseUrl: string; + requireAuthentification: boolean; + supportTokenAuthentification: boolean; + supportCookiesAuthentification: boolean; + supportCredentialsAuthentification: boolean; + loginUrl: string; + loginQueryString: string; + searchUrl: string; + categories: any; // FIXME {key: [string]} + defaultCategory: string; + resultsPerPageCount: number; + itemsSelector: string; + itemSelectors: any; // FIXME {key: [string]} + paginateSelector: string; + torrentDetailsSelector: string; + enableCloudFareBypass: boolean; + headers: any; // FIXME {key:[string]} + magnetSelector: string; + autoFixUnstableUrl: boolean; +} + +export function lodProvider(providerParam: string): void; +export function loadProvider(providerParam: string | TorrentProvider): void; + +export function addProvider(provider: string): void; + +export function loadProviders(...args: string[]): void; +export function loadProviders(...args: TorrentProvider[]): void; + +export function removeProvider(providerName: string): void; + +export function enableProvider(providerName: string, args?: string[]): void; +export function enableProvider(providerName: string, ...args: string[]): void; + +export function enablePublicProviders(): void; + +export function disableProvider(providerName: string): void; + +export function disableAllProviders(): void; + +export function getProviders(): TorrentProvider[]; + +export function getActiveProviders(): TorrentProvider[]; + +export function isProviderActive(name: string): boolean; + +export function search( + query: string, + category: string, + limit: number +): Promise; + +export function search( + providers: string[], + query: string, + category: string, + limit: number +): Promise; + +export function getTorrentDetails(torrent: Torrent): Promise; + +export function downloadTorrent( + torrent: Torrent, + filenamePath?: string +): Promise; + +export function overrideConfig( + providerName: string, + newConfig: TorrentProvider +): Promise; + +export function getMagnet(torrent: Torrent): Promise; + +export function getProvider(name: string, throwOnError: boolean): string; diff --git a/types/torrent-search-api/torrent-search-api-tests.ts b/types/torrent-search-api/torrent-search-api-tests.ts new file mode 100644 index 0000000000..f035c7240e --- /dev/null +++ b/types/torrent-search-api/torrent-search-api-tests.ts @@ -0,0 +1,107 @@ +import TorrentSearchApi = require("torrent-search-api"); + +// $ExpectType void +TorrentSearchApi.enableProvider("Torrent9"); + +// $ExpectType Promise +TorrentSearchApi.search("1080", "Movies", 20); + +// $ExpectType TorrentProvider[] +TorrentSearchApi.getProviders(); + +// $ExpectType TorrentProvider[] +TorrentSearchApi.getActiveProviders(); + +// $ExpectType void +TorrentSearchApi.enablePublicProviders(); + +// $ExpectType void +TorrentSearchApi.enableProvider("Torrent9"); + +// $ExpectType void +TorrentSearchApi.enableProvider("IpTorrents", ["uid=XXX;", "pass=XXX;"]); + +// $ExpectType void +TorrentSearchApi.enableProvider("IpTorrents", "USERNAME", "PASSWORD"); + +// $ExpectType void +TorrentSearchApi.enableProvider("xxx", "TOKEN"); + +// $ExpectType void +TorrentSearchApi.disableProvider("TorrentLeech"); + +// $ExpectType void +TorrentSearchApi.disableAllProviders(); + +// $ExpectType boolean +TorrentSearchApi.isProviderActive("1337x"); + +// $ExpectType Promise +TorrentSearchApi.search("1080", "Movies", 20); + +// $ExpectType Promise +TorrentSearchApi.search(["IpTorrents", "Torrent9"], "1080", "Movies", 20); + +const torrent = { + title: "tile", + time: "time", + size: "size", + magnet: "magnet", + desc: "desc", + provider: "provider" +}; + +// $ExpectType Promise +TorrentSearchApi.getTorrentDetails(torrent); + +// $ExpectType Promise +TorrentSearchApi.getMagnet(torrent); + +// $ExpectType Promise +TorrentSearchApi.downloadTorrent(torrent); + +// $ExpectType Promise +TorrentSearchApi.downloadTorrent(torrent, "file.mp4"); + +const provider = { + name: "name", + baseUrl: "baseUrl", + requireAuthentification: true, + supportTokenAuthentification: true, + supportCookiesAuthentification: true, + supportCredentialsAuthentification: true, + loginUrl: "loginUrl", + loginQueryString: "loginQueryString", + searchUrl: "searchUrl", + categories: { + All: "all", + Movies: "movies" + }, + defaultCategory: "all", + resultsPerPageCount: 50, + itemsSelector: ".selector", + itemSelectors: { + title: ".title", + seeds: ".seeds", + peers: ".peers", + size: ".size", + desc: ".desc" + }, + paginateSelector: ".page", + torrentDetailsSelector: ".detail", + enableCloudFareBypass: true, + headers: { + UserAgent: "ua" + }, + magnetSelector: ".magnet", + autoFixUnstableUrl: true +}; + +// $ExpectType void +TorrentSearchApi.loadProvider(provider); + +// $ExpectType void +TorrentSearchApi.loadProviders("/path/to/provider"); + +// $ExpectType void +TorrentSearchApi.removeProvider("MyCustomProvider"); diff --git a/types/torrent-search-api/tsconfig.json b/types/torrent-search-api/tsconfig.json new file mode 100644 index 0000000000..7b342437d9 --- /dev/null +++ b/types/torrent-search-api/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": ["index.d.ts", "torrent-search-api-tests.ts"] +} diff --git a/types/torrent-search-api/tslint.json b/types/torrent-search-api/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/torrent-search-api/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }