mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2024-11-19 07:09:14 +00:00
feat: Check if the server supports logs
This commit is contained in:
parent
515b0e2c67
commit
8c5bdf9cd8
|
@ -37,7 +37,9 @@
|
|||
"alert": "Alert",
|
||||
"copied_to_clipboard": "Copied to clipboard!",
|
||||
"please_connect": "Please connect your server, domain and DNS provider to dive in!",
|
||||
"network_error": "Network error"
|
||||
"network_error": "Network error",
|
||||
"feature_unsupported_on_api_version": "This feature is only supported on server version {versionConstraint}. Your server is on version {currentVersion}.",
|
||||
"error": "Error"
|
||||
},
|
||||
"more_page": {
|
||||
"configuration_wizard": "Setup wizard",
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:pub_semver/pub_semver.dart';
|
||||
import 'package:selfprivacy/config/get_it_config.dart';
|
||||
import 'package:selfprivacy/logic/models/server_logs.dart';
|
||||
|
||||
|
@ -74,6 +76,8 @@ class ServerLogsBloc extends Bloc<ServerLogsEvent, ServerLogsState> {
|
|||
});
|
||||
}
|
||||
|
||||
static const String logsSupportedVersion = '>=3.3.0';
|
||||
|
||||
Future<(List<ServerLogEntry>, ServerLogsPageMeta)> _getLogs({
|
||||
// No more than 50
|
||||
required final int limit,
|
||||
|
@ -82,12 +86,29 @@ class ServerLogsBloc extends Bloc<ServerLogsEvent, ServerLogsState> {
|
|||
// All entries returned will be greater than this cursor. Sets lower bound on results.
|
||||
final String? downCursor,
|
||||
// Only one cursor can be set at a time.
|
||||
}) =>
|
||||
getIt<ApiConnectionRepository>().api.getServerLogs(
|
||||
limit: limit,
|
||||
upCursor: upCursor,
|
||||
downCursor: downCursor,
|
||||
);
|
||||
}) {
|
||||
final String? apiVersion =
|
||||
getIt<ApiConnectionRepository>().apiData.apiVersion.data;
|
||||
if (apiVersion == null) {
|
||||
throw Exception('basis.network_error'.tr());
|
||||
}
|
||||
if (!VersionConstraint.parse(logsSupportedVersion)
|
||||
.allows(Version.parse(apiVersion))) {
|
||||
throw Exception(
|
||||
'basis.feature_unsupported_on_api_version'.tr(
|
||||
namedArgs: {
|
||||
'versionConstraint': logsSupportedVersion,
|
||||
'currentVersion': apiVersion,
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
return getIt<ApiConnectionRepository>().api.getServerLogs(
|
||||
limit: limit,
|
||||
upCursor: upCursor,
|
||||
downCursor: downCursor,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> close() {
|
||||
|
|
|
@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:selfprivacy/logic/bloc/server_logs/server_logs_bloc.dart';
|
||||
import 'package:selfprivacy/logic/models/server_logs.dart';
|
||||
import 'package:selfprivacy/ui/helpers/empty_page_placeholder.dart';
|
||||
import 'package:selfprivacy/utils/platform_adapter.dart';
|
||||
|
||||
@RoutePage()
|
||||
|
@ -86,7 +87,8 @@ class _ServerLogsScreenState extends State<ServerLogsScreen> {
|
|||
if (state is ServerLogsLoaded) {
|
||||
return _buildDrawer(state.systemdUnits);
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
// Return an empty drawer if the state is not loaded
|
||||
return const Drawer(child: SizedBox());
|
||||
},
|
||||
),
|
||||
body: BlocBuilder<ServerLogsBloc, ServerLogsState>(
|
||||
|
@ -130,7 +132,11 @@ class _ServerLogsScreenState extends State<ServerLogsScreen> {
|
|||
);
|
||||
}
|
||||
} else if (state is ServerLogsError) {
|
||||
return Center(child: Text('Error: ${state.error}'));
|
||||
return EmptyPagePlaceholder(
|
||||
title: 'basis.error'.tr(),
|
||||
iconData: Icons.error_outline,
|
||||
description: state.error.toString(),
|
||||
);
|
||||
}
|
||||
return Center(child: Text('server.no_logs'.tr()));
|
||||
},
|
||||
|
@ -240,13 +246,19 @@ class ServerLogEntryDialog extends StatelessWidget {
|
|||
_KeyValueRow('server.log_dialog.cursor'.tr(), log.cursor),
|
||||
if (log.priority != null)
|
||||
_KeyValueRow(
|
||||
'server.log_dialog.priority'.tr(), log.priority?.toString()),
|
||||
'server.log_dialog.priority'.tr(),
|
||||
log.priority?.toString(),
|
||||
),
|
||||
if (log.systemdSlice != null)
|
||||
_KeyValueRow(
|
||||
'server.log_dialog.systemd_slice'.tr(), log.systemdSlice),
|
||||
'server.log_dialog.systemd_slice'.tr(),
|
||||
log.systemdSlice,
|
||||
),
|
||||
if (log.systemdUnit != null)
|
||||
_KeyValueRow(
|
||||
'server.log_dialog.systemd_unit'.tr(), log.systemdUnit),
|
||||
'server.log_dialog.systemd_unit'.tr(),
|
||||
log.systemdUnit,
|
||||
),
|
||||
const Divider(),
|
||||
_SectionRow('server.log_dialog.message'.tr()),
|
||||
_DataRow(log.message),
|
||||
|
|
Loading…
Reference in a new issue