mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 23:34:24 +01:00
opt: check private key size
This commit is contained in:
@@ -6,6 +6,8 @@ import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:toolbox/core/extension/numx.dart';
|
||||
import 'package:toolbox/data/res/misc.dart';
|
||||
|
||||
import '../../../core/utils/ui.dart';
|
||||
import '../../../data/model/server/private_key_info.dart';
|
||||
@@ -111,6 +113,20 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage>
|
||||
showSnackBar(context, Text(_s.fileNotExist(path)));
|
||||
return;
|
||||
}
|
||||
final size = (await file.stat()).size;
|
||||
if (size > privateKeyMaxSize) {
|
||||
showSnackBar(
|
||||
context,
|
||||
Text(
|
||||
_s.fileTooLarge(
|
||||
path,
|
||||
size.convertBytes,
|
||||
privateKeyMaxSize.convertBytes,
|
||||
),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
_keyController.text = await file.readAsString();
|
||||
},
|
||||
|
||||
@@ -63,35 +63,38 @@ class _ServerPageState extends State<ServerPage>
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
final child = Consumer<ServerProvider>(
|
||||
builder: (_, pro, __) {
|
||||
if (pro.servers.isEmpty) {
|
||||
return Center(
|
||||
child: Text(
|
||||
_s.serverTabEmpty,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
);
|
||||
}
|
||||
return ListView.separated(
|
||||
padding: const EdgeInsets.all(7),
|
||||
controller: ScrollController(),
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
itemBuilder: (ctx, idx) {
|
||||
if (idx == pro.servers.length) {
|
||||
return SizedBox(height: _media.padding.bottom);
|
||||
}
|
||||
return _buildEachServerCard(pro.servers[idx]);
|
||||
},
|
||||
itemCount: pro.servers.length + 1,
|
||||
separatorBuilder: (_, __) => const SizedBox(
|
||||
height: 3,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
return Scaffold(
|
||||
body: RefreshIndicator(child: child, onRefresh: () async => await _serverProvider.refreshData(onlyFailed: true)),
|
||||
body: RefreshIndicator(
|
||||
onRefresh: () async =>
|
||||
await _serverProvider.refreshData(onlyFailed: true),
|
||||
child: Consumer<ServerProvider>(
|
||||
builder: (_, pro, __) {
|
||||
if (pro.servers.isEmpty) {
|
||||
return Center(
|
||||
child: Text(
|
||||
_s.serverTabEmpty,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
);
|
||||
}
|
||||
return ListView.separated(
|
||||
padding: const EdgeInsets.all(7),
|
||||
controller: ScrollController(),
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
itemBuilder: (ctx, idx) {
|
||||
if (idx == pro.servers.length) {
|
||||
return SizedBox(height: _media.padding.bottom);
|
||||
}
|
||||
return _buildEachServerCard(pro.servers[idx]);
|
||||
},
|
||||
itemCount: pro.servers.length + 1,
|
||||
separatorBuilder: (_, __) => const SizedBox(
|
||||
height: 3,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () => AppRoute(
|
||||
const ServerEditPage(),
|
||||
|
||||
Reference in New Issue
Block a user