mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-05 09:27:43 +08:00
feat: prowlarr refactor and support prowlarr seed ratio
This commit is contained in:
@@ -161,6 +161,7 @@ class Indexer {
|
||||
int? priority;
|
||||
double? seedRatio;
|
||||
bool? disabled;
|
||||
bool? synced;
|
||||
|
||||
Indexer(
|
||||
{this.name,
|
||||
@@ -169,7 +170,8 @@ class Indexer {
|
||||
this.id,
|
||||
this.priority = 50,
|
||||
this.seedRatio = 0,
|
||||
this.disabled});
|
||||
this.disabled,
|
||||
this.synced});
|
||||
|
||||
Indexer.fromJson(Map<String, dynamic> json) {
|
||||
name = json['name'];
|
||||
@@ -179,6 +181,7 @@ class Indexer {
|
||||
priority = json["priority"];
|
||||
seedRatio = json["seed_ratio"] ?? 0;
|
||||
disabled = json["disabled"] ?? false;
|
||||
synced = json["synced"] ?? false;
|
||||
}
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:form_builder_validators/form_builder_validators.dart';
|
||||
import 'package:ui/providers/settings.dart';
|
||||
import 'package:ui/settings/dialog.dart';
|
||||
import 'package:ui/widgets/progress_indicator.dart';
|
||||
import 'package:ui/widgets/utils.dart';
|
||||
import 'package:ui/widgets/widgets.dart';
|
||||
|
||||
class IndexerSettings extends ConsumerStatefulWidget {
|
||||
@@ -16,22 +17,112 @@ class IndexerSettings extends ConsumerStatefulWidget {
|
||||
}
|
||||
|
||||
class _IndexerState extends ConsumerState<IndexerSettings> {
|
||||
final _formKey = GlobalKey<FormBuilderState>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var indexers = ref.watch(indexersProvider);
|
||||
return indexers.when(
|
||||
data: (value) => Wrap(
|
||||
children: List.generate(value.length + 1, (i) {
|
||||
if (i < value.length) {
|
||||
var indexer = value[i];
|
||||
return SettingsCard(
|
||||
onTap: () => showIndexerDetails(indexer),
|
||||
child: Text(indexer.name ?? ""));
|
||||
}
|
||||
return SettingsCard(
|
||||
onTap: () => showIndexerDetails(Indexer()),
|
||||
child: const Icon(Icons.add));
|
||||
}),
|
||||
data: (value) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 10, bottom: 10, left: 10),
|
||||
child: Text("Prowlarr 设置", style: TextStyle(fontSize: 18)),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 20), child: prowlarrSetting()),
|
||||
Divider(),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 10, bottom: 10, left: 10),
|
||||
child: Text("索引器列表", style: TextStyle(fontSize: 18)),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 20),
|
||||
child: Wrap(
|
||||
children: List.generate(value.length + 1, (i) {
|
||||
if (i < value.length) {
|
||||
var indexer = value[i];
|
||||
return SettingsCard(
|
||||
onTap: () => showIndexerDetails(indexer),
|
||||
child: Text(indexer.name ?? ""));
|
||||
}
|
||||
return SettingsCard(
|
||||
onTap: () => showIndexerDetails(Indexer()),
|
||||
child: const Icon(Icons.add));
|
||||
}),
|
||||
)),
|
||||
],
|
||||
);
|
||||
},
|
||||
error: (err, trace) => PoNetworkError(err: err),
|
||||
loading: () => const MyProgressIndicator());
|
||||
}
|
||||
|
||||
Widget prowlarrSetting() {
|
||||
var ps = ref.watch(prowlarrSettingDataProvider);
|
||||
return ps.when(
|
||||
data: (v) => FormBuilder(
|
||||
key: _formKey, //设置globalKey,用于后面获取FormState
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
initialValue: {
|
||||
"api_key": v.apiKey,
|
||||
"url": v.url,
|
||||
"disabled": v.disabled
|
||||
},
|
||||
child: Column(
|
||||
children: [
|
||||
FormBuilderTextField(
|
||||
name: "url",
|
||||
decoration: const InputDecoration(
|
||||
labelText: "Prowlarr URL",
|
||||
icon: Icon(Icons.web),
|
||||
hintText: "http://10.0.0.8:9696"),
|
||||
validator: FormBuilderValidators.required(),
|
||||
),
|
||||
FormBuilderTextField(
|
||||
name: "api_key",
|
||||
decoration: const InputDecoration(
|
||||
labelText: "API Key",
|
||||
icon: Icon(Icons.key),
|
||||
helperText: "Prowlarr 设置 -> 通用 -> API 密钥"),
|
||||
validator: FormBuilderValidators.required(),
|
||||
),
|
||||
FormBuilderSwitch(
|
||||
name: "disabled",
|
||||
title: const Text("禁用 Prowlarr"),
|
||||
decoration:
|
||||
InputDecoration(icon: Icon(Icons.do_not_disturb)),
|
||||
),
|
||||
Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(10),
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
if (_formKey.currentState!.saveAndValidate()) {
|
||||
var values = _formKey.currentState!.value;
|
||||
var f = ref
|
||||
.read(prowlarrSettingDataProvider.notifier)
|
||||
.save(ProwlarrSetting(
|
||||
apiKey: values["api_key"],
|
||||
url: values["url"],
|
||||
disabled: values["disabled"]))
|
||||
.then((v) {
|
||||
showSnakeBar("更新成功");
|
||||
ref.invalidate(indexersProvider);
|
||||
});
|
||||
showLoadingWithFuture(f);
|
||||
}
|
||||
},
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: Text("保存"),
|
||||
)),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
error: (err, trace) => PoNetworkError(err: err),
|
||||
loading: () => const MyProgressIndicator());
|
||||
@@ -54,6 +145,7 @@ class _IndexerState extends ConsumerState<IndexerSettings> {
|
||||
child: Column(
|
||||
children: [
|
||||
FormBuilderDropdown(
|
||||
enabled: indexer.synced != true,
|
||||
name: "impl",
|
||||
decoration: const InputDecoration(labelText: "类型"),
|
||||
items: const [
|
||||
@@ -61,24 +153,28 @@ class _IndexerState extends ConsumerState<IndexerSettings> {
|
||||
],
|
||||
),
|
||||
FormBuilderTextField(
|
||||
enabled: indexer.synced != true,
|
||||
name: "name",
|
||||
decoration: Commons.requiredTextFieldStyle(text: "名称"),
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: FormBuilderValidators.required(),
|
||||
),
|
||||
FormBuilderTextField(
|
||||
enabled: indexer.synced != true,
|
||||
name: "url",
|
||||
decoration: Commons.requiredTextFieldStyle(text: "地址"),
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: FormBuilderValidators.required(),
|
||||
),
|
||||
FormBuilderTextField(
|
||||
enabled: indexer.synced != true,
|
||||
name: "api_key",
|
||||
decoration: Commons.requiredTextFieldStyle(text: "API Key"),
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: FormBuilderValidators.required(),
|
||||
),
|
||||
FormBuilderTextField(
|
||||
enabled: indexer.synced != true,
|
||||
name: "priority",
|
||||
decoration: const InputDecoration(
|
||||
labelText: "索引优先级",
|
||||
@@ -88,6 +184,7 @@ class _IndexerState extends ConsumerState<IndexerSettings> {
|
||||
validator: FormBuilderValidators.positiveNumber(),
|
||||
),
|
||||
FormBuilderTextField(
|
||||
enabled: indexer.synced != true,
|
||||
name: "seed_ratio",
|
||||
decoration: const InputDecoration(
|
||||
labelText: "做种率",
|
||||
@@ -97,7 +194,10 @@ class _IndexerState extends ConsumerState<IndexerSettings> {
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: FormBuilderValidators.numeric(),
|
||||
),
|
||||
FormBuilderSwitch(name: "disabled", title: const Text("禁用此索引器"))
|
||||
FormBuilderSwitch(
|
||||
enabled: indexer.synced != true,
|
||||
name: "disabled",
|
||||
title: const Text("禁用此索引器"))
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -122,6 +222,11 @@ class _IndexerState extends ConsumerState<IndexerSettings> {
|
||||
}
|
||||
|
||||
return showSettingDialog(
|
||||
context, "索引器", indexer.id != null, body, onSubmit, onDelete);
|
||||
context,
|
||||
indexer.synced != true?"索引器":"Prowlarr 索引器",
|
||||
(indexer.id != null) && (indexer.synced != true),
|
||||
body,
|
||||
onSubmit,
|
||||
onDelete);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import 'package:ui/settings/general.dart';
|
||||
import 'package:ui/settings/importlist.dart';
|
||||
import 'package:ui/settings/indexer.dart';
|
||||
import 'package:ui/settings/notifier.dart';
|
||||
import 'package:ui/settings/prowlarr.dart';
|
||||
import 'package:ui/settings/storage.dart';
|
||||
|
||||
class SystemSettingsPage extends ConsumerStatefulWidget {
|
||||
@@ -27,7 +26,6 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
||||
children: [
|
||||
getExpansionTile("常规", const GeneralSettings()),
|
||||
getExpansionTile("索引器", const IndexerSettings()),
|
||||
getExpansionTile("Prowlarr 设置", const ProwlarrSettingPage()),
|
||||
getExpansionTile("下载器", const DownloaderSettings()),
|
||||
getExpansionTile("存储", const StorageSettings()),
|
||||
getExpansionTile("通知客户端", const NotifierSettings()),
|
||||
|
||||
Reference in New Issue
Block a user