From 69a9c667a5efcf878713de9ec1398cf0ce14a54f Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Mon, 3 May 2021 19:03:33 +0800 Subject: [PATCH] server: Deluge: create empty services --- config.ts | 45 ++++- .../services/Deluge/clientGatewayService.ts | 180 ++++++++++++++++++ .../services/Deluge/clientRequestManager.ts | 7 + server/services/index.ts | 3 + shared/schema/ClientConnectionSettings.ts | 7 +- 5 files changed, 239 insertions(+), 3 deletions(-) create mode 100644 server/services/Deluge/clientGatewayService.ts create mode 100644 server/services/Deluge/clientRequestManager.ts diff --git a/config.ts b/config.ts index a49749db..fa447c40 100644 --- a/config.ts +++ b/config.ts @@ -54,6 +54,22 @@ const {argv} = yargs(process.argv.slice(2)) describe: "Disable Flood's builtin access control system, deprecated, use auth=none instead", type: 'boolean', }) + .option('dehost', { + describe: 'Host of Deluge RPC interface', + type: 'string', + }) + .option('deport', { + describe: 'Port of Deluge RPC interface', + type: 'number', + }) + .option('deuser', { + describe: 'Username of Deluge RPC interface', + type: 'string', + }) + .option('depass', { + describe: 'Password of Deluge RPC interface', + type: 'string', + }) .option('rthost', { describe: "Host of rTorrent's SCGI interface", type: 'string', @@ -91,7 +107,24 @@ const {argv} = yargs(process.argv.slice(2)) describe: 'Password of Transmission RPC interface', type: 'string', }) - .group(['rthost', 'rtport', 'rtsocket', 'qburl', 'qbuser', 'qbpass', 'trurl', 'truser', 'trpass'], 'When auth=none:') + .group( + [ + 'dehost', + 'deport', + 'deuser', + 'depass', + 'rthost', + 'rtport', + 'rtsocket', + 'qburl', + 'qbuser', + 'qbpass', + 'trurl', + 'truser', + 'trpass', + ], + 'When auth=none:', + ) .option('ssl', { default: false, describe: 'Enable SSL, key.pem and fullchain.pem needed in runtime directory', @@ -262,6 +295,16 @@ if (argv.rtsocket != null || argv.rthost != null) { username: argv.truser, password: argv.trpass, }; +} else if (argv.dehost != null) { + connectionSettings = { + client: 'Deluge', + type: 'rpc', + version: 1, + host: argv.dehost, + port: argv.deport, + username: argv.deuser, + password: argv.depass, + }; } let authMethod: Config['authMethod'] = 'default'; diff --git a/server/services/Deluge/clientGatewayService.ts b/server/services/Deluge/clientGatewayService.ts new file mode 100644 index 00000000..ce75cefd --- /dev/null +++ b/server/services/Deluge/clientGatewayService.ts @@ -0,0 +1,180 @@ +import type { + AddTorrentByFileOptions, + AddTorrentByURLOptions, + ReannounceTorrentsOptions, + SetTorrentsTagsOptions, +} from '@shared/schema/api/torrents'; +import type { + CheckTorrentsOptions, + DeleteTorrentsOptions, + MoveTorrentsOptions, + SetTorrentContentsPropertiesOptions, + SetTorrentsInitialSeedingOptions, + SetTorrentsPriorityOptions, + SetTorrentsSequentialOptions, + SetTorrentsTrackersOptions, + StartTorrentsOptions, + StopTorrentsOptions, +} from '@shared/types/api/torrents'; +import type {ClientSettings} from '@shared/types/ClientSettings'; +import type {DelugeConnectionSettings} from '@shared/schema/ClientConnectionSettings'; +import type {TorrentContent} from '@shared/types/TorrentContent'; +import type {TorrentListSummary, TorrentProperties} from '@shared/types/Torrent'; +import type {TorrentPeer} from '@shared/types/TorrentPeer'; +import type {TorrentTracker} from '@shared/types/TorrentTracker'; +import type {TransferSummary} from '@shared/types/TransferData'; +import type {SetClientSettingsOptions} from '@shared/types/api/client'; + +import ClientGatewayService from '../interfaces/clientGatewayService'; +import ClientRequestManager from './clientRequestManager'; + +class DelugeClientGatewayService extends ClientGatewayService { + private clientRequestManager = new ClientRequestManager(this.user.client as DelugeConnectionSettings); + + async addTorrentsByFile({ + files, + destination, + tags, + isBasePath, + isCompleted, + isInitialSeeding, + isSequential, + start, + }: Required): Promise { + return []; + } + + async addTorrentsByURL({ + urls, + cookies, + destination, + tags, + isBasePath, + isCompleted, + isSequential, + start, + }: Required): Promise { + return []; + } + + async checkTorrents({hashes}: CheckTorrentsOptions): Promise { + return; + } + + async getTorrentContents(hash: TorrentProperties['hash']): Promise> { + return []; + } + + async getTorrentPeers(hash: TorrentProperties['hash']): Promise> { + return []; + } + + async getTorrentTrackers(hash: TorrentProperties['hash']): Promise> { + return []; + } + + async moveTorrents({hashes, destination}: MoveTorrentsOptions): Promise { + return; + } + + async reannounceTorrents({hashes}: ReannounceTorrentsOptions): Promise { + return; + } + + async removeTorrents({hashes, deleteData}: DeleteTorrentsOptions): Promise { + return; + } + + async setTorrentsInitialSeeding({hashes, isInitialSeeding}: SetTorrentsInitialSeedingOptions): Promise { + return; + } + + async setTorrentsPriority({hashes, priority}: SetTorrentsPriorityOptions): Promise { + return; + } + + async setTorrentsSequential({hashes, isSequential}: SetTorrentsSequentialOptions): Promise { + return; + } + + async setTorrentsTags({hashes, tags}: SetTorrentsTagsOptions): Promise { + return; + } + + async setTorrentsTrackers({hashes, trackers}: SetTorrentsTrackersOptions): Promise { + return; + } + + async setTorrentContentsPriority( + hash: string, + {indices, priority}: SetTorrentContentsPropertiesOptions, + ): Promise { + return; + } + + async startTorrents({hashes}: StartTorrentsOptions): Promise { + return; + } + + async stopTorrents({hashes}: StopTorrentsOptions): Promise { + return; + } + + async fetchTorrentList(): Promise { + return { + id: Date.now(), + torrents: {}, + }; + } + + async fetchTransferSummary(): Promise { + return { + downRate: 0, + downTotal: 0, + upRate: 0, + upTotal: 0, + }; + } + + async getClientSessionDirectory(): Promise<{path: string; case: 'lower' | 'upper'}> { + return {path: '/', case: 'lower'}; + } + + async getClientSettings(): Promise { + return { + dht: false, + dhtPort: 0, + directoryDefault: '/', + networkHttpMaxOpen: 0, + networkLocalAddress: [''], + networkMaxOpenFiles: 0, + networkPortOpen: false, + networkPortRandom: false, + networkPortRange: '', + piecesHashOnCompletion: false, + piecesMemoryMax: 0, + protocolPex: false, + throttleGlobalDownSpeed: 0, + throttleGlobalUpSpeed: 0, + throttleMaxPeersNormal: 0, + throttleMaxPeersSeed: 0, + throttleMaxDownloads: 0, + throttleMaxDownloadsGlobal: 0, + throttleMaxUploads: 0, + throttleMaxUploadsGlobal: 0, + throttleMinPeersNormal: 0, + throttleMinPeersSeed: 0, + trackersNumWant: 0, + }; + } + + async setClientSettings(settings: SetClientSettingsOptions): Promise { + return; + } + + async testGateway(): Promise { + return; + } +} + +export default DelugeClientGatewayService; diff --git a/server/services/Deluge/clientRequestManager.ts b/server/services/Deluge/clientRequestManager.ts new file mode 100644 index 00000000..d757c04b --- /dev/null +++ b/server/services/Deluge/clientRequestManager.ts @@ -0,0 +1,7 @@ +import type {DelugeConnectionSettings} from '@shared/schema/ClientConnectionSettings'; + +class ClientRequestManager { + constructor(connectionSettings: DelugeConnectionSettings) {} +} + +export default ClientRequestManager; diff --git a/server/services/index.ts b/server/services/index.ts index e0ce7752..a1841adc 100644 --- a/server/services/index.ts +++ b/server/services/index.ts @@ -8,6 +8,7 @@ import SettingService from './settingService'; import TaxonomyService from './taxonomyService'; import TorrentService from './torrentService'; +import DelugeClientGatewayService from './Deluge/clientGatewayService'; import QBittorrentClientGatewayService from './qBittorrent/clientGatewayService'; import RTorrentClientGatewayService from './rTorrent/clientGatewayService'; import TransmissionClientGatewayService from './Transmission/clientGatewayService'; @@ -26,6 +27,8 @@ const serviceInstances: Record = {}; const newClientGatewayService = (user: UserInDatabase): ClientGatewayService => { switch (user.client.client) { + case 'Deluge': + return new DelugeClientGatewayService(user); case 'qBittorrent': return new QBittorrentClientGatewayService(user); case 'rTorrent': diff --git a/shared/schema/ClientConnectionSettings.ts b/shared/schema/ClientConnectionSettings.ts index a08d4a67..507beaa9 100644 --- a/shared/schema/ClientConnectionSettings.ts +++ b/shared/schema/ClientConnectionSettings.ts @@ -3,9 +3,11 @@ import type {infer as zodInfer} from 'zod'; const delugeConnectionSettingsSchema = object({ client: literal('Deluge'), - type: literal('web'), + type: literal('rpc'), version: literal(1), - url: string().url(), + host: string(), + port: number(), + username: string(), password: string(), }); @@ -60,6 +62,7 @@ const transmissionConnectionSettingsSchema = object({ export type TransmissionConnectionSettings = zodInfer; export const clientConnectionSettingsSchema = union([ + delugeConnectionSettingsSchema, qBittorrentConnectionSettingsSchema, rTorrentConnectionSettingsSchema, transmissionConnectionSettingsSchema,