mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-08 17:40:28 +00:00
feat: torrent seed config (#599)
This commit is contained in:
22 files changed
+456
-144
No files matched your search
@@ -41,9 +41,8 @@ class HttpConfig {
|
||||
bool useServerCtime;
|
||||
|
||||
HttpConfig({
|
||||
this.userAgent =
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36',
|
||||
this.connections = 16,
|
||||
this.userAgent = '',
|
||||
this.connections = 0,
|
||||
this.useServerCtime = false,
|
||||
});
|
||||
|
||||
@@ -55,10 +54,19 @@ class HttpConfig {
|
||||
|
||||
@JsonSerializable()
|
||||
class BtConfig {
|
||||
int listenPort = 0;
|
||||
List<String> trackers = [];
|
||||
int listenPort;
|
||||
List<String> trackers;
|
||||
bool seedKeep;
|
||||
double seedRatio;
|
||||
int seedTime;
|
||||
|
||||
BtConfig();
|
||||
BtConfig({
|
||||
this.listenPort = 0,
|
||||
this.trackers = const [],
|
||||
this.seedKeep = false,
|
||||
this.seedRatio = 0,
|
||||
this.seedTime = 0,
|
||||
});
|
||||
|
||||
factory BtConfig.fromJson(Map<String, dynamic> json) =>
|
||||
_$BtConfigFromJson(json);
|
||||
|
||||
@@ -37,9 +37,8 @@ Map<String, dynamic> _$ProtocolConfigToJson(ProtocolConfig instance) =>
|
||||
};
|
||||
|
||||
HttpConfig _$HttpConfigFromJson(Map<String, dynamic> json) => HttpConfig(
|
||||
userAgent: json['userAgent'] as String? ??
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36',
|
||||
connections: json['connections'] as int? ?? 16,
|
||||
userAgent: json['userAgent'] as String? ?? '',
|
||||
connections: json['connections'] as int? ?? 0,
|
||||
useServerCtime: json['useServerCtime'] as bool? ?? false,
|
||||
);
|
||||
|
||||
@@ -50,14 +49,23 @@ Map<String, dynamic> _$HttpConfigToJson(HttpConfig instance) =>
|
||||
'useServerCtime': instance.useServerCtime,
|
||||
};
|
||||
|
||||
BtConfig _$BtConfigFromJson(Map<String, dynamic> json) => BtConfig()
|
||||
..listenPort = json['listenPort'] as int
|
||||
..trackers =
|
||||
(json['trackers'] as List<dynamic>).map((e) => e as String).toList();
|
||||
BtConfig _$BtConfigFromJson(Map<String, dynamic> json) => BtConfig(
|
||||
listenPort: json['listenPort'] as int? ?? 0,
|
||||
trackers: (json['trackers'] as List<dynamic>?)
|
||||
?.map((e) => e as String)
|
||||
.toList() ??
|
||||
const [],
|
||||
seedKeep: json['seedKeep'] as bool? ?? false,
|
||||
seedRatio: (json['seedRatio'] as num?)?.toDouble() ?? 0,
|
||||
seedTime: json['seedTime'] as int? ?? 0,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$BtConfigToJson(BtConfig instance) => <String, dynamic>{
|
||||
'listenPort': instance.listenPort,
|
||||
'trackers': instance.trackers,
|
||||
'seedKeep': instance.seedKeep,
|
||||
'seedRatio': instance.seedRatio,
|
||||
'seedTime': instance.seedTime,
|
||||
};
|
||||
|
||||
ExtraConfig _$ExtraConfigFromJson(Map<String, dynamic> json) => ExtraConfig(
|
||||
|
||||
@@ -6,11 +6,15 @@ part 'task.g.dart';
|
||||
|
||||
enum Status { ready, running, pause, wait, error, done }
|
||||
|
||||
enum Protocol { http, bt }
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class Task {
|
||||
String id;
|
||||
Protocol? protocol;
|
||||
Meta meta;
|
||||
Status status;
|
||||
bool uploading;
|
||||
Progress progress;
|
||||
DateTime createdAt;
|
||||
DateTime updatedAt;
|
||||
@@ -19,6 +23,7 @@ class Task {
|
||||
required this.id,
|
||||
required this.meta,
|
||||
required this.status,
|
||||
required this.uploading,
|
||||
required this.progress,
|
||||
required this.createdAt,
|
||||
required this.updatedAt,
|
||||
@@ -34,11 +39,15 @@ class Progress {
|
||||
int used;
|
||||
int speed;
|
||||
int downloaded;
|
||||
int uploadSpeed;
|
||||
int uploaded;
|
||||
|
||||
Progress({
|
||||
required this.used,
|
||||
required this.speed,
|
||||
required this.downloaded,
|
||||
required this.uploadSpeed,
|
||||
required this.uploaded,
|
||||
});
|
||||
|
||||
factory Progress.fromJson(Map<String, dynamic> json) =>
|
||||
|
||||
@@ -10,19 +10,32 @@ Task _$TaskFromJson(Map<String, dynamic> json) => Task(
|
||||
id: json['id'] as String,
|
||||
meta: Meta.fromJson(json['meta'] as Map<String, dynamic>),
|
||||
status: $enumDecode(_$StatusEnumMap, json['status']),
|
||||
uploading: json['uploading'] as bool,
|
||||
progress: Progress.fromJson(json['progress'] as Map<String, dynamic>),
|
||||
createdAt: DateTime.parse(json['createdAt'] as String),
|
||||
updatedAt: DateTime.parse(json['updatedAt'] as String),
|
||||
);
|
||||
)..protocol = $enumDecodeNullable(_$ProtocolEnumMap, json['protocol']);
|
||||
|
||||
Map<String, dynamic> _$TaskToJson(Task instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'meta': instance.meta.toJson(),
|
||||
'status': _$StatusEnumMap[instance.status]!,
|
||||
'progress': instance.progress.toJson(),
|
||||
'createdAt': instance.createdAt.toIso8601String(),
|
||||
'updatedAt': instance.updatedAt.toIso8601String(),
|
||||
};
|
||||
Map<String, dynamic> _$TaskToJson(Task instance) {
|
||||
final val = <String, dynamic>{
|
||||
'id': instance.id,
|
||||
};
|
||||
|
||||
void writeNotNull(String key, dynamic value) {
|
||||
if (value != null) {
|
||||
val[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
writeNotNull('protocol', _$ProtocolEnumMap[instance.protocol]);
|
||||
val['meta'] = instance.meta.toJson();
|
||||
val['status'] = _$StatusEnumMap[instance.status]!;
|
||||
val['uploading'] = instance.uploading;
|
||||
val['progress'] = instance.progress.toJson();
|
||||
val['createdAt'] = instance.createdAt.toIso8601String();
|
||||
val['updatedAt'] = instance.updatedAt.toIso8601String();
|
||||
return val;
|
||||
}
|
||||
|
||||
const _$StatusEnumMap = {
|
||||
Status.ready: 'ready',
|
||||
@@ -33,14 +46,23 @@ const _$StatusEnumMap = {
|
||||
Status.done: 'done',
|
||||
};
|
||||
|
||||
const _$ProtocolEnumMap = {
|
||||
Protocol.http: 'http',
|
||||
Protocol.bt: 'bt',
|
||||
};
|
||||
|
||||
Progress _$ProgressFromJson(Map<String, dynamic> json) => Progress(
|
||||
used: json['used'] as int,
|
||||
speed: json['speed'] as int,
|
||||
downloaded: json['downloaded'] as int,
|
||||
uploadSpeed: json['uploadSpeed'] as int,
|
||||
uploaded: json['uploaded'] as int,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ProgressToJson(Progress instance) => <String, dynamic>{
|
||||
'used': instance.used,
|
||||
'speed': instance.speed,
|
||||
'downloaded': instance.downloaded,
|
||||
'uploadSpeed': instance.uploadSpeed,
|
||||
'uploaded': instance.uploaded,
|
||||
};
|
||||
@@ -334,6 +334,69 @@ class SettingView extends GetView<SettingController> {
|
||||
},
|
||||
);
|
||||
});
|
||||
final buildBtSeedConfig = _buildConfigItem('seedConfig',
|
||||
() => 'seedKeep'.tr + (btConfig.seedKeep ? 'on'.tr : 'off'.tr),
|
||||
(Key key) {
|
||||
final seedRatioController =
|
||||
TextEditingController(text: btConfig.seedRatio.toString());
|
||||
seedRatioController.addListener(() {
|
||||
if (seedRatioController.text.isNotEmpty) {
|
||||
btConfig.seedRatio = double.parse(seedRatioController.text);
|
||||
debounceSave();
|
||||
}
|
||||
});
|
||||
final seedTimeController =
|
||||
TextEditingController(text: (btConfig.seedTime ~/ 60).toString());
|
||||
seedTimeController.addListener(() {
|
||||
if (seedTimeController.text.isNotEmpty) {
|
||||
btConfig.seedTime = int.parse(seedTimeController.text) * 60;
|
||||
debounceSave();
|
||||
}
|
||||
});
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SwitchListTile(
|
||||
controlAffinity: ListTileControlAffinity.leading,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
value: btConfig.seedKeep,
|
||||
onChanged: (bool value) {
|
||||
downloaderCfg.update((val) {
|
||||
val!.protocolConfig.bt.seedKeep = value;
|
||||
});
|
||||
debounceSave();
|
||||
},
|
||||
title: Text('seedKeep'.tr)),
|
||||
btConfig.seedKeep
|
||||
? null
|
||||
: TextField(
|
||||
controller: seedRatioController,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'seedRatio'.tr,
|
||||
),
|
||||
keyboardType:
|
||||
const TextInputType.numberWithOptions(decimal: true),
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.allow(
|
||||
RegExp(r'^\d+\.?\d{0,2}')),
|
||||
],
|
||||
),
|
||||
btConfig.seedKeep
|
||||
? null
|
||||
: TextField(
|
||||
controller: seedTimeController,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'seedTime'.tr,
|
||||
),
|
||||
keyboardType: TextInputType.number,
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.digitsOnly,
|
||||
NumericalRangeFormatter(min: 0, max: 100000000),
|
||||
],
|
||||
),
|
||||
].where((e) => e != null).map((e) => e!).toList(),
|
||||
);
|
||||
});
|
||||
|
||||
// ui config items start
|
||||
final buildTheme = _buildConfigItem(
|
||||
@@ -833,6 +896,7 @@ class SettingView extends GetView<SettingController> {
|
||||
buildBtListenPort(),
|
||||
buildBtTrackerSubscribeUrls(),
|
||||
buildBtTrackers(),
|
||||
buildBtSeedConfig(),
|
||||
]),
|
||||
)),
|
||||
Text('ui'.tr),
|
||||
|
||||
@@ -95,5 +95,9 @@ const enUS = {
|
||||
'Thanks to all the contributors who have helped build and develop the Gopeed community!',
|
||||
'browserExtension': 'Browser Extension',
|
||||
'launchAtStartup': 'Launch at Startup',
|
||||
'seedConfig': 'Seed Config',
|
||||
'seedKeep': 'Keep seeding',
|
||||
'seedRatio': 'Seed ratio',
|
||||
'seedTime': 'Seed time (minutes)',
|
||||
},
|
||||
};
|
||||
@@ -92,5 +92,9 @@ const zhCN = {
|
||||
'thanksDesc': '感谢所有为 Gopeed 社区建设添砖加瓦的贡献者们!',
|
||||
'browserExtension': '浏览器扩展',
|
||||
'launchAtStartup': '开机自动运行',
|
||||
'seedConfig': '做种设置',
|
||||
'seedKeep': '持续做种',
|
||||
'seedRatio': '做种分享率',
|
||||
'seedTime': '做种时间(分钟)',
|
||||
}
|
||||
};
|
||||
@@ -19,8 +19,7 @@ const zhTW = {
|
||||
'advancedOptions': '進階選項',
|
||||
'downloadLink': '下載連結',
|
||||
'downloadLinkValid': '請輸入下載連結',
|
||||
'downloadLinkHit':
|
||||
'請輸入下載連結,支援 HTTP/HTTPS/MAGNET@append',
|
||||
'downloadLinkHit': '請輸入下載連結,支援 HTTP/HTTPS/MAGNET@append',
|
||||
'downloadLinkHitDesktop': ',或直接拖曳種子檔到此處',
|
||||
'download': '下載',
|
||||
'noFileSelected': '請至少選擇一個檔案以繼續。',
|
||||
@@ -93,5 +92,9 @@ const zhTW = {
|
||||
'thanksDesc': '感謝所有幫助建立和發展 Gopeed 社群的貢獻者!',
|
||||
'browserExtension': '瀏覽器擴充功能',
|
||||
'launchAtStartup': '開機自動執行',
|
||||
'seedConfig': '做種設定',
|
||||
'seedKeep': '持續做種',
|
||||
'seedRatio': '做種分享率',
|
||||
'seedTime': '做種時間(分鐘)',
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user