mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-08 17:40:28 +00:00
feat: support max running tasks config (#112)
This commit is contained in:
1 parent
1e08ecd8db
commit
d9c5ca339f
22 files changed
+269
-129
No files matched your search
@@ -73,15 +73,12 @@ Future<T> _parse<T>(
|
||||
) async {
|
||||
try {
|
||||
var resp = await fetch();
|
||||
if (fromJsonT != null) {
|
||||
final result = Result<T>.fromJson(resp.data, fromJsonT);
|
||||
if (result.code == 0) {
|
||||
return result.data as T;
|
||||
} else {
|
||||
throw Exception(result);
|
||||
}
|
||||
fromJsonT ??= (json) => null as T;
|
||||
final result = Result<T>.fromJson(resp.data, fromJsonT);
|
||||
if (result.code == 0) {
|
||||
return result.data as T;
|
||||
} else {
|
||||
return null as T;
|
||||
throw Exception(result);
|
||||
}
|
||||
} on DioError catch (e) {
|
||||
throw Exception(Result(code: 1000, msg: e.message));
|
||||
|
||||
@@ -5,6 +5,7 @@ part 'downloader_config.g.dart';
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class DownloaderConfig {
|
||||
String downloadDir = '';
|
||||
int maxRunning = 0;
|
||||
ProtocolConfig protocolConfig = ProtocolConfig();
|
||||
ExtraConfig extra = ExtraConfig();
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ part of 'downloader_config.dart';
|
||||
DownloaderConfig _$DownloaderConfigFromJson(Map<String, dynamic> json) =>
|
||||
DownloaderConfig()
|
||||
..downloadDir = json['downloadDir'] as String
|
||||
..maxRunning = json['maxRunning'] as int
|
||||
..protocolConfig = ProtocolConfig.fromJson(
|
||||
json['protocolConfig'] as Map<String, dynamic>?)
|
||||
..extra = ExtraConfig.fromJson(json['extra'] as Map<String, dynamic>?);
|
||||
@@ -16,6 +17,7 @@ DownloaderConfig _$DownloaderConfigFromJson(Map<String, dynamic> json) =>
|
||||
Map<String, dynamic> _$DownloaderConfigToJson(DownloaderConfig instance) =>
|
||||
<String, dynamic>{
|
||||
'downloadDir': instance.downloadDir,
|
||||
'maxRunning': instance.maxRunning,
|
||||
'protocolConfig': instance.protocolConfig.toJson(),
|
||||
'extra': instance.extra.toJson(),
|
||||
};
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'meta.dart';
|
||||
import 'options.dart';
|
||||
import 'resource.dart';
|
||||
|
||||
part 'task.g.dart';
|
||||
|
||||
enum Status { ready, running, pause, error, done }
|
||||
enum Status { ready, running, pause, wait, error, done }
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class Task {
|
||||
|
||||
@@ -28,6 +28,7 @@ const _$StatusEnumMap = {
|
||||
Status.ready: 'ready',
|
||||
Status.running: 'running',
|
||||
Status.pause: 'pause',
|
||||
Status.wait: 'wait',
|
||||
Status.error: 'error',
|
||||
Status.done: 'done',
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user