server: Deluge: create empty services

This commit is contained in:
Jesse Chan
2021-05-03 19:03:33 +08:00
parent 0e954cf66f
commit 69a9c667a5
5 changed files with 239 additions and 3 deletions
+44 -1
View File
@@ -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';
@@ -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<AddTorrentByFileOptions>): Promise<string[]> {
return [];
}
async addTorrentsByURL({
urls,
cookies,
destination,
tags,
isBasePath,
isCompleted,
isSequential,
start,
}: Required<AddTorrentByURLOptions>): Promise<string[]> {
return [];
}
async checkTorrents({hashes}: CheckTorrentsOptions): Promise<void> {
return;
}
async getTorrentContents(hash: TorrentProperties['hash']): Promise<Array<TorrentContent>> {
return [];
}
async getTorrentPeers(hash: TorrentProperties['hash']): Promise<Array<TorrentPeer>> {
return [];
}
async getTorrentTrackers(hash: TorrentProperties['hash']): Promise<Array<TorrentTracker>> {
return [];
}
async moveTorrents({hashes, destination}: MoveTorrentsOptions): Promise<void> {
return;
}
async reannounceTorrents({hashes}: ReannounceTorrentsOptions): Promise<void> {
return;
}
async removeTorrents({hashes, deleteData}: DeleteTorrentsOptions): Promise<void> {
return;
}
async setTorrentsInitialSeeding({hashes, isInitialSeeding}: SetTorrentsInitialSeedingOptions): Promise<void> {
return;
}
async setTorrentsPriority({hashes, priority}: SetTorrentsPriorityOptions): Promise<void> {
return;
}
async setTorrentsSequential({hashes, isSequential}: SetTorrentsSequentialOptions): Promise<void> {
return;
}
async setTorrentsTags({hashes, tags}: SetTorrentsTagsOptions): Promise<void> {
return;
}
async setTorrentsTrackers({hashes, trackers}: SetTorrentsTrackersOptions): Promise<void> {
return;
}
async setTorrentContentsPriority(
hash: string,
{indices, priority}: SetTorrentContentsPropertiesOptions,
): Promise<void> {
return;
}
async startTorrents({hashes}: StartTorrentsOptions): Promise<void> {
return;
}
async stopTorrents({hashes}: StopTorrentsOptions): Promise<void> {
return;
}
async fetchTorrentList(): Promise<TorrentListSummary> {
return {
id: Date.now(),
torrents: {},
};
}
async fetchTransferSummary(): Promise<TransferSummary> {
return {
downRate: 0,
downTotal: 0,
upRate: 0,
upTotal: 0,
};
}
async getClientSessionDirectory(): Promise<{path: string; case: 'lower' | 'upper'}> {
return {path: '/', case: 'lower'};
}
async getClientSettings(): Promise<ClientSettings> {
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<void> {
return;
}
async testGateway(): Promise<void> {
return;
}
}
export default DelugeClientGatewayService;
@@ -0,0 +1,7 @@
import type {DelugeConnectionSettings} from '@shared/schema/ClientConnectionSettings';
class ClientRequestManager {
constructor(connectionSettings: DelugeConnectionSettings) {}
}
export default ClientRequestManager;
+3
View File
@@ -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<string, ServiceInstances> = {};
const newClientGatewayService = (user: UserInDatabase): ClientGatewayService => {
switch (user.client.client) {
case 'Deluge':
return new DelugeClientGatewayService(user);
case 'qBittorrent':
return new QBittorrentClientGatewayService(user);
case 'rTorrent':
+5 -2
View File
@@ -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<typeof transmissionConnectionSettingsSchema>;
export const clientConnectionSettingsSchema = union([
delugeConnectionSettingsSchema,
qBittorrentConnectionSettingsSchema,
rTorrentConnectionSettingsSchema,
transmissionConnectionSettingsSchema,