mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-16 13:23:41 +00:00
fix: advanced options used by default when creating task (#901)
This commit is contained in:
1 file changed
+32
-28
@@ -82,16 +82,7 @@ class CreateView extends GetView<CreateController> {
|
|||||||
_urlController.text = url;
|
_urlController.text = url;
|
||||||
_urlController.selection = TextSelection.fromPosition(
|
_urlController.selection = TextSelection.fromPosition(
|
||||||
TextPosition(offset: _urlController.text.length));
|
TextPosition(offset: _urlController.text.length));
|
||||||
final uppercaseUrl = url.toUpperCase();
|
final protocol = parseProtocol(url);
|
||||||
Protocol? protocol;
|
|
||||||
if (uppercaseUrl.startsWith("HTTP:") ||
|
|
||||||
uppercaseUrl.startsWith("HTTPS:")) {
|
|
||||||
protocol = Protocol.http;
|
|
||||||
}
|
|
||||||
if (uppercaseUrl.startsWith("MAGNET:") ||
|
|
||||||
uppercaseUrl.endsWith(".TORRENT")) {
|
|
||||||
protocol = Protocol.bt;
|
|
||||||
}
|
|
||||||
if (protocol != null) {
|
if (protocol != null) {
|
||||||
final extraHandlers = {
|
final extraHandlers = {
|
||||||
Protocol.http: () {
|
Protocol.http: () {
|
||||||
@@ -672,6 +663,20 @@ class CreateView extends GetView<CreateController> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parse protocol from url
|
||||||
|
parseProtocol(String url) {
|
||||||
|
final uppercaseUrl = url.toUpperCase();
|
||||||
|
Protocol? protocol;
|
||||||
|
if (uppercaseUrl.startsWith("HTTP:") || uppercaseUrl.startsWith("HTTPS:")) {
|
||||||
|
protocol = Protocol.http;
|
||||||
|
}
|
||||||
|
if (uppercaseUrl.startsWith("MAGNET:") ||
|
||||||
|
uppercaseUrl.endsWith(".TORRENT")) {
|
||||||
|
protocol = Protocol.bt;
|
||||||
|
}
|
||||||
|
return protocol;
|
||||||
|
}
|
||||||
|
|
||||||
// recognize magnet uri, if length == 40, auto add magnet prefix
|
// recognize magnet uri, if length == 40, auto add magnet prefix
|
||||||
recognizeMagnetUri(String text) {
|
recognizeMagnetUri(String text) {
|
||||||
if (text.length != 40) {
|
if (text.length != 40) {
|
||||||
@@ -764,24 +769,23 @@ class CreateView extends GetView<CreateController> {
|
|||||||
|
|
||||||
Object? parseReqExtra(String url) {
|
Object? parseReqExtra(String url) {
|
||||||
Object? reqExtra;
|
Object? reqExtra;
|
||||||
if (controller.showAdvanced.value) {
|
final protocol = parseProtocol(url);
|
||||||
switch (controller.advancedTabController.index) {
|
switch (protocol) {
|
||||||
case 0:
|
case Protocol.http:
|
||||||
final header = Map<String, String>.fromEntries(_httpHeaderControllers
|
final header = Map<String, String>.fromEntries(_httpHeaderControllers
|
||||||
.map((e) => MapEntry(e.name.text, e.value.text)));
|
.map((e) => MapEntry(e.name.text, e.value.text)));
|
||||||
header.removeWhere(
|
header.removeWhere(
|
||||||
(key, value) => key.trim().isEmpty || value.trim().isEmpty);
|
(key, value) => key.trim().isEmpty || value.trim().isEmpty);
|
||||||
if (header.isNotEmpty) {
|
if (header.isNotEmpty) {
|
||||||
reqExtra = ReqExtraHttp()..header = header;
|
reqExtra = ReqExtraHttp()..header = header;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case Protocol.bt:
|
||||||
if (_btTrackerController.text.trim().isNotEmpty) {
|
if (_btTrackerController.text.trim().isNotEmpty) {
|
||||||
reqExtra = ReqExtraBt()
|
reqExtra = ReqExtraBt()
|
||||||
..trackers = Util.textToLines(_btTrackerController.text);
|
..trackers = Util.textToLines(_btTrackerController.text);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return reqExtra;
|
return reqExtra;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user