Skip to content

Commit 2b83a73

Browse files
authored
fix: advanced options used by default when creating task (#901)
1 parent 447f599 commit 2b83a73

File tree

1 file changed

+32
-28
lines changed

1 file changed

+32
-28
lines changed

ui/flutter/lib/app/modules/create/views/create_view.dart

+32-28
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,7 @@ class CreateView extends GetView<CreateController> {
8282
_urlController.text = url;
8383
_urlController.selection = TextSelection.fromPosition(
8484
TextPosition(offset: _urlController.text.length));
85-
final uppercaseUrl = url.toUpperCase();
86-
Protocol? protocol;
87-
if (uppercaseUrl.startsWith("HTTP:") ||
88-
uppercaseUrl.startsWith("HTTPS:")) {
89-
protocol = Protocol.http;
90-
}
91-
if (uppercaseUrl.startsWith("MAGNET:") ||
92-
uppercaseUrl.endsWith(".TORRENT")) {
93-
protocol = Protocol.bt;
94-
}
85+
final protocol = parseProtocol(url);
9586
if (protocol != null) {
9687
final extraHandlers = {
9788
Protocol.http: () {
@@ -672,6 +663,20 @@ class CreateView extends GetView<CreateController> {
672663
);
673664
}
674665

666+
// parse protocol from url
667+
parseProtocol(String url) {
668+
final uppercaseUrl = url.toUpperCase();
669+
Protocol? protocol;
670+
if (uppercaseUrl.startsWith("HTTP:") || uppercaseUrl.startsWith("HTTPS:")) {
671+
protocol = Protocol.http;
672+
}
673+
if (uppercaseUrl.startsWith("MAGNET:") ||
674+
uppercaseUrl.endsWith(".TORRENT")) {
675+
protocol = Protocol.bt;
676+
}
677+
return protocol;
678+
}
679+
675680
// recognize magnet uri, if length == 40, auto add magnet prefix
676681
recognizeMagnetUri(String text) {
677682
if (text.length != 40) {
@@ -764,24 +769,23 @@ class CreateView extends GetView<CreateController> {
764769

765770
Object? parseReqExtra(String url) {
766771
Object? reqExtra;
767-
if (controller.showAdvanced.value) {
768-
switch (controller.advancedTabController.index) {
769-
case 0:
770-
final header = Map<String, String>.fromEntries(_httpHeaderControllers
771-
.map((e) => MapEntry(e.name.text, e.value.text)));
772-
header.removeWhere(
773-
(key, value) => key.trim().isEmpty || value.trim().isEmpty);
774-
if (header.isNotEmpty) {
775-
reqExtra = ReqExtraHttp()..header = header;
776-
}
777-
break;
778-
case 1:
779-
if (_btTrackerController.text.trim().isNotEmpty) {
780-
reqExtra = ReqExtraBt()
781-
..trackers = Util.textToLines(_btTrackerController.text);
782-
}
783-
break;
784-
}
772+
final protocol = parseProtocol(url);
773+
switch (protocol) {
774+
case Protocol.http:
775+
final header = Map<String, String>.fromEntries(_httpHeaderControllers
776+
.map((e) => MapEntry(e.name.text, e.value.text)));
777+
header.removeWhere(
778+
(key, value) => key.trim().isEmpty || value.trim().isEmpty);
779+
if (header.isNotEmpty) {
780+
reqExtra = ReqExtraHttp()..header = header;
781+
}
782+
break;
783+
case Protocol.bt:
784+
if (_btTrackerController.text.trim().isNotEmpty) {
785+
reqExtra = ReqExtraBt()
786+
..trackers = Util.textToLines(_btTrackerController.text);
787+
}
788+
break;
785789
}
786790
return reqExtra;
787791
}

0 commit comments

Comments
 (0)