mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-18 06:13:42 +00:00
feat: support create task directly (#262)
This commit is contained in:
12 files changed
+150
-104
No files matched your search
@@ -161,7 +161,7 @@ func (f *Fetcher) Wait() (err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !selected {
|
if !selected {
|
||||||
util.SafeRemove(filepath.Join(f.meta.Opts.Path, file.Path()))
|
util.SafeRemove(filepath.Join(f.meta.Opts.Path, f.meta.Res.Name, file.Path()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
@@ -202,7 +202,7 @@ func (f *Fetcher) updateRes() {
|
|||||||
Size: file.Length(),
|
Size: file.Length(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res.CalcSize()
|
res.CalcSize(nil)
|
||||||
f.meta.Res = res
|
f.meta.Res = res
|
||||||
if f.meta.Opts != nil {
|
if f.meta.Opts != nil {
|
||||||
f.meta.Opts.InitSelectFiles(len(res.Files))
|
f.meta.Opts.InitSelectFiles(len(res.Files))
|
||||||
|
|||||||
+5
-2
@@ -3,6 +3,7 @@ package base
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/GopeedLab/gopeed/pkg/util"
|
"github.com/GopeedLab/gopeed/pkg/util"
|
||||||
|
"golang.org/x/exp/slices"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Request download request
|
// Request download request
|
||||||
@@ -47,11 +48,13 @@ func (r *Resource) Validate() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Resource) CalcSize() {
|
func (r *Resource) CalcSize(selectFiles []int) {
|
||||||
var size int64
|
var size int64
|
||||||
for _, file := range r.Files {
|
for i, file := range r.Files {
|
||||||
|
if len(selectFiles) == 0 || slices.Contains(selectFiles, i) {
|
||||||
size += file.Size
|
size += file.Size
|
||||||
}
|
}
|
||||||
|
}
|
||||||
r.Size = size
|
r.Size = size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -540,11 +540,17 @@ func (d *Downloader) GetTask(id string) *Task {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Downloader) GetTasks() []*Task {
|
func (d *Downloader) GetTasks() []*Task {
|
||||||
// reverse tasks, so that the latest task is in the front
|
|
||||||
tasks := make([]*Task, len(d.tasks))
|
tasks := make([]*Task, len(d.tasks))
|
||||||
for i := 0; i < len(d.tasks); i++ {
|
for i := 0; i < len(d.tasks); i++ {
|
||||||
tasks[i] = d.tasks[len(d.tasks)-i-1]
|
tasks[i] = d.tasks[i]
|
||||||
}
|
}
|
||||||
|
// sort tasks by status, order by Status(if(running,1,0)) desc, CreatedAt desc
|
||||||
|
sort.Slice(tasks, func(i, j int) bool {
|
||||||
|
if tasks[i].Status != tasks[j].Status {
|
||||||
|
return tasks[i].Status == base.DownloadStatusRunning
|
||||||
|
}
|
||||||
|
return tasks[i].CreatedAt.After(tasks[j].CreatedAt)
|
||||||
|
})
|
||||||
return tasks
|
return tasks
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -579,16 +585,16 @@ func (d *Downloader) watch(task *Task) {
|
|||||||
d.emit(EventKeyError, task, err)
|
d.emit(EventKeyError, task, err)
|
||||||
} else {
|
} else {
|
||||||
task.Progress.Used = task.timer.Used()
|
task.Progress.Used = task.timer.Used()
|
||||||
if task.Size == 0 {
|
if task.Meta.Res.Size == 0 {
|
||||||
task.Size = task.fetcher.Progress().TotalDownloaded()
|
task.Meta.Res.Size = task.fetcher.Progress().TotalDownloaded()
|
||||||
task.Meta.Res.Size = task.Size
|
|
||||||
}
|
}
|
||||||
used := task.Progress.Used / int64(time.Second)
|
used := task.Progress.Used / int64(time.Second)
|
||||||
if used == 0 {
|
if used == 0 {
|
||||||
used = 1
|
used = 1
|
||||||
}
|
}
|
||||||
task.Progress.Speed = task.Size / used
|
totalSize := task.Meta.Res.Size
|
||||||
task.Progress.Downloaded = task.Size
|
task.Progress.Speed = totalSize / used
|
||||||
|
task.Progress.Downloaded = totalSize
|
||||||
task.Status = base.DownloadStatusDone
|
task.Status = base.DownloadStatusDone
|
||||||
d.storage.Put(bucketTask, task.ID, task.clone())
|
d.storage.Put(bucketTask, task.ID, task.clone())
|
||||||
d.emit(EventKeyDone, task)
|
d.emit(EventKeyDone, task)
|
||||||
@@ -741,6 +747,8 @@ func (d *Downloader) doStart(task *Task) (err error) {
|
|||||||
}
|
}
|
||||||
task.Meta.Opts.Name = newName
|
task.Meta.Opts.Name = newName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
task.Meta.Res.CalcSize(task.Meta.Opts.SelectFiles)
|
||||||
}
|
}
|
||||||
|
|
||||||
task.Progress.Speed = 0
|
task.Progress.Speed = 0
|
||||||
|
|||||||
@@ -243,7 +243,7 @@ func (d *Downloader) triggerOnResolve(req *base.Request) (res *base.Resource) {
|
|||||||
gopeed.Logger.logger.Warn().Err(err).Msgf("[%s] resource invalid", ext.buildIdentity())
|
gopeed.Logger.logger.Warn().Err(err).Msgf("[%s] resource invalid", ext.buildIdentity())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Res.CalcSize()
|
ctx.Res.CalcSize(nil)
|
||||||
}
|
}
|
||||||
res = ctx.Res
|
res = ctx.Res
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ type Task struct {
|
|||||||
Meta *fetcher.FetcherMeta `json:"meta"`
|
Meta *fetcher.FetcherMeta `json:"meta"`
|
||||||
Status base.Status `json:"status"`
|
Status base.Status `json:"status"`
|
||||||
Progress *Progress `json:"progress"`
|
Progress *Progress `json:"progress"`
|
||||||
Size int64 `json:"size"`
|
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
|
||||||
fetcherBuilder fetcher.FetcherBuilder
|
fetcherBuilder fetcher.FetcherBuilder
|
||||||
@@ -50,7 +49,6 @@ func (t *Task) clone() *Task {
|
|||||||
Meta: t.Meta,
|
Meta: t.Meta,
|
||||||
Status: t.Status,
|
Status: t.Status,
|
||||||
Progress: t.Progress,
|
Progress: t.Progress,
|
||||||
Size: t.Size,
|
|
||||||
CreatedAt: t.CreatedAt,
|
CreatedAt: t.CreatedAt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
"donate": "Donate",
|
"donate": "Donate",
|
||||||
"exit": "Exit",
|
"exit": "Exit",
|
||||||
"create": "Create Task",
|
"create": "Create Task",
|
||||||
|
"directDownload": "Direct Download",
|
||||||
"advancedOptions": "Advanced Options",
|
"advancedOptions": "Advanced Options",
|
||||||
"downloadLink": "Download Link",
|
"downloadLink": "Download Link",
|
||||||
"downloadLinkValid": "Please enter the download link",
|
"downloadLinkValid": "Please enter the download link",
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
"donate": "打赏",
|
"donate": "打赏",
|
||||||
"exit": "退出",
|
"exit": "退出",
|
||||||
"create": "创建任务",
|
"create": "创建任务",
|
||||||
|
"directDownload": "直接下载",
|
||||||
"advancedOptions": "高级选项",
|
"advancedOptions": "高级选项",
|
||||||
"downloadLink": "下载链接",
|
"downloadLink": "下载链接",
|
||||||
"downloadLinkValid": "请输入下载链接",
|
"downloadLinkValid": "请输入下载链接",
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ class Task {
|
|||||||
Meta meta;
|
Meta meta;
|
||||||
Status status;
|
Status status;
|
||||||
Progress progress;
|
Progress progress;
|
||||||
int size;
|
|
||||||
DateTime createdAt;
|
DateTime createdAt;
|
||||||
|
|
||||||
Task({
|
Task({
|
||||||
@@ -20,7 +19,6 @@ class Task {
|
|||||||
required this.meta,
|
required this.meta,
|
||||||
required this.status,
|
required this.status,
|
||||||
required this.progress,
|
required this.progress,
|
||||||
required this.size,
|
|
||||||
required this.createdAt,
|
required this.createdAt,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ Task _$TaskFromJson(Map<String, dynamic> json) => Task(
|
|||||||
meta: Meta.fromJson(json['meta'] as Map<String, dynamic>),
|
meta: Meta.fromJson(json['meta'] as Map<String, dynamic>),
|
||||||
status: $enumDecode(_$StatusEnumMap, json['status']),
|
status: $enumDecode(_$StatusEnumMap, json['status']),
|
||||||
progress: Progress.fromJson(json['progress'] as Map<String, dynamic>),
|
progress: Progress.fromJson(json['progress'] as Map<String, dynamic>),
|
||||||
size: json['size'] as int,
|
|
||||||
createdAt: DateTime.parse(json['createdAt'] as String),
|
createdAt: DateTime.parse(json['createdAt'] as String),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -20,7 +19,6 @@ Map<String, dynamic> _$TaskToJson(Task instance) => <String, dynamic>{
|
|||||||
'meta': instance.meta.toJson(),
|
'meta': instance.meta.toJson(),
|
||||||
'status': _$StatusEnumMap[instance.status]!,
|
'status': _$StatusEnumMap[instance.status]!,
|
||||||
'progress': instance.progress.toJson(),
|
'progress': instance.progress.toJson(),
|
||||||
'size': instance.size,
|
|
||||||
'createdAt': instance.createdAt.toIso8601String(),
|
'createdAt': instance.createdAt.toIso8601String(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,9 @@ class CreateController extends GetxController
|
|||||||
final RxList fileInfos = [].obs;
|
final RxList fileInfos = [].obs;
|
||||||
final RxList openedFolders = [].obs;
|
final RxList openedFolders = [].obs;
|
||||||
final selectedIndexes = <int>[].obs;
|
final selectedIndexes = <int>[].obs;
|
||||||
final isResolving = false.obs;
|
final isConfirming = false.obs;
|
||||||
final showAdvanced = false.obs;
|
final showAdvanced = false.obs;
|
||||||
|
final directDownload = false.obs;
|
||||||
late TabController advancedTabController;
|
late TabController advancedTabController;
|
||||||
final oldUrl = "".obs;
|
final oldUrl = "".obs;
|
||||||
final fileDataUri = "".obs;
|
final fileDataUri = "".obs;
|
||||||
|
|||||||
@@ -24,9 +24,12 @@ import '../../app/controllers/app_controller.dart';
|
|||||||
import '../controllers/create_controller.dart';
|
import '../controllers/create_controller.dart';
|
||||||
|
|
||||||
class CreateView extends GetView<CreateController> {
|
class CreateView extends GetView<CreateController> {
|
||||||
final _resolveFormKey = GlobalKey<FormState>();
|
final _confirmFormKey = GlobalKey<FormState>();
|
||||||
|
|
||||||
final _urlController = TextEditingController();
|
final _urlController = TextEditingController();
|
||||||
|
final _renameController = TextEditingController();
|
||||||
|
final _connectionsController = TextEditingController();
|
||||||
|
final _pathController = TextEditingController();
|
||||||
final _confirmController = RoundedLoadingButtonController();
|
final _confirmController = RoundedLoadingButtonController();
|
||||||
final _httpUaController = TextEditingController();
|
final _httpUaController = TextEditingController();
|
||||||
final _httpCookieController = TextEditingController();
|
final _httpCookieController = TextEditingController();
|
||||||
@@ -40,6 +43,17 @@ class CreateView extends GetView<CreateController> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final appController = Get.find<AppController>();
|
||||||
|
|
||||||
|
if (_connectionsController.text.isEmpty) {
|
||||||
|
_connectionsController.text = appController
|
||||||
|
.downloaderConfig.value.protocolConfig.http.connections
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
if (_pathController.text.isEmpty) {
|
||||||
|
_pathController.text = appController.downloaderConfig.value.downloadDir;
|
||||||
|
}
|
||||||
|
|
||||||
final String? filePath = Get.rootDelegate.arguments();
|
final String? filePath = Get.rootDelegate.arguments();
|
||||||
if (_urlController.text.isEmpty) {
|
if (_urlController.text.isEmpty) {
|
||||||
if (filePath?.isNotEmpty ?? false) {
|
if (filePath?.isNotEmpty ?? false) {
|
||||||
@@ -91,11 +105,12 @@ class CreateView extends GetView<CreateController> {
|
|||||||
onTap: () {
|
onTap: () {
|
||||||
FocusScope.of(context).requestFocus(FocusNode());
|
FocusScope.of(context).requestFocus(FocusNode());
|
||||||
},
|
},
|
||||||
|
child: SingleChildScrollView(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding:
|
padding:
|
||||||
const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0),
|
const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0),
|
||||||
child: Form(
|
child: Form(
|
||||||
key: _resolveFormKey,
|
key: _confirmFormKey,
|
||||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
@@ -170,12 +185,14 @@ class CreateView extends GetView<CreateController> {
|
|||||||
isHistoryListEmpty:
|
isHistoryListEmpty:
|
||||||
reverseResultOfHistories.isEmpty,
|
reverseResultOfHistories.isEmpty,
|
||||||
historyList: ListView.builder(
|
historyList: ListView.builder(
|
||||||
itemCount: reverseResultOfHistories.length,
|
itemCount:
|
||||||
|
reverseResultOfHistories.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_urlController.text =
|
_urlController.text =
|
||||||
reverseResultOfHistories[index];
|
reverseResultOfHistories[
|
||||||
|
index];
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
child: MouseRegion(
|
child: MouseRegion(
|
||||||
@@ -196,10 +213,12 @@ class CreateView extends GetView<CreateController> {
|
|||||||
.colorScheme
|
.colorScheme
|
||||||
.background,
|
.background,
|
||||||
borderRadius:
|
borderRadius:
|
||||||
BorderRadius.circular(10.0),
|
BorderRadius.circular(
|
||||||
|
10.0),
|
||||||
),
|
),
|
||||||
child: Text(
|
child: Text(
|
||||||
reverseResultOfHistories[index]
|
reverseResultOfHistories[
|
||||||
|
index]
|
||||||
.toString(),
|
.toString(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -223,14 +242,31 @@ class CreateView extends GetView<CreateController> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
]
|
]),
|
||||||
//.where((e) => e != null).map((e) => e!).toList(),
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 40),
|
||||||
|
child: Column(children: [
|
||||||
|
TextField(
|
||||||
|
controller: _renameController,
|
||||||
|
decoration: InputDecoration(labelText: 'rename'.tr),
|
||||||
|
),
|
||||||
|
TextField(
|
||||||
|
controller: _connectionsController,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: 'connections'.tr,
|
||||||
|
),
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
inputFormatters: [
|
||||||
|
FilteringTextInputFormatter.digitsOnly,
|
||||||
|
NumericalRangeFormatter(min: 1, max: 256),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
DirectorySelector(
|
||||||
|
controller: _pathController,
|
||||||
),
|
),
|
||||||
Obx(
|
Obx(
|
||||||
() => Visibility(
|
() => Visibility(
|
||||||
visible: controller.showAdvanced.value,
|
visible: controller.showAdvanced.value,
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.only(left: 40, top: 15),
|
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
TabBar(
|
TabBar(
|
||||||
@@ -280,25 +316,42 @@ class CreateView extends GetView<CreateController> {
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
).paddingOnly(top: 16),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
]),
|
||||||
),
|
),
|
||||||
Center(
|
Center(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.only(top: 15),
|
padding: const EdgeInsets.only(top: 15),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
Row(
|
||||||
padding: const EdgeInsets.only(right: 10),
|
mainAxisSize: MainAxisSize.min,
|
||||||
child: TextButton(
|
children: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
controller.directDownload.value =
|
||||||
|
!controller.directDownload.value;
|
||||||
|
},
|
||||||
|
child: Row(children: [
|
||||||
|
Obx(() => Checkbox(
|
||||||
|
value:
|
||||||
|
controller.directDownload.value,
|
||||||
|
onChanged: (bool? value) {
|
||||||
|
controller.directDownload.value =
|
||||||
|
value ?? false;
|
||||||
|
},
|
||||||
|
)),
|
||||||
|
Text('directDownload'.tr),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
controller.showAdvanced.value =
|
controller.showAdvanced.value =
|
||||||
!controller.showAdvanced.value;
|
!controller.showAdvanced.value;
|
||||||
},
|
},
|
||||||
child: Row(
|
child: Row(children: [
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
Obx(() => Checkbox(
|
Obx(() => Checkbox(
|
||||||
value: controller.showAdvanced.value,
|
value: controller.showAdvanced.value,
|
||||||
onChanged: (bool? value) {
|
onChanged: (bool? value) {
|
||||||
@@ -309,12 +362,13 @@ class CreateView extends GetView<CreateController> {
|
|||||||
Text('advancedOptions'.tr),
|
Text('advancedOptions'.tr),
|
||||||
]),
|
]),
|
||||||
),
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: 150,
|
width: 150,
|
||||||
child: RoundedLoadingButton(
|
child: RoundedLoadingButton(
|
||||||
color: Get.theme.colorScheme.secondary,
|
color: Get.theme.colorScheme.secondary,
|
||||||
onPressed: _doResolve,
|
onPressed: _doConfirm,
|
||||||
controller: _confirmController,
|
controller: _confirmController,
|
||||||
child: Text('confirm'.tr),
|
child: Text('confirm'.tr),
|
||||||
),
|
),
|
||||||
@@ -329,6 +383,7 @@ class CreateView extends GetView<CreateController> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -346,45 +401,54 @@ class CreateView extends GetView<CreateController> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _doResolve() async {
|
Future<void> _doConfirm() async {
|
||||||
if (controller.isResolving.value) {
|
if (controller.isConfirming.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
controller.isResolving.value = true;
|
controller.isConfirming.value = true;
|
||||||
try {
|
try {
|
||||||
_confirmController.start();
|
_confirmController.start();
|
||||||
if (_resolveFormKey.currentState!.validate()) {
|
if (_confirmFormKey.currentState!.validate()) {
|
||||||
// check if is multi line urls
|
|
||||||
final urls = Util.textToLines(_urlController.text);
|
|
||||||
ResolveResult rr;
|
|
||||||
bool isMultiLine = false;
|
|
||||||
if (urls.length > 1) {
|
|
||||||
isMultiLine = true;
|
|
||||||
rr = ResolveResult(
|
|
||||||
res: Resource(
|
|
||||||
files: urls
|
|
||||||
.map((u) => FileInfo(
|
|
||||||
name: u,
|
|
||||||
req: Request(url: u, extra: parseReqExtra(u))))
|
|
||||||
.toList()));
|
|
||||||
} else {
|
|
||||||
final submitUrl = Util.isWeb() && controller.fileDataUri.isNotEmpty
|
final submitUrl = Util.isWeb() && controller.fileDataUri.isNotEmpty
|
||||||
? controller.fileDataUri.value
|
? controller.fileDataUri.value
|
||||||
: _urlController.text;
|
: _urlController.text;
|
||||||
// add final submitUrl to the history
|
|
||||||
_historyController.addHistory(submitUrl);
|
final urls = Util.textToLines(submitUrl);
|
||||||
rr = await resolve(Request(
|
// Add url to the history
|
||||||
|
for (final url in urls) {
|
||||||
|
_historyController.addHistory(url);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
Check if is direct download, there has two ways to direct download
|
||||||
|
1. Direct download option is checked
|
||||||
|
2. Muli line urls
|
||||||
|
*/
|
||||||
|
final isMultiLine = urls.length > 1;
|
||||||
|
final isDirect = controller.directDownload.value || isMultiLine;
|
||||||
|
if (isDirect) {
|
||||||
|
await Future.wait(urls.map((url) {
|
||||||
|
return createTask(CreateTask(
|
||||||
|
req: Request(url: url, extra: parseReqExtra(url)),
|
||||||
|
opt: Options(
|
||||||
|
name: isMultiLine ? "" : _renameController.text,
|
||||||
|
path: _pathController.text,
|
||||||
|
selectFiles: [],
|
||||||
|
extra: parseReqOpts())));
|
||||||
|
}));
|
||||||
|
Get.rootDelegate.offNamed(Routes.TASK);
|
||||||
|
} else {
|
||||||
|
final rr = await resolve(Request(
|
||||||
url: submitUrl,
|
url: submitUrl,
|
||||||
extra: parseReqExtra(_urlController.text),
|
extra: parseReqExtra(_urlController.text),
|
||||||
));
|
));
|
||||||
|
await _showResolveDialog(rr);
|
||||||
}
|
}
|
||||||
await _showResolveDialog(rr, isMultiLine);
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
showErrorMessage(e);
|
showErrorMessage(e);
|
||||||
} finally {
|
} finally {
|
||||||
_confirmController.reset();
|
_confirmController.reset();
|
||||||
controller.isResolving.value = false;
|
controller.isConfirming.value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -407,6 +471,13 @@ class CreateView extends GetView<CreateController> {
|
|||||||
return reqExtra;
|
return reqExtra;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Object? parseReqOpts() {
|
||||||
|
return _connectionsController.text.isEmpty
|
||||||
|
? null
|
||||||
|
: (OptsExtraHttp()
|
||||||
|
..connections = int.parse(_connectionsController.text));
|
||||||
|
}
|
||||||
|
|
||||||
String _hitText() {
|
String _hitText() {
|
||||||
return 'downloadLinkHit'.trParams({
|
return 'downloadLinkHit'.trParams({
|
||||||
'append':
|
'append':
|
||||||
@@ -414,14 +485,8 @@ class CreateView extends GetView<CreateController> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _showResolveDialog(ResolveResult rr, bool isMuiltiLine) async {
|
Future<void> _showResolveDialog(ResolveResult rr) async {
|
||||||
final appController = Get.find<AppController>();
|
|
||||||
|
|
||||||
final createFormKey = GlobalKey<FormState>();
|
final createFormKey = GlobalKey<FormState>();
|
||||||
final nameController = TextEditingController();
|
|
||||||
final connectionsController = TextEditingController();
|
|
||||||
final pathController = TextEditingController(
|
|
||||||
text: appController.downloaderConfig.value.downloadDir);
|
|
||||||
final downloadController = RoundedLoadingButtonController();
|
final downloadController = RoundedLoadingButtonController();
|
||||||
return showDialog<void>(
|
return showDialog<void>(
|
||||||
context: Get.context!,
|
context: Get.context!,
|
||||||
@@ -440,31 +505,7 @@ class CreateView extends GetView<CreateController> {
|
|||||||
child: Form(
|
child: Form(
|
||||||
key: createFormKey,
|
key: createFormKey,
|
||||||
autovalidateMode: AutovalidateMode.always,
|
autovalidateMode: AutovalidateMode.always,
|
||||||
child: Column(
|
child: FileListView(files: rr.res.files)),
|
||||||
children: [
|
|
||||||
Expanded(child: FileListView(files: rr.res.files)),
|
|
||||||
TextFormField(
|
|
||||||
controller: nameController,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: 'rename'.tr,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
TextFormField(
|
|
||||||
controller: connectionsController,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: 'connections'.tr,
|
|
||||||
),
|
|
||||||
keyboardType: TextInputType.number,
|
|
||||||
inputFormatters: [
|
|
||||||
FilteringTextInputFormatter.digitsOnly,
|
|
||||||
NumericalRangeFormatter(min: 1, max: 256),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
DirectorySelector(
|
|
||||||
controller: pathController,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@@ -500,25 +541,19 @@ class CreateView extends GetView<CreateController> {
|
|||||||
showMessage('tip'.tr, 'noFileSelected'.tr);
|
showMessage('tip'.tr, 'noFileSelected'.tr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Object? optExtra = connectionsController.text.isEmpty
|
final optExtra = parseReqOpts();
|
||||||
? null
|
|
||||||
: (OptsExtraHttp()
|
|
||||||
..connections =
|
|
||||||
int.parse(connectionsController.text));
|
|
||||||
if (createFormKey.currentState!.validate()) {
|
if (createFormKey.currentState!.validate()) {
|
||||||
if (rr.id.isEmpty) {
|
if (rr.id.isEmpty) {
|
||||||
// create task batch, there has two ways to batch create task
|
// from extension resolve result
|
||||||
// 1. from multi line urls
|
|
||||||
// 2. from extension resolve result
|
|
||||||
await Future.wait(
|
await Future.wait(
|
||||||
controller.selectedIndexes.map((index) {
|
controller.selectedIndexes.map((index) {
|
||||||
final file = rr.res.files[index];
|
final file = rr.res.files[index];
|
||||||
return createTask(CreateTask(
|
return createTask(CreateTask(
|
||||||
req: file.req!,
|
req: file.req!,
|
||||||
opt: Options(
|
opt: Options(
|
||||||
name: isMuiltiLine ? "" : file.name,
|
name: file.name,
|
||||||
path: path.join(
|
path: path.join(
|
||||||
pathController.text, rr.res.name),
|
_pathController.text, rr.res.name),
|
||||||
selectFiles: [],
|
selectFiles: [],
|
||||||
extra: optExtra)));
|
extra: optExtra)));
|
||||||
}));
|
}));
|
||||||
@@ -526,8 +561,8 @@ class CreateView extends GetView<CreateController> {
|
|||||||
await createTask(CreateTask(
|
await createTask(CreateTask(
|
||||||
rid: rr.id,
|
rid: rr.id,
|
||||||
opt: Options(
|
opt: Options(
|
||||||
name: nameController.text,
|
name: _renameController.text,
|
||||||
path: pathController.text,
|
path: _pathController.text,
|
||||||
selectFiles: controller.selectedIndexes,
|
selectFiles: controller.selectedIndexes,
|
||||||
extra: optExtra)));
|
extra: optExtra)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ class LocaleKeys {
|
|||||||
static const donate = 'donate';
|
static const donate = 'donate';
|
||||||
static const exit = 'exit';
|
static const exit = 'exit';
|
||||||
static const create = 'create';
|
static const create = 'create';
|
||||||
|
static const directDownload = 'directDownload';
|
||||||
static const advancedOptions = 'advancedOptions';
|
static const advancedOptions = 'advancedOptions';
|
||||||
static const downloadLink = 'downloadLink';
|
static const downloadLink = 'downloadLink';
|
||||||
static const downloadLinkValid = 'downloadLinkValid';
|
static const downloadLinkValid = 'downloadLinkValid';
|
||||||
@@ -106,6 +107,7 @@ class Locales {
|
|||||||
'donate': 'Donate',
|
'donate': 'Donate',
|
||||||
'exit': 'Exit',
|
'exit': 'Exit',
|
||||||
'create': 'Create Task',
|
'create': 'Create Task',
|
||||||
|
'directDownload': 'Direct Download',
|
||||||
'advancedOptions': 'Advanced Options',
|
'advancedOptions': 'Advanced Options',
|
||||||
'downloadLink': 'Download Link',
|
'downloadLink': 'Download Link',
|
||||||
'downloadLinkValid': 'Please enter the download link',
|
'downloadLinkValid': 'Please enter the download link',
|
||||||
@@ -379,6 +381,7 @@ class Locales {
|
|||||||
'donate': '打赏',
|
'donate': '打赏',
|
||||||
'exit': '退出',
|
'exit': '退出',
|
||||||
'create': '创建任务',
|
'create': '创建任务',
|
||||||
|
'directDownload': '直接下载',
|
||||||
'advancedOptions': '高级选项',
|
'advancedOptions': '高级选项',
|
||||||
'downloadLink': '下载链接',
|
'downloadLink': '下载链接',
|
||||||
'downloadLinkValid': '请输入下载链接',
|
'downloadLinkValid': '请输入下载链接',
|
||||||
|
|||||||
Reference in new issue
Block a user