mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-06 00:25:43 +00:00
feat: auto recognize magnet uri (#230)
This commit is contained in:
2 files changed
+22
No files matched your search
@@ -13,6 +13,7 @@ class CreateController extends GetxController
|
||||
final isResolving = false.obs;
|
||||
final showAdvanced = false.obs;
|
||||
late TabController advancedTabController;
|
||||
final oldUrl = "".obs;
|
||||
final fileDataUri = "".obs;
|
||||
|
||||
@override
|
||||
|
||||
@@ -55,7 +55,10 @@ class CreateView extends GetView<CreateController> {
|
||||
_urlController.text = value!.text!;
|
||||
_urlController.selection = TextSelection.fromPosition(
|
||||
TextPosition(offset: _urlController.text.length));
|
||||
return;
|
||||
}
|
||||
|
||||
recognizeMagnetUri(value!.text!);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -117,6 +120,10 @@ class CreateView extends GetView<CreateController> {
|
||||
},
|
||||
onChanged: (v) async {
|
||||
controller.clearFileDataUri();
|
||||
if (controller.oldUrl.value.isEmpty) {
|
||||
recognizeMagnetUri(v);
|
||||
}
|
||||
controller.oldUrl.value = v;
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -237,6 +244,20 @@ class CreateView extends GetView<CreateController> {
|
||||
);
|
||||
}
|
||||
|
||||
// recognize magnet uri, if length == 40, auto add magnet prefix
|
||||
recognizeMagnetUri(String text) {
|
||||
if (text.length != 40) {
|
||||
return;
|
||||
}
|
||||
final exp = RegExp(r"[0-9a-fA-F]+");
|
||||
if (exp.hasMatch(text)) {
|
||||
final uri = "magnet:?xt=urn:btih:$text";
|
||||
_urlController.text = uri;
|
||||
_urlController.selection = TextSelection.fromPosition(
|
||||
TextPosition(offset: _urlController.text.length));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _doResolve() async {
|
||||
if (controller.isResolving.value) {
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user