mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-05 16:15:43 +00:00
fix: http download fail (#61)
This commit is contained in:
1 parent
c62867e3ef
commit
0a4be165a5
14 files changed
+113
-54
No files matched your search
@@ -1,5 +1,5 @@
|
||||
name-template: 'v1.2.0 🌈'
|
||||
tag-template: 'v1.2.0'
|
||||
name-template: 'v$NEXT_PATCH_VERSION 🌈'
|
||||
tag-template: 'v$NEXT_PATCH_VERSION'
|
||||
categories:
|
||||
- title: '🆕 Features'
|
||||
labels:
|
||||
|
||||
@@ -151,7 +151,7 @@ func (f *Fetcher) Create(res *base.Resource, opts *base.Options) error {
|
||||
return err
|
||||
}
|
||||
if opts.Extra == nil {
|
||||
opts.Extra = &fhttp.ReqExtra{}
|
||||
opts.Extra = &fhttp.OptsExtra{}
|
||||
}
|
||||
extra := opts.Extra.(*fhttp.OptsExtra)
|
||||
if extra.Connections == 0 {
|
||||
|
||||
@@ -142,12 +142,16 @@ func doDownloadReady(f fetcher.Fetcher, listener net.Listener, connections int,
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
opts = &base.Options{
|
||||
Name: test.DownloadName,
|
||||
Path: test.Dir,
|
||||
Extra: http.OptsExtra{
|
||||
var extra any = nil
|
||||
if connections > 0 {
|
||||
extra = http.OptsExtra{
|
||||
Connections: connections,
|
||||
},
|
||||
}
|
||||
}
|
||||
opts = &base.Options{
|
||||
Name: test.DownloadName,
|
||||
Path: test.Dir,
|
||||
Extra: extra,
|
||||
}
|
||||
err = fetcher.Create(res, opts)
|
||||
if err != nil {
|
||||
|
||||
@@ -102,7 +102,14 @@ func (d *Downloader) Setup() error {
|
||||
|
||||
current := task.fetcher.Progress().TotalDownloaded()
|
||||
task.Progress.Used = task.timer.Used()
|
||||
task.Progress.Speed = current - task.Progress.Downloaded
|
||||
downloaded := current - task.Progress.Downloaded
|
||||
usedTime := float64(d.refreshInterval) / 1000
|
||||
if downloaded == 0 {
|
||||
task.Progress.Speed = int64(float64(task.Progress.Speed) / (usedTime * 1.55))
|
||||
} else {
|
||||
usedTime := float64(d.refreshInterval) / 1000
|
||||
task.Progress.Speed = int64(float64(current-task.Progress.Downloaded) / usedTime)
|
||||
}
|
||||
task.Progress.Downloaded = current
|
||||
d.emit(EventKeyProgress, task)
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ func (cfg *DownloaderConfig) Init() *DownloaderConfig {
|
||||
}
|
||||
|
||||
if cfg.RefreshInterval == 0 {
|
||||
cfg.RefreshInterval = 1000
|
||||
cfg.RefreshInterval = 500
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ android {
|
||||
// You can update the following values to match your application needs.
|
||||
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
|
||||
minSdkVersion 19
|
||||
targetSdkVersion flutter.targetSdkVersion
|
||||
targetSdkVersion 29
|
||||
versionCode flutterVersionCode.toInteger()
|
||||
versionName flutterVersionName
|
||||
}
|
||||
|
||||
@@ -15,7 +15,9 @@ class CreateTask {
|
||||
this.opts,
|
||||
});
|
||||
|
||||
factory CreateTask.fromJson(Map<String, dynamic> json) =>
|
||||
factory CreateTask.fromJson(
|
||||
Map<String, dynamic> json,
|
||||
) =>
|
||||
_$CreateTaskFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$CreateTaskToJson(this);
|
||||
|
||||
@@ -64,12 +64,12 @@ ExtraConfigBt _$ExtraConfigBtFromJson(Map<String, dynamic> json) =>
|
||||
..trackerSubscribeUrls = (json['trackerSubscribeUrls'] as List<dynamic>)
|
||||
.map((e) => e as String)
|
||||
.toList()
|
||||
..lastTrackerUpdateTime = json['lastTrackerUpdateTime'] == null
|
||||
? null
|
||||
: DateTime.parse(json['lastTrackerUpdateTime'] as String)
|
||||
..subscribeTrackers = (json['subscribeTrackers'] as List<dynamic>)
|
||||
.map((e) => e as String)
|
||||
.toList()
|
||||
..lastTrackerUpdateTime = json['lastTrackerUpdateTime'] == null
|
||||
? null
|
||||
: DateTime.parse(json['lastTrackerUpdateTime'] as String)
|
||||
..customTrackers = (json['customTrackers'] as List<dynamic>)
|
||||
.map((e) => e as String)
|
||||
.toList();
|
||||
@@ -77,6 +77,7 @@ ExtraConfigBt _$ExtraConfigBtFromJson(Map<String, dynamic> json) =>
|
||||
Map<String, dynamic> _$ExtraConfigBtToJson(ExtraConfigBt instance) {
|
||||
final val = <String, dynamic>{
|
||||
'trackerSubscribeUrls': instance.trackerSubscribeUrls,
|
||||
'subscribeTrackers': instance.subscribeTrackers,
|
||||
};
|
||||
|
||||
void writeNotNull(String key, dynamic value) {
|
||||
@@ -87,7 +88,6 @@ Map<String, dynamic> _$ExtraConfigBtToJson(ExtraConfigBt instance) {
|
||||
|
||||
writeNotNull('lastTrackerUpdateTime',
|
||||
instance.lastTrackerUpdateTime?.toIso8601String());
|
||||
val['subscribeTrackers'] = instance.subscribeTrackers;
|
||||
val['customTrackers'] = instance.customTrackers;
|
||||
return val;
|
||||
}
|
||||
@@ -2,11 +2,12 @@ import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'options.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
@JsonSerializable(explicitToJson: true, genericArgumentFactories: true)
|
||||
class Options {
|
||||
String name;
|
||||
String path;
|
||||
List<int> selectFiles;
|
||||
Map<String, dynamic>? extra;
|
||||
|
||||
Options({
|
||||
required this.name,
|
||||
@@ -19,3 +20,14 @@ class Options {
|
||||
|
||||
Map<String, dynamic> toJson() => _$OptionsToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class OptsExtraHttp {
|
||||
int connections = 0;
|
||||
|
||||
OptsExtraHttp();
|
||||
|
||||
factory OptsExtraHttp.fromJson(Map<String, dynamic> json) =>
|
||||
_$OptsExtraHttpFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$OptsExtraHttpToJson(this);
|
||||
}
|
||||
@@ -11,10 +11,29 @@ Options _$OptionsFromJson(Map<String, dynamic> json) => Options(
|
||||
path: json['path'] as String,
|
||||
selectFiles:
|
||||
(json['selectFiles'] as List<dynamic>).map((e) => e as int).toList(),
|
||||
);
|
||||
)..extra = json['extra'] as Map<String, dynamic>?;
|
||||
|
||||
Map<String, dynamic> _$OptionsToJson(Options instance) => <String, dynamic>{
|
||||
'name': instance.name,
|
||||
'path': instance.path,
|
||||
'selectFiles': instance.selectFiles,
|
||||
Map<String, dynamic> _$OptionsToJson(Options instance) {
|
||||
final val = <String, dynamic>{
|
||||
'name': instance.name,
|
||||
'path': instance.path,
|
||||
'selectFiles': instance.selectFiles,
|
||||
};
|
||||
|
||||
void writeNotNull(String key, dynamic value) {
|
||||
if (value != null) {
|
||||
val[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
writeNotNull('extra', instance.extra);
|
||||
return val;
|
||||
}
|
||||
|
||||
OptsExtraHttp _$OptsExtraHttpFromJson(Map<String, dynamic> json) =>
|
||||
OptsExtraHttp()..connections = json['connections'] as int;
|
||||
|
||||
Map<String, dynamic> _$OptsExtraHttpToJson(OptsExtraHttp instance) =>
|
||||
<String, dynamic>{
|
||||
'connections': instance.connections,
|
||||
};
|
||||
@@ -2,17 +2,31 @@ import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'request.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
@JsonSerializable(explicitToJson: true, genericArgumentFactories: true)
|
||||
class Request {
|
||||
String url;
|
||||
Map<String, dynamic>? extra;
|
||||
|
||||
Request({
|
||||
required this.url,
|
||||
this.extra,
|
||||
});
|
||||
|
||||
factory Request.fromJson(Map<String, dynamic> json) =>
|
||||
_$RequestFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$RequestToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class ReqExtraHttp {
|
||||
String method = 'GET';
|
||||
Map<String, String> headers = {};
|
||||
String body = '';
|
||||
|
||||
ReqExtraHttp();
|
||||
|
||||
factory ReqExtraHttp.fromJson(Map<String, dynamic> json) =>
|
||||
_$ReqExtraHttpFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$ReqExtraHttpToJson(this);
|
||||
}
|
||||
@@ -8,8 +8,7 @@ part of 'request.dart';
|
||||
|
||||
Request _$RequestFromJson(Map<String, dynamic> json) => Request(
|
||||
url: json['url'] as String,
|
||||
extra: json['extra'] as Map<String, dynamic>?,
|
||||
);
|
||||
)..extra = json['extra'] as Map<String, dynamic>?;
|
||||
|
||||
Map<String, dynamic> _$RequestToJson(Request instance) {
|
||||
final val = <String, dynamic>{
|
||||
@@ -25,3 +24,15 @@ Map<String, dynamic> _$RequestToJson(Request instance) {
|
||||
writeNotNull('extra', instance.extra);
|
||||
return val;
|
||||
}
|
||||
|
||||
ReqExtraHttp _$ReqExtraHttpFromJson(Map<String, dynamic> json) => ReqExtraHttp()
|
||||
..method = json['method'] as String
|
||||
..headers = Map<String, String>.from(json['headers'] as Map)
|
||||
..body = json['body'] as String;
|
||||
|
||||
Map<String, dynamic> _$ReqExtraHttpToJson(ReqExtraHttp instance) =>
|
||||
<String, dynamic>{
|
||||
'method': instance.method,
|
||||
'headers': instance.headers,
|
||||
'body': instance.body,
|
||||
};
|
||||
@@ -11,19 +11,19 @@ class Resource {
|
||||
int size;
|
||||
bool range;
|
||||
List<FileInfo> files;
|
||||
Map<String, dynamic>? extra;
|
||||
String hash;
|
||||
|
||||
Resource({
|
||||
required this.req,
|
||||
required this.name,
|
||||
required this.size,
|
||||
required this.range,
|
||||
required this.files,
|
||||
this.extra,
|
||||
});
|
||||
Resource(
|
||||
{required this.req,
|
||||
required this.name,
|
||||
required this.size,
|
||||
required this.range,
|
||||
required this.files,
|
||||
required this.hash});
|
||||
|
||||
factory Resource.fromJson(Map<String, dynamic> json) =>
|
||||
_$ResourceFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$ResourceToJson(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,27 +14,17 @@ Resource _$ResourceFromJson(Map<String, dynamic> json) => Resource(
|
||||
files: (json['files'] as List<dynamic>)
|
||||
.map((e) => FileInfo.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
extra: json['extra'] as Map<String, dynamic>?,
|
||||
hash: json['hash'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ResourceToJson(Resource instance) {
|
||||
final val = <String, dynamic>{
|
||||
'req': instance.req.toJson(),
|
||||
'name': instance.name,
|
||||
'size': instance.size,
|
||||
'range': instance.range,
|
||||
'files': instance.files.map((e) => e.toJson()).toList(),
|
||||
};
|
||||
|
||||
void writeNotNull(String key, dynamic value) {
|
||||
if (value != null) {
|
||||
val[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
writeNotNull('extra', instance.extra);
|
||||
return val;
|
||||
}
|
||||
Map<String, dynamic> _$ResourceToJson(Resource instance) => <String, dynamic>{
|
||||
'req': instance.req.toJson(),
|
||||
'name': instance.name,
|
||||
'size': instance.size,
|
||||
'range': instance.range,
|
||||
'files': instance.files.map((e) => e.toJson()).toList(),
|
||||
'hash': instance.hash,
|
||||
};
|
||||
|
||||
FileInfo _$FileInfoFromJson(Map<String, dynamic> json) => FileInfo(
|
||||
name: json['name'] as String,
|
||||
|
||||
Reference in new issue
Block a user