mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-26 02:34:58 +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 tmdbImgBaseUrl = "$_baseUrl/api/v1/posters";
|
||||||
|
|
||||||
|
static final cronJobUrl = "$_baseUrl/api/v1/setting/cron/trigger";
|
||||||
|
|
||||||
static const tmdbApiKey = "tmdb_api_key";
|
static const tmdbApiKey = "tmdb_api_key";
|
||||||
static const downloadDirKey = "download_dir";
|
static const downloadDirKey = "download_dir";
|
||||||
|
|
||||||
@@ -100,4 +102,14 @@ class APIs {
|
|||||||
context.go('/login');
|
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/providers/settings.dart';
|
||||||
import 'package:ui/widgets/utils.dart';
|
import 'package:ui/widgets/utils.dart';
|
||||||
import 'package:ui/widgets/progress_indicator.dart';
|
import 'package:ui/widgets/progress_indicator.dart';
|
||||||
|
import 'package:ui/widgets/widgets.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
class SystemPage extends ConsumerStatefulWidget {
|
class SystemPage extends ConsumerStatefulWidget {
|
||||||
@@ -28,8 +29,8 @@ class _SystemPageState extends ConsumerState<SystemPage> {
|
|||||||
ExpansionTile(
|
ExpansionTile(
|
||||||
expandedCrossAxisAlignment: CrossAxisAlignment.stretch,
|
expandedCrossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
initiallyExpanded: true,
|
initiallyExpanded: true,
|
||||||
childrenPadding: EdgeInsets.all(20),
|
childrenPadding: const EdgeInsets.all(20),
|
||||||
title: Text("日志"),
|
title: const Text("日志"),
|
||||||
children: [
|
children: [
|
||||||
logs.when(
|
logs.when(
|
||||||
data: (list) {
|
data: (list) {
|
||||||
@@ -59,7 +60,62 @@ class _SystemPageState extends ConsumerState<SystemPage> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
ExpansionTile(
|
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,
|
expandedCrossAxisAlignment: CrossAxisAlignment.center,
|
||||||
initiallyExpanded: true,
|
initiallyExpanded: true,
|
||||||
children: [
|
children: [
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ class _MySliderState extends State<MyRangeSlider> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class LoadingIconButton extends StatefulWidget {
|
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 Future<void> Function() onPressed;
|
||||||
final IconData icon;
|
final IconData icon;
|
||||||
final String? tooltip;
|
final String? tooltip;
|
||||||
@@ -187,7 +187,7 @@ class _LoadingIconButtonState extends State<LoadingIconButton> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class LoadingTextButton extends StatefulWidget {
|
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 Future<void> Function() onPressed;
|
||||||
final Widget label;
|
final Widget label;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user