mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-15 12:53:41 +00:00
feat: support use server time for file creation (#359)
This commit is contained in:
20 files changed
+192
-75
No files matched your search
@@ -4,13 +4,16 @@ part 'downloader_config.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class DownloaderConfig {
|
||||
String downloadDir = '';
|
||||
int maxRunning = 0;
|
||||
String downloadDir;
|
||||
int maxRunning;
|
||||
ProtocolConfig protocolConfig = ProtocolConfig();
|
||||
ExtraConfig extra = ExtraConfig();
|
||||
ProxyConfig proxy = ProxyConfig();
|
||||
|
||||
DownloaderConfig();
|
||||
DownloaderConfig({
|
||||
this.downloadDir = '',
|
||||
this.maxRunning = 0,
|
||||
});
|
||||
|
||||
factory DownloaderConfig.fromJson(Map<String, dynamic> json) =>
|
||||
_$DownloaderConfigFromJson(json);
|
||||
@@ -31,11 +34,16 @@ class ProtocolConfig {
|
||||
|
||||
@JsonSerializable()
|
||||
class HttpConfig {
|
||||
String userAgent =
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36';
|
||||
int connections = 0;
|
||||
String userAgent;
|
||||
int connections;
|
||||
bool useServerCtime;
|
||||
|
||||
HttpConfig();
|
||||
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.useServerCtime = false,
|
||||
});
|
||||
|
||||
factory HttpConfig.fromJson(Map<String, dynamic> json) =>
|
||||
_$HttpConfigFromJson(json);
|
||||
@@ -69,13 +77,19 @@ class ExtraConfig {
|
||||
|
||||
@JsonSerializable()
|
||||
class ProxyConfig {
|
||||
bool enable = false;
|
||||
String scheme = '';
|
||||
String host = '';
|
||||
String usr = '';
|
||||
String pwd = '';
|
||||
bool enable;
|
||||
String scheme;
|
||||
String host;
|
||||
String usr;
|
||||
String pwd;
|
||||
|
||||
ProxyConfig();
|
||||
ProxyConfig({
|
||||
this.enable = false,
|
||||
this.scheme = '',
|
||||
this.host = '',
|
||||
this.usr = '',
|
||||
this.pwd = '',
|
||||
});
|
||||
|
||||
factory ProxyConfig.fromJson(Map<String, dynamic> json) =>
|
||||
_$ProxyConfigFromJson(json);
|
||||
@@ -85,13 +99,20 @@ class ProxyConfig {
|
||||
|
||||
@JsonSerializable()
|
||||
class ExtraConfigBt {
|
||||
List<String> trackerSubscribeUrls = [];
|
||||
List<String> subscribeTrackers = [];
|
||||
List<String> trackerSubscribeUrls;
|
||||
List<String> subscribeTrackers;
|
||||
bool autoUpdateTrackers;
|
||||
DateTime? lastTrackerUpdateTime;
|
||||
|
||||
List<String> customTrackers = [];
|
||||
List<String> customTrackers;
|
||||
|
||||
ExtraConfigBt();
|
||||
ExtraConfigBt({
|
||||
this.trackerSubscribeUrls = const [],
|
||||
this.subscribeTrackers = const [],
|
||||
this.autoUpdateTrackers = true,
|
||||
this.lastTrackerUpdateTime,
|
||||
this.customTrackers = const [],
|
||||
});
|
||||
|
||||
factory ExtraConfigBt.fromJson(Map<String, dynamic> json) =>
|
||||
_$ExtraConfigBtFromJson(json);
|
||||
|
||||
@@ -7,9 +7,10 @@ part of 'downloader_config.dart';
|
||||
// **************************************************************************
|
||||
|
||||
DownloaderConfig _$DownloaderConfigFromJson(Map<String, dynamic> json) =>
|
||||
DownloaderConfig()
|
||||
..downloadDir = json['downloadDir'] as String
|
||||
..maxRunning = json['maxRunning'] as int
|
||||
DownloaderConfig(
|
||||
downloadDir: json['downloadDir'] as String? ?? '',
|
||||
maxRunning: json['maxRunning'] as int? ?? 0,
|
||||
)
|
||||
..protocolConfig = ProtocolConfig.fromJson(
|
||||
json['protocolConfig'] as Map<String, dynamic>?)
|
||||
..extra = ExtraConfig.fromJson(json['extra'] as Map<String, dynamic>?)
|
||||
@@ -35,14 +36,18 @@ Map<String, dynamic> _$ProtocolConfigToJson(ProtocolConfig instance) =>
|
||||
'bt': instance.bt.toJson(),
|
||||
};
|
||||
|
||||
HttpConfig _$HttpConfigFromJson(Map<String, dynamic> json) => HttpConfig()
|
||||
..userAgent = json['userAgent'] as String
|
||||
..connections = json['connections'] as int;
|
||||
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,
|
||||
useServerCtime: json['useServerCtime'] as bool? ?? false,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$HttpConfigToJson(HttpConfig instance) =>
|
||||
<String, dynamic>{
|
||||
'userAgent': instance.userAgent,
|
||||
'connections': instance.connections,
|
||||
'useServerCtime': instance.useServerCtime,
|
||||
};
|
||||
|
||||
BtConfig _$BtConfigFromJson(Map<String, dynamic> json) => BtConfig()
|
||||
@@ -67,12 +72,13 @@ Map<String, dynamic> _$ExtraConfigToJson(ExtraConfig instance) =>
|
||||
'bt': instance.bt.toJson(),
|
||||
};
|
||||
|
||||
ProxyConfig _$ProxyConfigFromJson(Map<String, dynamic> json) => ProxyConfig()
|
||||
..enable = json['enable'] as bool
|
||||
..scheme = json['scheme'] as String
|
||||
..host = json['host'] as String
|
||||
..usr = json['usr'] as String
|
||||
..pwd = json['pwd'] as String;
|
||||
ProxyConfig _$ProxyConfigFromJson(Map<String, dynamic> json) => ProxyConfig(
|
||||
enable: json['enable'] as bool? ?? false,
|
||||
scheme: json['scheme'] as String? ?? '',
|
||||
host: json['host'] as String? ?? '',
|
||||
usr: json['usr'] as String? ?? '',
|
||||
pwd: json['pwd'] as String? ?? '',
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ProxyConfigToJson(ProxyConfig instance) =>
|
||||
<String, dynamic>{
|
||||
@@ -84,24 +90,30 @@ Map<String, dynamic> _$ProxyConfigToJson(ProxyConfig instance) =>
|
||||
};
|
||||
|
||||
ExtraConfigBt _$ExtraConfigBtFromJson(Map<String, dynamic> json) =>
|
||||
ExtraConfigBt()
|
||||
..trackerSubscribeUrls = (json['trackerSubscribeUrls'] as List<dynamic>)
|
||||
.map((e) => e as String)
|
||||
.toList()
|
||||
..subscribeTrackers = (json['subscribeTrackers'] as List<dynamic>)
|
||||
.map((e) => e as String)
|
||||
.toList()
|
||||
..lastTrackerUpdateTime = json['lastTrackerUpdateTime'] == null
|
||||
ExtraConfigBt(
|
||||
trackerSubscribeUrls: (json['trackerSubscribeUrls'] as List<dynamic>?)
|
||||
?.map((e) => e as String)
|
||||
.toList() ??
|
||||
const [],
|
||||
subscribeTrackers: (json['subscribeTrackers'] as List<dynamic>?)
|
||||
?.map((e) => e as String)
|
||||
.toList() ??
|
||||
const [],
|
||||
autoUpdateTrackers: json['autoUpdateTrackers'] as bool? ?? true,
|
||||
lastTrackerUpdateTime: json['lastTrackerUpdateTime'] == null
|
||||
? null
|
||||
: DateTime.parse(json['lastTrackerUpdateTime'] as String)
|
||||
..customTrackers = (json['customTrackers'] as List<dynamic>)
|
||||
.map((e) => e as String)
|
||||
.toList();
|
||||
: DateTime.parse(json['lastTrackerUpdateTime'] as String),
|
||||
customTrackers: (json['customTrackers'] as List<dynamic>?)
|
||||
?.map((e) => e as String)
|
||||
.toList() ??
|
||||
const [],
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ExtraConfigBtToJson(ExtraConfigBt instance) {
|
||||
final val = <String, dynamic>{
|
||||
'trackerSubscribeUrls': instance.trackerSubscribeUrls,
|
||||
'subscribeTrackers': instance.subscribeTrackers,
|
||||
'autoUpdateTrackers': instance.autoUpdateTrackers,
|
||||
};
|
||||
|
||||
void writeNotNull(String key, dynamic value) {
|
||||
|
||||
@@ -95,6 +95,9 @@ class AppController extends GetxController with WindowListener, TrayListener {
|
||||
|
||||
_initForegroundTask().onError((error, stackTrace) =>
|
||||
logger.w("initForegroundTask error", error, stackTrace));
|
||||
|
||||
_initTrackerUpdate().onError((error, stackTrace) =>
|
||||
logger.w("initTrackerUpdate error", error, stackTrace));
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -357,12 +360,13 @@ class AppController extends GetxController with WindowListener, TrayListener {
|
||||
btConfig.trackers.toSet().toList();
|
||||
}
|
||||
|
||||
Future<void> trackerUpdateOnStart() async {
|
||||
Future<void> _initTrackerUpdate() async {
|
||||
final btExtConfig = downloaderConfig.value.extra.bt;
|
||||
final lastUpdateTime = btExtConfig.lastTrackerUpdateTime;
|
||||
// if last update time is null or more than 1 day, update trackers
|
||||
if (lastUpdateTime == null ||
|
||||
lastUpdateTime.difference(DateTime.now()).inDays < 0) {
|
||||
if (btExtConfig.autoUpdateTrackers &&
|
||||
(lastUpdateTime == null ||
|
||||
lastUpdateTime.difference(DateTime.now()).inDays < 0)) {
|
||||
try {
|
||||
await trackerUpdate();
|
||||
} catch (e) {
|
||||
@@ -386,9 +390,6 @@ class AppController extends GetxController with WindowListener, TrayListener {
|
||||
|
||||
_initDownloaderConfig() async {
|
||||
final config = downloaderConfig.value;
|
||||
if (config.protocolConfig.http.connections == 0) {
|
||||
config.protocolConfig.http.connections = 16;
|
||||
}
|
||||
final extra = config.extra;
|
||||
if (extra.themeMode.isEmpty) {
|
||||
extra.themeMode = ThemeMode.dark.name;
|
||||
|
||||
@@ -138,6 +138,22 @@ class SettingView extends GetView<SettingController> {
|
||||
],
|
||||
);
|
||||
});
|
||||
final buildHttpUseServerCtime = _buildConfigItem(
|
||||
'useServerCtime'.tr, () => httpConfig.useServerCtime.toString(),
|
||||
(Key key) {
|
||||
return Container(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Switch(
|
||||
value: httpConfig.useServerCtime,
|
||||
onChanged: (bool value) {
|
||||
downloaderCfg.update((val) {
|
||||
val!.protocolConfig.http.useServerCtime = value;
|
||||
});
|
||||
debounceSave();
|
||||
},
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
// bt config items start
|
||||
final btConfig = downloaderCfg.value.protocolConfig.bt;
|
||||
@@ -207,8 +223,13 @@ class SettingView extends GetView<SettingController> {
|
||||
Expanded(
|
||||
child: SwitchListTile(
|
||||
controlAffinity: ListTileControlAffinity.leading,
|
||||
value: true,
|
||||
onChanged: (bool value) {},
|
||||
value: btExtConfig.autoUpdateTrackers,
|
||||
onChanged: (bool value) {
|
||||
downloaderCfg.update((val) {
|
||||
val!.extra.bt.autoUpdateTrackers = value;
|
||||
});
|
||||
debounceSave();
|
||||
},
|
||||
title: Text('updateDaily'.tr)),
|
||||
),
|
||||
],
|
||||
@@ -676,6 +697,7 @@ class SettingView extends GetView<SettingController> {
|
||||
children: _addDivider([
|
||||
buildHttpUa(),
|
||||
buildHttpConnections(),
|
||||
buildHttpUseServerCtime(),
|
||||
]),
|
||||
)),
|
||||
const Text('BitTorrent'),
|
||||
|
||||
@@ -5,6 +5,8 @@ const enUS = {
|
||||
'tip': 'Tip',
|
||||
'confirm': 'Confirm',
|
||||
'cancel': 'Cancel',
|
||||
'on': 'On',
|
||||
'off': 'Off',
|
||||
'selectAll': 'Select All',
|
||||
'task': 'Tasks',
|
||||
'downloading': 'downloading',
|
||||
@@ -31,6 +33,7 @@ const enUS = {
|
||||
'downloadDir': 'Download Directory',
|
||||
'downloadDirValid': 'Please select the download directory',
|
||||
'connections': 'Connections',
|
||||
'useServerCtime': 'Use server time for file creation',
|
||||
'maxRunning': 'Max Running Tasks',
|
||||
'items': '@count items',
|
||||
'subscribeTracker': 'Subscribe Tracker',
|
||||
|
||||
@@ -5,6 +5,8 @@ const zhCN = {
|
||||
'tip': '提示',
|
||||
'confirm': '确认',
|
||||
'cancel': '取消',
|
||||
'on': '开启',
|
||||
'off': '关闭',
|
||||
'selectAll': '全选',
|
||||
'task': '任务',
|
||||
'downloading': '下载中',
|
||||
@@ -30,6 +32,7 @@ const zhCN = {
|
||||
'downloadDir': '下载目录',
|
||||
'downloadDirValid': '请选择下载目录',
|
||||
'connections': '连接数',
|
||||
'useServerCtime': '创建文件使用服务器时间',
|
||||
'maxRunning': '最大下载数',
|
||||
'items': '@count 项',
|
||||
'subscribeTracker': '订阅 Tracker',
|
||||
|
||||
@@ -5,6 +5,8 @@ const zhTW = {
|
||||
'tip': '提示',
|
||||
'confirm': '確定',
|
||||
'cancel': '取消',
|
||||
'on': '開啟',
|
||||
'off': '關閉',
|
||||
'selectAll': '全選',
|
||||
'task': '任務',
|
||||
'downloading': '下載中',
|
||||
@@ -30,6 +32,7 @@ const zhTW = {
|
||||
'downloadDir': '下載目録',
|
||||
'downloadDirValid': '請選擇下載目録',
|
||||
'connections': '同時連接數',
|
||||
'useServerCtime': '使用伺服器時間作為檔案建立時間',
|
||||
'maxRunning': '最大同時下載數',
|
||||
'items': '@count 項',
|
||||
'subscribeTracker': '已訂閲的追蹤者列表',
|
||||
|
||||
@@ -73,9 +73,6 @@ Future<void> init() async {
|
||||
}
|
||||
|
||||
Future<void> onStart() async {
|
||||
final appController = Get.find<AppController>();
|
||||
await appController.trackerUpdateOnStart();
|
||||
|
||||
// if is debug mode, check language message is complete,change debug locale to your comfortable language if you want
|
||||
if (kDebugMode) {
|
||||
final debugLang = getLocaleKey(debugLocale);
|
||||
|
||||
Reference in new issue
Block a user