@@ -82,16 +82,7 @@ class CreateView extends GetView<CreateController> {
82
82
_urlController.text = url;
83
83
_urlController.selection = TextSelection .fromPosition (
84
84
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);
95
86
if (protocol != null ) {
96
87
final extraHandlers = {
97
88
Protocol .http: () {
@@ -672,6 +663,20 @@ class CreateView extends GetView<CreateController> {
672
663
);
673
664
}
674
665
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
+
675
680
// recognize magnet uri, if length == 40, auto add magnet prefix
676
681
recognizeMagnetUri (String text) {
677
682
if (text.length != 40 ) {
@@ -764,24 +769,23 @@ class CreateView extends GetView<CreateController> {
764
769
765
770
Object ? parseReqExtra (String url) {
766
771
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 ;
785
789
}
786
790
return reqExtra;
787
791
}
0 commit comments