Skip to content
This repository was archived by the owner on Mar 4, 2021. It is now read-only.

Commit 0fbace4

Browse files
committed
feat:增加Transmission的支持(未经过测试)
1 parent f2cace9 commit 0fbace4

File tree

6 files changed

+376
-9
lines changed

6 files changed

+376
-9
lines changed

src/interfaces/BtClient/AbstractClient.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export interface Torrent {
7979
}
8080

8181
export interface TorrentFilterRules {
82+
ids?: any;
8283
complete?: boolean;
8384
}
8485

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
import {
2+
AddTorrentOptions,
3+
Torrent,
4+
TorrentClientConfig,
5+
TorrentFilterRules
6+
} from "@/interfaces/BtClient/AbstractClient";
7+
8+
export interface TransmissionBaseResponse {
9+
arguments: any;
10+
result: 'success' | string;
11+
tag?: number
12+
}
13+
14+
export interface TransmissionTorrentGetResponse extends TransmissionBaseResponse {
15+
arguments: {
16+
torrents: rawTorrent[]
17+
}
18+
}
19+
20+
export interface AddTorrentResponse extends TransmissionBaseResponse {
21+
arguments: {
22+
'torrent-added': {
23+
id: number;
24+
hashString: string;
25+
name: string;
26+
};
27+
};
28+
}
29+
30+
export type TransmissionTorrentIds = number | Array<number | string> | 'recently-active'
31+
32+
export type TransmissionRequestMethod =
33+
'session-get' | 'session-stats' |
34+
'torrent-get' | 'torrent-add' | 'torrent-start' | 'torrent-stop' | 'torrent-remove'
35+
36+
export interface TransmissionAddTorrentOptions extends AddTorrentOptions {
37+
"download-dir": string,
38+
filename: string,
39+
metainfo: string,
40+
paused: boolean,
41+
42+
}
43+
44+
export interface TransmissionTorrent extends Torrent {
45+
id: number | string;
46+
}
47+
48+
export interface TransmissionTorrentFilterRules extends TorrentFilterRules {
49+
ids?: TransmissionTorrentIds;
50+
}
51+
52+
export interface TransmissionArguments {
53+
54+
}
55+
56+
export interface TransmissionTorrentBaseArguments extends TransmissionArguments {
57+
ids?: TransmissionTorrentIds
58+
}
59+
60+
export interface TransmissionTorrentGetArguments extends TransmissionTorrentBaseArguments {
61+
fields: TransmissionTorrentsField[]
62+
}
63+
64+
export interface TransmissionTorrentRemoveArguments extends TransmissionTorrentBaseArguments {
65+
'delete-local-data'?: boolean
66+
}
67+
68+
export interface TransmissionTorrentClientConfig extends TorrentClientConfig {
69+
70+
}
71+
72+
// 这里只写出了部分我们需要的
73+
export interface rawTorrent {
74+
addedDate: number,
75+
id: number,
76+
hashString: string,
77+
isFinished: boolean,
78+
name: string,
79+
percentDone: number,
80+
uploadRatio: number,
81+
downloadDir: string,
82+
status: number,
83+
totalSize: number,
84+
leftUntilDone: number,
85+
labels: string[]
86+
}
87+
88+
export type TransmissionTorrentsField =
89+
'activityDate'
90+
| 'addedDate'
91+
| 'bandwidthPriority'
92+
| 'comment'
93+
| 'corruptEver'
94+
| 'creator'
95+
| 'dateCreated'
96+
| 'desiredAvailable'
97+
| 'doneDate'
98+
| 'downloadDir'
99+
| 'downloadedEver'
100+
| 'downloadLimit'
101+
| 'downloadLimited'
102+
| 'editDate'
103+
| 'error'
104+
| 'errorString'
105+
| 'eta'
106+
| 'etaIdle'
107+
| 'files'
108+
| 'fileStats'
109+
| 'hashString'
110+
| 'haveUnchecked'
111+
| 'haveValid'
112+
| 'honorsSessionLimits'
113+
| 'id'
114+
| 'isFinished'
115+
| 'isPrivate'
116+
| 'isStalled'
117+
| 'labels'
118+
| 'leftUntilDone'
119+
| 'magnetLink'
120+
| 'manualAnnounceTime'
121+
| 'maxConnectedPeers'
122+
| 'metadataPercentComplete'
123+
| 'name'
124+
| 'peer-limit'
125+
| 'peers'
126+
| 'peersConnected'
127+
| 'peersFrom'
128+
| 'peersGettingFromUs'
129+
| 'peersSendingToUs'
130+
| 'percentDone'
131+
| 'pieces'
132+
| 'pieceCount'
133+
| 'pieceSize'
134+
| 'priorities'
135+
| 'queuePosition'
136+
| 'rateDownload (B/s)'
137+
| 'rateUpload (B/s)'
138+
| 'recheckProgress'
139+
| 'secondsDownloading'
140+
| 'secondsSeeding'
141+
| 'seedIdleLimit'
142+
| 'seedIdleMode'
143+
| 'seedRatioLimit'
144+
| 'seedRatioMode'
145+
| 'sizeWhenDone'
146+
| 'startDate'
147+
| 'status'
148+
| 'trackers'
149+
| 'trackerStats'
150+
| 'totalSize'
151+
| 'torrentFile'
152+
| 'uploadedEver'
153+
| 'uploadLimit'
154+
| 'uploadLimited'
155+
| 'uploadRatio'
156+
| 'wanted'
157+
| 'webseeds'
158+
| 'webseedsSendingToUs'

src/plugins/btclient/factory.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import {TorrentClient, TorrentClientConfig} from "@/interfaces/BtClient/AbstractClient";
22
import Qbittorrent from "@/plugins/btclient/qbittorrent";
3+
import Transmission from "@/plugins/btclient/transmission";
34

45
export default function (config: TorrentClientConfig): TorrentClient {
56
switch (config.type) {
67
case "qbittorrent":
78
return new Qbittorrent(config)
9+
case "transmission":
10+
return new Transmission(config)
811
case "deluge":
912
case "rtorrent":
10-
case "transmission":
1113
return new Qbittorrent(config) // FIXME
1214
}
1315
}

src/plugins/btclient/qbittorrent.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,9 @@ export default class Qbittorrent implements TorrentClient {
7373
})
7474
}
7575

76-
async addTorrent(urls: string, options: Partial<QbittorrentAddTorrentOptions> | undefined): Promise<boolean> {
76+
async addTorrent(urls: string, options: Partial<QbittorrentAddTorrentOptions> = {}): Promise<boolean> {
7777
const formData = new FormData()
7878

79-
// 开始处理options
80-
options = options || {};
81-
8279
// 处理链接
8380
if (urls.startsWith('magnet:') || !options.localDownload) {
8481
formData.append('urls', urls)

0 commit comments

Comments
 (0)