Skip to content

Commit 0dea185

Browse files
committed
feat: add to blacklist ui
1 parent 834254b commit 0dea185

File tree

5 files changed

+74
-17
lines changed

5 files changed

+74
-17
lines changed

db/db.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,14 @@ func (c *client) GetAllDonloadClients() []*ent.DownloadClients {
323323
cc, err := c.ent.DownloadClients.Query().Order(ent.Asc(downloadclients.FieldPriority1)).All(context.TODO())
324324
if err != nil {
325325
log.Errorf("no download client")
326-
return nil
326+
return []*ent.DownloadClients{
327+
{
328+
Implementation: downloadclients.ImplementationBuildin,
329+
Name: "内建下载器",
330+
Priority1: 9999,
331+
Enable: true,
332+
},
333+
}
327334
}
328335
cc = append(cc, &ent.DownloadClients{
329336
Implementation: downloadclients.ImplementationBuildin,

engine/client.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type Engine struct {
3636
tasks utils.Map[int, *Task]
3737
language string
3838
schedulers utils.Map[string, scheduler]
39+
buildin *buildin.Downloader
3940
}
4041

4142
func (c *Engine) registerCronJob(name string, cron string, f func() error) {
@@ -143,8 +144,16 @@ func (c *Engine) reloadTasks() {
143144
}
144145

145146
func (c *Engine) buildInDownloader() (pkg.Downloader, error) {
147+
if c.buildin!= nil {
148+
return c.buildin, nil
149+
}
146150
dir := c.db.GetDownloadDir()
147-
return buildin.NewDownloader(dir)
151+
d, err := buildin.NewDownloader(dir)
152+
if err != nil {
153+
return nil, errors.Wrap(err, "buildin downloader")
154+
}
155+
c.buildin = d
156+
return d, nil
148157
}
149158

150159
func (c *Engine) GetDownloadClient() (pkg.Downloader, *ent.DownloadClients, error) {
@@ -175,7 +184,7 @@ func (c *Engine) GetDownloadClient() (pkg.Downloader, *ent.DownloadClients, erro
175184
} else if d.Implementation == downloadclients.ImplementationBuildin {
176185
bin, err := c.buildInDownloader()
177186
if err != nil {
178-
log.Warnf("connect to download client error: %v", d.URL)
187+
log.Warnf("connect to download client error: %v", err)
179188
continue
180189
}
181190
return bin, d, nil

server/activity.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ func (s *Server) RemoveActivity(c *gin.Context) (interface{}, error) {
106106
episodeIds := s.core.GetEpisodeIds(his)
107107

108108
for _, id := range episodeIds {
109-
ep, _ := s.db.GetEpisode(his.MediaID, his.SeasonNum, id)
109+
ep, err := s.db.GetEpisode(his.MediaID, his.SeasonNum, id)
110+
if err != nil {
111+
log.Warnf("get episode error: %v", err)
112+
continue
113+
}
110114
if !s.db.IsEpisodeDownloadingOrDownloaded(id) && ep.Status != episode.StatusDownloaded {
111115
//没有正在下载中或者下载完成的任务,并且episode状态不是已经下载完成
112116
s.db.SetEpisodeStatus(id, episode.StatusMissing)

ui/lib/activity.dart

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,14 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
6060
AsyncValue<List<Activity>>? activitiesWatcher;
6161

6262
if (selectedTab == 2) {
63-
activitiesWatcher = ref.watch(activitiesDataProvider(ActivityStatus.archive));
63+
activitiesWatcher =
64+
ref.watch(activitiesDataProvider(ActivityStatus.archive));
6465
} else if (selectedTab == 1) {
65-
activitiesWatcher = ref.watch(activitiesDataProvider(ActivityStatus.seeding));
66+
activitiesWatcher =
67+
ref.watch(activitiesDataProvider(ActivityStatus.seeding));
6668
} else if (selectedTab == 0) {
67-
activitiesWatcher = ref.watch(activitiesDataProvider(ActivityStatus.active));
69+
activitiesWatcher =
70+
ref.watch(activitiesDataProvider(ActivityStatus.active));
6871
}
6972

7073
return activitiesWatcher!.when(
@@ -143,7 +146,8 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
143146
trailing: selectedTab != 2
144147
? IconButton(
145148
tooltip: "删除任务",
146-
onPressed: () => onDelete()(ac.id!),
149+
onPressed: () =>
150+
showConfirmDialog(context, ac.id!),
147151
icon: const Icon(Icons.delete))
148152
: const Text("-"),
149153
),
@@ -160,12 +164,45 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
160164
);
161165
}
162166

163-
Function(int) onDelete() {
164-
return (id) {
165-
final f = ref
166-
.read(activitiesDataProvider(ActivityStatus.active).notifier)
167-
.deleteActivity(id);
168-
showLoadingWithFuture(f);
169-
};
167+
Future<void> showConfirmDialog(BuildContext oriContext, int id) {
168+
var add2Blacklist = false;
169+
return showDialog<void>(
170+
context: context,
171+
barrierDismissible: true,
172+
builder: (BuildContext context) {
173+
return AlertDialog(
174+
title: const Text("确认删除"),
175+
content: StatefulBuilder(builder: (context, setState) {
176+
return CheckboxListTile(
177+
value: add2Blacklist,
178+
title: Text("加入黑名单"),
179+
onChanged: (v) {
180+
setState(
181+
() {
182+
add2Blacklist = v!;
183+
},
184+
);
185+
});
186+
}),
187+
actions: [
188+
TextButton(
189+
onPressed: () => Navigator.of(context).pop(),
190+
child: const Text("取消")),
191+
TextButton(
192+
child: const Text("确认"),
193+
onPressed: () {
194+
final f = ref
195+
.read(activitiesDataProvider(ActivityStatus.active)
196+
.notifier)
197+
.deleteActivity(id, add2Blacklist)
198+
.then((value) {
199+
Navigator.of(context).pop();
200+
});
201+
showLoadingWithFuture(f);
202+
}),
203+
],
204+
);
205+
},
206+
);
170207
}
171208
}

ui/lib/providers/activity.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ class ActivityData
6868
return activities;
6969
}
7070

71-
Future<void> deleteActivity(int id) async {
71+
Future<void> deleteActivity(int id, bool add2Blacklist) async {
7272
final dio = APIs.getDio();
7373
var resp = await dio.post(APIs.activityDeleteUrl, data: {
7474
"id": id,
75-
"add_2_blacklist": false,
75+
"add_2_blacklist": add2Blacklist,
7676
});
7777
final sp = ServerResponse.fromJson(resp.data);
7878
if (sp.code != 0) {

0 commit comments

Comments
 (0)