mirror of
https://github.com/simon-ding/polaris.git
synced 2026-03-09 19:20:46 +08:00
feat: add to blacklist ui
This commit is contained in:
9
db/db.go
9
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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -60,11 +60,14 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
|
||||
AsyncValue<List<Activity>>? 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<ActivityPage>
|
||||
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<ActivityPage>
|
||||
);
|
||||
}
|
||||
|
||||
Function(int) onDelete() {
|
||||
return (id) {
|
||||
final f = ref
|
||||
.read(activitiesDataProvider(ActivityStatus.active).notifier)
|
||||
.deleteActivity(id);
|
||||
showLoadingWithFuture(f);
|
||||
};
|
||||
Future<void> showConfirmDialog(BuildContext oriContext, int id) {
|
||||
var add2Blacklist = false;
|
||||
return showDialog<void>(
|
||||
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);
|
||||
}),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,11 +68,11 @@ class ActivityData
|
||||
return activities;
|
||||
}
|
||||
|
||||
Future<void> deleteActivity(int id) async {
|
||||
Future<void> 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) {
|
||||
|
||||
Reference in New Issue
Block a user