mirror of
https://github.com/simon-ding/polaris.git
synced 2026-03-07 18:10:49 +08:00
feat: ui to manaul trigger cron jobs
This commit is contained in:
@@ -46,6 +46,8 @@ class APIs {
|
||||
|
||||
static final tmdbImgBaseUrl = "$_baseUrl/api/v1/posters";
|
||||
|
||||
static final cronJobUrl = "$_baseUrl/api/v1/setting/cron/trigger";
|
||||
|
||||
static const tmdbApiKey = "tmdb_api_key";
|
||||
static const downloadDirKey = "download_dir";
|
||||
|
||||
@@ -100,4 +102,14 @@ class APIs {
|
||||
context.go('/login');
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> triggerCronJob(String name) async {
|
||||
var resp = await getDio().post(APIs.cronJobUrl, data: {"job_name": name});
|
||||
|
||||
var sp = ServerResponse.fromJson(resp.data);
|
||||
|
||||
if (sp.code != 0) {
|
||||
throw sp.message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:ui/providers/APIs.dart';
|
||||
import 'package:ui/providers/settings.dart';
|
||||
import 'package:ui/widgets/utils.dart';
|
||||
import 'package:ui/widgets/progress_indicator.dart';
|
||||
import 'package:ui/widgets/widgets.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class SystemPage extends ConsumerStatefulWidget {
|
||||
@@ -28,8 +29,8 @@ class _SystemPageState extends ConsumerState<SystemPage> {
|
||||
ExpansionTile(
|
||||
expandedCrossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
initiallyExpanded: true,
|
||||
childrenPadding: EdgeInsets.all(20),
|
||||
title: Text("日志"),
|
||||
childrenPadding: const EdgeInsets.all(20),
|
||||
title: const Text("日志"),
|
||||
children: [
|
||||
logs.when(
|
||||
data: (list) {
|
||||
@@ -59,7 +60,62 @@ class _SystemPageState extends ConsumerState<SystemPage> {
|
||||
],
|
||||
),
|
||||
ExpansionTile(
|
||||
title: Text("关于"),
|
||||
expandedCrossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
initiallyExpanded: true,
|
||||
childrenPadding: const EdgeInsets.all(20),
|
||||
title: const Text("定时任务"),
|
||||
children: [
|
||||
logs.when(
|
||||
data: (list) {
|
||||
return DataTable(columns: const [
|
||||
DataColumn(label: Text("任务")),
|
||||
DataColumn(label: Text("间隔")),
|
||||
DataColumn(label: Text("手动触发"))
|
||||
], rows: [
|
||||
DataRow(cells: [
|
||||
const DataCell(Text("检查并处理已完成任务")),
|
||||
const DataCell(Text("每分钟")),
|
||||
DataCell(LoadingIconButton(
|
||||
icon: Icons.not_started,
|
||||
onPressed: () =>
|
||||
APIs.triggerCronJob("check_running_tasks"),
|
||||
))
|
||||
]),
|
||||
DataRow(cells: [
|
||||
const DataCell(Text("下载监控中的剧集和电影")),
|
||||
const DataCell(Text("每小时")),
|
||||
DataCell(LoadingIconButton(
|
||||
icon: Icons.not_started,
|
||||
onPressed: () => APIs.triggerCronJob(
|
||||
"check_available_medias_to_download"),
|
||||
))
|
||||
]),
|
||||
DataRow(cells: [
|
||||
const DataCell(Text("更新监控列表")),
|
||||
const DataCell(Text("每小时")),
|
||||
DataCell(IconButton(
|
||||
icon: const Icon(Icons.not_started),
|
||||
onPressed: () =>
|
||||
APIs.triggerCronJob("update_import_lists"),
|
||||
))
|
||||
]),
|
||||
DataRow(cells: [
|
||||
const DataCell(Text("更新最新剧集信息")),
|
||||
const DataCell(Text("每天2次")),
|
||||
DataCell(LoadingIconButton(
|
||||
icon: Icons.not_started,
|
||||
onPressed: () =>
|
||||
APIs.triggerCronJob("check_series_new_release"),
|
||||
))
|
||||
]),
|
||||
]);
|
||||
},
|
||||
error: (err, trace) => Text("$err"),
|
||||
loading: () => const MyProgressIndicator())
|
||||
],
|
||||
),
|
||||
ExpansionTile(
|
||||
title: const Text("关于"),
|
||||
expandedCrossAxisAlignment: CrossAxisAlignment.center,
|
||||
initiallyExpanded: true,
|
||||
children: [
|
||||
|
||||
@@ -142,7 +142,7 @@ class _MySliderState extends State<MyRangeSlider> {
|
||||
}
|
||||
|
||||
class LoadingIconButton extends StatefulWidget {
|
||||
LoadingIconButton({required this.onPressed, required this.icon, this.tooltip});
|
||||
const LoadingIconButton({super.key, required this.onPressed, required this.icon, this.tooltip});
|
||||
final Future<void> Function() onPressed;
|
||||
final IconData icon;
|
||||
final String? tooltip;
|
||||
@@ -187,7 +187,7 @@ class _LoadingIconButtonState extends State<LoadingIconButton> {
|
||||
}
|
||||
|
||||
class LoadingTextButton extends StatefulWidget {
|
||||
LoadingTextButton({required this.onPressed, required this.label});
|
||||
const LoadingTextButton({super.key, required this.onPressed, required this.label});
|
||||
final Future<void> Function() onPressed;
|
||||
final Widget label;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user