mirror of
https://github.com/simon-ding/polaris.git
synced 2026-02-06 15:10:49 +08:00
feat: add prowlarr enable button
This commit is contained in:
@@ -63,6 +63,7 @@ type Limiter struct {
|
||||
}
|
||||
|
||||
type ProwlarrSetting struct {
|
||||
ApiKey string `json:"api_key"`
|
||||
URL string `json:"url"`
|
||||
Disabled bool `json:"disabled"`
|
||||
ApiKey string `json:"api_key"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ func searchWithTorznab(db *db.Client, t prowlarr.ProwlarrSupportType, queries ..
|
||||
allTorznab := db.GetAllTorznabInfo()
|
||||
|
||||
p, err := db.GetProwlarrSetting()
|
||||
if err == nil { //prowlarr exists
|
||||
if err == nil && !p.Disabled { //prowlarr exists
|
||||
c := prowlarr.New(p.ApiKey, p.URL)
|
||||
all, err := c.GetIndexers(t)
|
||||
if err != nil {
|
||||
|
||||
@@ -318,9 +318,11 @@ func (s *Server) SaveProwlarrSetting(c *gin.Context) (interface{}, error) {
|
||||
if err := c.ShouldBindJSON(&in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
client := prowlarr.New(in.ApiKey, in.URL)
|
||||
if _, err := client.GetIndexers(prowlarr.TV); err != nil {
|
||||
return nil, errors.Wrap(err, "connect to prowlarr error")
|
||||
if !in.Disabled {
|
||||
client := prowlarr.New(in.ApiKey, in.URL)
|
||||
if _, err := client.GetIndexers(prowlarr.TV); err != nil {
|
||||
return nil, errors.Wrap(err, "connect to prowlarr error")
|
||||
}
|
||||
}
|
||||
err := s.db.SaveProwlarrSetting(&in)
|
||||
if err != nil {
|
||||
|
||||
@@ -32,7 +32,7 @@ var prowlarrSettingDataProvider =
|
||||
class EditSettingData extends AutoDisposeAsyncNotifier<GeneralSetting> {
|
||||
@override
|
||||
FutureOr<GeneralSetting> build() async {
|
||||
final dio = APIs.getDio();
|
||||
final dio = APIs.getDio();
|
||||
|
||||
var resp = await dio.get(APIs.settingsGeneralUrl);
|
||||
var rrr = ServerResponse.fromJson(resp.data);
|
||||
@@ -509,14 +509,20 @@ class ImportListData extends AutoDisposeAsyncNotifier<List<ImportList>> {
|
||||
}
|
||||
|
||||
class ProwlarrSetting {
|
||||
final bool disabled;
|
||||
final String apiKey;
|
||||
final String url;
|
||||
ProwlarrSetting({required this.apiKey, required this.url});
|
||||
ProwlarrSetting(
|
||||
{required this.apiKey, required this.url, required this.disabled});
|
||||
factory ProwlarrSetting.fromJson(Map<String, dynamic> json) {
|
||||
return ProwlarrSetting(apiKey: json["api_key"], url: json["url"]);
|
||||
return ProwlarrSetting(
|
||||
apiKey: json["api_key"],
|
||||
url: json["url"],
|
||||
disabled: json["disabled"] ?? false);
|
||||
}
|
||||
|
||||
Map<String, dynamic> tojson() => {"api_key": apiKey, "url": url};
|
||||
Map<String, dynamic> tojson() =>
|
||||
{"api_key": apiKey, "url": url, "disabled": disabled};
|
||||
}
|
||||
|
||||
class ProwlarrSettingData extends AutoDisposeAsyncNotifier<ProwlarrSetting> {
|
||||
|
||||
@@ -25,9 +25,18 @@ class ProwlarrSettingState extends ConsumerState<ProwlarrSettingPage> {
|
||||
data: (v) => FormBuilder(
|
||||
key: _formKey, //设置globalKey,用于后面获取FormState
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
initialValue: {"api_key": v.apiKey, "url": v.url},
|
||||
initialValue: {
|
||||
"api_key": v.apiKey,
|
||||
"url": v.url,
|
||||
"enabled": !v.disabled
|
||||
},
|
||||
child: Column(
|
||||
children: [
|
||||
FormBuilderSwitch(
|
||||
name: "enabled",
|
||||
title: const Text("启用"),
|
||||
decoration: InputDecoration(icon: Icon(Icons.check_circle)),
|
||||
),
|
||||
FormBuilderTextField(
|
||||
name: "url",
|
||||
decoration: const InputDecoration(
|
||||
@@ -55,12 +64,16 @@ class ProwlarrSettingState extends ConsumerState<ProwlarrSettingPage> {
|
||||
.read(prowlarrSettingDataProvider.notifier)
|
||||
.save(ProwlarrSetting(
|
||||
apiKey: values["api_key"],
|
||||
url: values["url"]))
|
||||
url: values["url"],
|
||||
disabled: !values["enabled"]))
|
||||
.then((v) => showSnakeBar("更新成功"));
|
||||
showLoadingWithFuture(f);
|
||||
}
|
||||
},
|
||||
child: const Padding(padding: EdgeInsets.all(10), child: Text("保存"),)),
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: Text("保存"),
|
||||
)),
|
||||
),
|
||||
)
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user