Skip to content

Commit 0a745d1

Browse files
committed
Add URL parsing & Add Clarity in New Client Page
Implements #45 & #47
1 parent 0d76c27 commit 0a745d1

File tree

8 files changed

+292
-161
lines changed

8 files changed

+292
-161
lines changed

Deluge Remote.xcodeproj/project.pbxproj

+2-6
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
47599CAD21E30BB3001CD9C7 /* HUDAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47599CAC21E30BB3001CD9C7 /* HUDAlert.swift */; };
4242
475A459A2589D042003B0EF9 /* TorrentInfoTableModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 475A45992589D042003B0EF9 /* TorrentInfoTableModel.swift */; };
4343
476A9BBA21E83822009C0971 /* Host.swift in Sources */ = {isa = PBXBuildFile; fileRef = 476A9BB921E83822009C0971 /* Host.swift */; };
44-
477BFAEF21E442F8008E80CF /* DelugeRequestRetrier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 477BFAEE21E442F8008E80CF /* DelugeRequestRetrier.swift */; };
4544
477BFAF121E4748B008E80CF /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 477BFAF021E4748B008E80CF /* String.swift */; };
4645
477D7ADB21D3299300F78CE1 /* ClientConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 477D7ADA21D3299300F78CE1 /* ClientConfig.swift */; };
4746
477D7B3221D3EFE000F78CE1 /* ClientManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 477D7B3121D3EFE000F78CE1 /* ClientManager.swift */; };
@@ -116,7 +115,6 @@
116115
47599CAC21E30BB3001CD9C7 /* HUDAlert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HUDAlert.swift; sourceTree = "<group>"; };
117116
475A45992589D042003B0EF9 /* TorrentInfoTableModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TorrentInfoTableModel.swift; sourceTree = "<group>"; };
118117
476A9BB921E83822009C0971 /* Host.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Host.swift; sourceTree = "<group>"; };
119-
477BFAEE21E442F8008E80CF /* DelugeRequestRetrier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DelugeRequestRetrier.swift; sourceTree = "<group>"; };
120118
477BFAF021E4748B008E80CF /* String.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = String.swift; sourceTree = "<group>"; };
121119
477D7ADA21D3299300F78CE1 /* ClientConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientConfig.swift; sourceTree = "<group>"; };
122120
477D7B3121D3EFE000F78CE1 /* ClientManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientManager.swift; sourceTree = "<group>"; };
@@ -300,7 +298,6 @@
300298
children = (
301299
47C20BC122268B4B0069A9B0 /* NetworkReachability.swift */,
302300
471602761DD433A700727CBD /* DelugeClient.swift */,
303-
477BFAEE21E442F8008E80CF /* DelugeRequestRetrier.swift */,
304301
477D7B3121D3EFE000F78CE1 /* ClientManager.swift */,
305302
473CB8C42596A8E100A4B3EF /* DelugeAPIRouter.swift */,
306303
);
@@ -540,7 +537,6 @@
540537
47B0E3CD21E07A1900E3056A /* MainTableViewCell.swift in Sources */,
541538
473D1F7C258B1F7000045DB0 /* TorrentConnectedClientCell.swift in Sources */,
542539
471477672586F37B0019A278 /* TorrentDetailViewTabController.swift in Sources */,
543-
477BFAEF21E442F8008E80CF /* DelugeRequestRetrier.swift in Sources */,
544540
472595E42594596E00BBFE10 /* SettingsTableViewModel.swift in Sources */,
545541
47C22F42235643AB00E85A30 /* PromiseKit.swift in Sources */,
546542
471477622586A1270019A278 /* TorrentUploadInfo.swift in Sources */,
@@ -728,7 +724,7 @@
728724
"@executable_path/Frameworks",
729725
);
730726
LIBRARY_SEARCH_PATHS = "";
731-
MARKETING_VERSION = 1.5.4;
727+
MARKETING_VERSION = 1.5.5;
732728
OTHER_LDFLAGS = "-ObjC";
733729
PRODUCT_BUNDLE_IDENTIFIER = "io.rudybermudez.Deluge-Remote";
734730
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -760,7 +756,7 @@
760756
"@executable_path/Frameworks",
761757
);
762758
LIBRARY_SEARCH_PATHS = "";
763-
MARKETING_VERSION = 1.5.4;
759+
MARKETING_VERSION = 1.5.5;
764760
OTHER_LDFLAGS = "-ObjC";
765761
PRODUCT_BUNDLE_IDENTIFIER = "io.rudybermudez.Deluge-Remote";
766762
PRODUCT_NAME = "$(TARGET_NAME)";

Deluge Remote/Resources/Base.lproj/Main.storyboard

+110-108
Large diffs are not rendered by default.

Deluge Remote/Sources/API/DelugeAPIRouter.swift

