diff --git a/db/db.go b/db/db.go index f90621f..343e1fd 100644 --- a/db/db.go +++ b/db/db.go @@ -323,7 +323,14 @@ func (c *client) GetAllDonloadClients() []*ent.DownloadClients { cc, err := c.ent.DownloadClients.Query().Order(ent.Asc(downloadclients.FieldPriority1)).All(context.TODO()) if err != nil { log.Errorf("no download client") - return nil + return []*ent.DownloadClients{ + { + Implementation: downloadclients.ImplementationBuildin, + Name: "内建下载器", + Priority1: 9999, + Enable: true, + }, + } } cc = append(cc, &ent.DownloadClients{ Implementation: downloadclients.ImplementationBuildin, diff --git a/engine/client.go b/engine/client.go index 77cf919..906dc5c 100644 --- a/engine/client.go +++ b/engine/client.go @@ -36,6 +36,7 @@ type Engine struct { tasks utils.Map[int, *Task] language string schedulers utils.Map[string, scheduler] + buildin *buildin.Downloader } func (c *Engine) registerCronJob(name string, cron string, f func() error) { @@ -143,8 +144,16 @@ func (c *Engine) reloadTasks() { } func (c *Engine) buildInDownloader() (pkg.Downloader, error) { + if c.buildin!= nil { + return c.buildin, nil + } dir := c.db.GetDownloadDir() - return buildin.NewDownloader(dir) + d, err := buildin.NewDownloader(dir) + if err != nil { + return nil, errors.Wrap(err, "buildin downloader") + } + c.buildin = d + return d, nil } func (c *Engine) GetDownloadClient() (pkg.Downloader, *ent.DownloadClients, error) { @@ -175,7 +184,7 @@ func (c *Engine) GetDownloadClient() (pkg.Downloader, *ent.DownloadClients, erro } else if d.Implementation == downloadclients.ImplementationBuildin { bin, err := c.buildInDownloader() if err != nil { - log.Warnf("connect to download client error: %v", d.URL) + log.Warnf("connect to download client error: %v", err) continue } return bin, d, nil diff --git a/server/activity.go b/server/activity.go index 4622930..655d1d5 100644 --- a/server/activity.go +++ b/server/activity.go @@ -106,7 +106,11 @@ func (s *Server) RemoveActivity(c *gin.Context) (interface{}, error) { episodeIds := s.core.GetEpisodeIds(his) for _, id := range episodeIds { - ep, _ := s.db.GetEpisode(his.MediaID, his.SeasonNum, id) + ep, err := s.db.GetEpisode(his.MediaID, his.SeasonNum, id) + if err != nil { + log.Warnf("get episode error: %v", err) + continue + } if !s.db.IsEpisodeDownloadingOrDownloaded(id) && ep.Status != episode.StatusDownloaded { //没有正在下载中或者下载完成的任务,并且episode状态不是已经下载完成 s.db.SetEpisodeStatus(id, episode.StatusMissing) diff --git a/ui/lib/activity.dart b/ui/lib/activity.dart index fb6ec44..a3d5bbc 100644 --- a/ui/lib/activity.dart +++ b/ui/lib/activity.dart @@ -60,11 +60,14 @@ class _ActivityPageState extends ConsumerState AsyncValue>? activitiesWatcher; if (selectedTab == 2) { - activitiesWatcher = ref.watch(activitiesDataProvider(ActivityStatus.archive)); + activitiesWatcher = + ref.watch(activitiesDataProvider(ActivityStatus.archive)); } else if (selectedTab == 1) { - activitiesWatcher = ref.watch(activitiesDataProvider(ActivityStatus.seeding)); + activitiesWatcher = + ref.watch(activitiesDataProvider(ActivityStatus.seeding)); } else if (selectedTab == 0) { - activitiesWatcher = ref.watch(activitiesDataProvider(ActivityStatus.active)); + activitiesWatcher = + ref.watch(activitiesDataProvider(ActivityStatus.active)); } return activitiesWatcher!.when( @@ -143,7 +146,8 @@ class _ActivityPageState extends ConsumerState trailing: selectedTab != 2 ? IconButton( tooltip: "删除任务", - onPressed: () => onDelete()(ac.id!), + onPressed: () => + showConfirmDialog(context, ac.id!), icon: const Icon(Icons.delete)) : const Text("-"), ), @@ -160,12 +164,45 @@ class _ActivityPageState extends ConsumerState ); } - Function(int) onDelete() { - return (id) { - final f = ref - .read(activitiesDataProvider(ActivityStatus.active).notifier) - .deleteActivity(id); - showLoadingWithFuture(f); - }; + Future showConfirmDialog(BuildContext oriContext, int id) { + var add2Blacklist = false; + return showDialog( + context: context, + barrierDismissible: true, + builder: (BuildContext context) { + return AlertDialog( + title: const Text("确认删除"), + content: StatefulBuilder(builder: (context, setState) { + return CheckboxListTile( + value: add2Blacklist, + title: Text("加入黑名单"), + onChanged: (v) { + setState( + () { + add2Blacklist = v!; + }, + ); + }); + }), + actions: [ + TextButton( + onPressed: () => Navigator.of(context).pop(), + child: const Text("取消")), + TextButton( + child: const Text("确认"), + onPressed: () { + final f = ref + .read(activitiesDataProvider(ActivityStatus.active) + .notifier) + .deleteActivity(id, add2Blacklist) + .then((value) { + Navigator.of(context).pop(); + }); + showLoadingWithFuture(f); + }), + ], + ); + }, + ); } } diff --git a/ui/lib/providers/activity.dart b/ui/lib/providers/activity.dart index 74ff01c..cab2c59 100644 --- a/ui/lib/providers/activity.dart +++ b/ui/lib/providers/activity.dart @@ -68,11 +68,11 @@ class ActivityData return activities; } - Future deleteActivity(int id) async { + Future deleteActivity(int id, bool add2Blacklist) async { final dio = APIs.getDio(); var resp = await dio.post(APIs.activityDeleteUrl, data: { "id": id, - "add_2_blacklist": false, + "add_2_blacklist": add2Blacklist, }); final sp = ServerResponse.fromJson(resp.data); if (sp.code != 0) {