+13
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ enum DelugeRouter: URLRequestConvertible {
5151
/// Add a torrent file to the server
5252
case addTorrentFile(ClientConfig, filename: String, data: Data, config: TorrentConfig)
5353

54+
/// Adds a torrent to the server from a URL
55+
case addTorrentURL(ClientConfig, URL, TorrentConfig)
56+
57+
case downloadTorrent(ClientConfig, from: URL)
58+
5459
/// Upload a torrent to the server
5560
///
5661
/// **Note**: This does not add the torrent to the client
@@ -125,6 +130,10 @@ enum DelugeRouter: URLRequestConvertible {
125130
return config.url
126131
case .addTorrentFile(let config, filename: _, data: _, config: _):
127132
return config.url
133+
case .addTorrentURL(let config, _, _):
134+
return config.url
135+
case .downloadTorrent(let config, from: _):
136+
return config.url
128137
case .uploadTorrentFile(let config, _):
129138
return config.url
130139
case .getUploadedTorrentInfo(let config, filename: _):
@@ -180,6 +189,10 @@ enum DelugeRouter: URLRequestConvertible {
180189
return paramsFor(method: "core.remove_torrent", with: [hash, withData])
181190
case .addTorrentMagnet(_, let url, config: let config):
182191
return paramsFor(method: "core.add_torrent_magnet", with: [url.absoluteString, config.toParams()])
192+
case .downloadTorrent(_, from: let url):
193+
return paramsFor(method: "web.download_torrent_from_url", with: [url.absoluteString, []])
194+
case .addTorrentURL(_, let url, let config):
195+
return paramsFor(method: "core.add_torrent_url", with: [url.absoluteString, config.toParams()])
183196
case .getMagnetInfo(_, let url):
184197
return paramsFor(method: "web.get_magnet_info", with: [url.absoluteString])
185198
case .addTorrentFile(_, filename: let filename, data: let data, config: let config):

Deluge Remote/Sources/API/DelugeClient.swift

+67
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,47 @@ class DelugeClient {
466466
}
467467
}
468468
}
469+
470+
func downloadTorrent(from url: URL)-> Promise<String> { return Promise { seal in
471+
Manager.request(DelugeRouter.downloadTorrent(clientConfig, from: url))
472+
.validate().responseDecodable(of: DelugeResponse<String>?.self, queue: self.queue) { response in
473+
switch response.result {
474+
case .success(let data):
475+
if let result = data?.result {
476+
seal.fulfill(result)
477+
} else {
478+
if let error = data?.error {
479+
seal.reject(ClientError.apiError(error))
480+
} else {
481+
seal.reject(ClientError.unexpectedResponse)
482+
}
483+
}
484+
case .failure(let error): seal.reject(ClientError.other(error))
485+
}
486+
}
487+
}
488+
}
469489

490+
func addTorrentURL(_ url: URL, with config: TorrentConfig) -> Promise<String> { return Promise { seal in
491+
Manager.request(DelugeRouter.addTorrentURL(clientConfig, url, config))
492+
.validate().responseDecodable(of: DelugeResponse<String>?.self, queue: self.queue) { response in
493+
switch response.result {
494+
case .success(let data):
495+
if let result = data?.result {
496+
seal.fulfill(result)
497+
} else {
498+
if let error = data?.error {
499+
seal.reject(ClientError.apiError(error))
500+
} else {
501+
seal.reject(ClientError.unexpectedResponse)
502+
}
503+
}
504+
case .failure(let error): seal.reject(ClientError.other(error))
505+
}
506+
}
507+
}
508+
}
509+
470510
func addTorrentFile(fileName: String, torrent: Data, with config: TorrentConfig) -> Promise<String> { return Promise { seal in
471511
Manager.request(DelugeRouter.addTorrentFile(self.clientConfig, filename: fileName, data: torrent, config: config))
472512
.validate().responseDecodable(of: DelugeResponse<String>?.self, queue: self.queue) { response in
@@ -542,6 +582,33 @@ class DelugeClient {
542582
}
543583
}
544584
}
585+
586+
func getTorrentInfo(url: URL) -> Promise<UploadedTorrentInfo> { return Promise { seal in
587+
firstly { downloadTorrent(from: url) }
588+
.done { fileName in
589+
self.Manager.request(DelugeRouter.getUploadedTorrentInfo(self.clientConfig, filename: fileName))
590+
.validate().responseJSON(queue: self.queue) { response in
591+
switch response.result {
592+
case .success(let json):
593+
guard
594+
let dict = json as? JSON,
595+
let result = dict["result"] as? JSON,
596+
let info = UploadedTorrentInfo(json: result)
597+
else {
598+
seal.reject(ClientError.unexpectedResponse)
599+
return
600+
}
601+
seal.fulfill(info)
602+
case .failure(let error):
603+
seal.reject(ClientError.other(error))
604+
}
605+
}
606+
607+
}.catch { error in
608+
seal.reject(error)
609+
}
610+
}
611+
}
545612

546613
func getAddTorrentConfig() -> Promise<TorrentConfig> { return Promise { seal in
547614
Manager.request(DelugeRouter.getDefaultTorrentConfig(self.clientConfig))

Deluge Remote/Sources/API/DelugeRequestRetrier.swift

-12
This file was deleted.

Deluge Remote/Sources/Protocols/TorrentHandler.swift

+4
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@ import Foundation
1010

1111
enum TorrentType: String {
1212
case magnet = "Magnet Link"
13+
case url = "Torrent URL"
1314
case file = "Torrent File"
1415
}
1516

1617
enum TorrentData
1718
{
1819
case magnet(URL)
20+
case url(URL)
1921
case file(Data)
2022

2123
var type: TorrentType {
2224
switch self {
25+
case .url(_):
26+
return TorrentType.url
2327
case .magnet(_):
2428
return TorrentType.magnet
2529
case .file(_):

Deluge Remote/Sources/View Controllers/AddClientViewController.swift

+7-2
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,15 @@ class AddClientViewController: UITableViewController, Storyboarded {
118118
// MARK: - Table view data source
119119

120120
override func numberOfSections(in tableView: UITableView) -> Int {
121-
return 1
121+
return 3
122122
}
123123

124124
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
125-
return 7
125+
switch section {
126+
case 0: return 1
127+
case 1: return 5
128+
case 2: return 1
129+
default: return 0
130+
}
126131
}
127132
}

0 commit comments

Comments
 (0)