mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
#78 opt.: alter url
This commit is contained in:
@@ -146,11 +146,11 @@ abstract class S {
|
||||
/// **'Already in last directory.'**
|
||||
String get alreadyLastDir;
|
||||
|
||||
/// No description provided for @alterHost.
|
||||
/// No description provided for @alterUrl.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Alter host'**
|
||||
String get alterHost;
|
||||
/// **'Alter url'**
|
||||
String get alterUrl;
|
||||
|
||||
/// No description provided for @attention.
|
||||
///
|
||||
|
||||
@@ -29,7 +29,7 @@ class SDe extends S {
|
||||
String get alreadyLastDir => 'Bereits im letzten Verzeichnis.';
|
||||
|
||||
@override
|
||||
String get alterHost => 'Alternative Gastgeber';
|
||||
String get alterUrl => 'Url ändern';
|
||||
|
||||
@override
|
||||
String get attention => 'Achtung';
|
||||
|
||||
@@ -29,7 +29,7 @@ class SEn extends S {
|
||||
String get alreadyLastDir => 'Already in last directory.';
|
||||
|
||||
@override
|
||||
String get alterHost => 'Alter host';
|
||||
String get alterUrl => 'Alter url';
|
||||
|
||||
@override
|
||||
String get attention => 'Attention';
|
||||
|
||||
@@ -29,7 +29,7 @@ class SId extends S {
|
||||
String get alreadyLastDir => 'Sudah di direktori terakhir.';
|
||||
|
||||
@override
|
||||
String get alterHost => 'Alter host';
|
||||
String get alterUrl => 'Alter url';
|
||||
|
||||
@override
|
||||
String get attention => 'Perhatian';
|
||||
|
||||
@@ -29,7 +29,7 @@ class SZh extends S {
|
||||
String get alreadyLastDir => '已经是最上层目录了';
|
||||
|
||||
@override
|
||||
String get alterHost => '备选主机';
|
||||
String get alterUrl => '备选链接';
|
||||
|
||||
@override
|
||||
String get attention => '注意';
|
||||
@@ -711,7 +711,7 @@ class SZhTw extends SZh {
|
||||
String get alreadyLastDir => '已經是最上層目錄了';
|
||||
|
||||
@override
|
||||
String get alterHost => '備選主機';
|
||||
String get alterUrl => '備選鏈接';
|
||||
|
||||
@override
|
||||
String get attention => '注意';
|
||||
|
||||
@@ -57,16 +57,14 @@ Future<SSHClient> genClient(
|
||||
);
|
||||
} catch (e) {
|
||||
try {
|
||||
spi.fromStringUrl();
|
||||
socket = await SSHSocket.connect(
|
||||
spi.alterHost!,
|
||||
spi.ip,
|
||||
spi.port,
|
||||
timeout: const Duration(seconds: 5),
|
||||
);
|
||||
} catch (e) {
|
||||
throw SSHErr(
|
||||
type: SSHErrType.connect,
|
||||
message: e.toString(),
|
||||
);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
|
||||
import '../app/error.dart';
|
||||
|
||||
part 'server_private_info.g.dart';
|
||||
|
||||
@HiveType(typeId: 3)
|
||||
@@ -19,7 +21,7 @@ class ServerPrivateInfo {
|
||||
@HiveField(6)
|
||||
List<String>? tags;
|
||||
@HiveField(7)
|
||||
String? alterHost;
|
||||
String? alterUrl;
|
||||
|
||||
late String id;
|
||||
|
||||
@@ -31,7 +33,7 @@ class ServerPrivateInfo {
|
||||
required this.pwd,
|
||||
this.pubKeyId,
|
||||
this.tags,
|
||||
this.alterHost,
|
||||
this.alterUrl,
|
||||
}) : id = '$user@$ip:$port';
|
||||
|
||||
ServerPrivateInfo.fromJson(Map<String, dynamic> json) {
|
||||
@@ -43,7 +45,7 @@ class ServerPrivateInfo {
|
||||
pubKeyId = json["pubKeyId"]?.toString();
|
||||
id = '$user@$ip:$port';
|
||||
tags = json["tags"]?.cast<String>();
|
||||
alterHost = json["alterHost"]?.toString();
|
||||
alterUrl = json["alterHost"]?.toString();
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
@@ -55,7 +57,7 @@ class ServerPrivateInfo {
|
||||
data["authorization"] = pwd;
|
||||
data["pubKeyId"] = pubKeyId;
|
||||
data["tags"] = tags;
|
||||
data["alterHost"] = alterHost;
|
||||
data["alterHost"] = alterUrl;
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -63,7 +65,31 @@ class ServerPrivateInfo {
|
||||
return id != old.id ||
|
||||
pwd != old.pwd ||
|
||||
pubKeyId != old.pubKeyId ||
|
||||
alterHost != old.alterHost;
|
||||
alterUrl != old.alterUrl;
|
||||
}
|
||||
|
||||
void fromStringUrl() {
|
||||
if (alterUrl == null) {
|
||||
throw SSHErr(type: SSHErrType.connect, message: 'alterUrl is null');
|
||||
}
|
||||
final splited = alterUrl!.split('@');
|
||||
if (splited.length != 2) {
|
||||
throw SSHErr(type: SSHErrType.connect, message: 'alterUrl no @');
|
||||
}
|
||||
user = splited[0];
|
||||
final splited2 = splited[1].split(':');
|
||||
if (splited2.length != 2) {
|
||||
throw SSHErr(type: SSHErrType.connect, message: 'alterUrl no :');
|
||||
}
|
||||
ip = splited2[0];
|
||||
port = int.tryParse(splited2[1]) ?? 22;
|
||||
if (port <= 0 || port > 65535) {
|
||||
throw SSHErr(type: SSHErrType.connect, message: 'alterUrl port error');
|
||||
}
|
||||
|
||||
// Do not update [id]
|
||||
// Because [id] is the identity which is used to find the [SSHClient]
|
||||
// id = '$user@$ip:$port';
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -24,7 +24,7 @@ class ServerPrivateInfoAdapter extends TypeAdapter<ServerPrivateInfo> {
|
||||
pwd: fields[4] as String,
|
||||
pubKeyId: fields[5] as String?,
|
||||
tags: (fields[6] as List?)?.cast<String>(),
|
||||
alterHost: fields[7] as String?,
|
||||
alterUrl: fields[7] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ class ServerPrivateInfoAdapter extends TypeAdapter<ServerPrivateInfo> {
|
||||
..writeByte(6)
|
||||
..write(obj.tags)
|
||||
..writeByte(7)
|
||||
..write(obj.alterHost);
|
||||
..write(obj.alterUrl);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"added2List": "Zur Aufgabenliste hinzugefügt",
|
||||
"all": "Alle",
|
||||
"alreadyLastDir": "Bereits im letzten Verzeichnis.",
|
||||
"alterHost": "Alternative Gastgeber",
|
||||
"alterUrl": "Url ändern",
|
||||
"attention": "Achtung",
|
||||
"auto": "System folgen",
|
||||
"autoUpdateHomeWidget": "Home-Widget automatisch aktualisieren",
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"added2List": "Added to task list",
|
||||
"all": "All",
|
||||
"alreadyLastDir": "Already in last directory.",
|
||||
"alterHost": "Alter host",
|
||||
"alterUrl": "Alter url",
|
||||
"attention": "Attention",
|
||||
"auto": "Auto",
|
||||
"autoUpdateHomeWidget": "Auto update home widget",
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"added2List": "Ditambahkan ke Daftar Tugas",
|
||||
"all": "Semua",
|
||||
"alreadyLastDir": "Sudah di direktori terakhir.",
|
||||
"alterHost": "Alter host",
|
||||
"alterUrl": "Alter url",
|
||||
"attention": "Perhatian",
|
||||
"auto": "Auto",
|
||||
"autoUpdateHomeWidget": "Widget Rumah Pembaruan Otomatis",
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"added2List": "已添加至任务列表",
|
||||
"all": "所有",
|
||||
"alreadyLastDir": "已经是最上层目录了",
|
||||
"alterHost": "备选主机",
|
||||
"alterUrl": "备选链接",
|
||||
"attention": "注意",
|
||||
"auto": "自动",
|
||||
"autoUpdateHomeWidget": "自动更新桌面小部件",
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"added2List": "已添加至任務列表",
|
||||
"all": "所有",
|
||||
"alreadyLastDir": "已經是最上層目錄了",
|
||||
"alterHost": "備選主機",
|
||||
"alterUrl": "備選鏈接",
|
||||
"attention": "注意",
|
||||
"auto": "自動",
|
||||
"autoUpdateHomeWidget": "自動更新桌面小部件",
|
||||
|
||||
@@ -30,13 +30,13 @@ class ServerEditPage extends StatefulWidget {
|
||||
class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
final _nameController = TextEditingController();
|
||||
final _ipController = TextEditingController();
|
||||
final _alterHostController = TextEditingController();
|
||||
final _alterUrlController = TextEditingController();
|
||||
final _portController = TextEditingController();
|
||||
final _usernameController = TextEditingController();
|
||||
final _passwordController = TextEditingController();
|
||||
final _nameFocus = FocusNode();
|
||||
final _ipFocus = FocusNode();
|
||||
final _alterHostFocus = FocusNode();
|
||||
final _alterUrlFocus = FocusNode();
|
||||
final _portFocus = FocusNode();
|
||||
final _usernameFocus = FocusNode();
|
||||
|
||||
@@ -120,20 +120,12 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
Input(
|
||||
controller: _ipController,
|
||||
type: TextInputType.text,
|
||||
onSubmitted: (_) => _focusScope.requestFocus(_alterHostFocus),
|
||||
onSubmitted: (_) => _focusScope.requestFocus(_portFocus),
|
||||
node: _ipFocus,
|
||||
label: _s.host,
|
||||
icon: Icons.computer,
|
||||
hint: 'example.com',
|
||||
),
|
||||
Input(
|
||||
controller: _alterHostController,
|
||||
type: TextInputType.text,
|
||||
node: _alterHostFocus,
|
||||
onSubmitted: (_) => _focusScope.requestFocus(_portFocus),
|
||||
label: _s.alterHost,
|
||||
icon: Icons.computer,
|
||||
),
|
||||
Input(
|
||||
controller: _portController,
|
||||
type: TextInputType.number,
|
||||
@@ -147,10 +139,19 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
controller: _usernameController,
|
||||
type: TextInputType.text,
|
||||
node: _usernameFocus,
|
||||
onSubmitted: (_) => _focusScope.requestFocus(_alterUrlFocus),
|
||||
label: _s.user,
|
||||
icon: Icons.account_box,
|
||||
hint: 'root',
|
||||
),
|
||||
Input(
|
||||
controller: _alterUrlController,
|
||||
type: TextInputType.text,
|
||||
node: _alterUrlFocus,
|
||||
label: _s.alterUrl,
|
||||
icon: Icons.computer,
|
||||
hint: 'user@ip:port',
|
||||
),
|
||||
TagEditor(
|
||||
tags: _tags,
|
||||
onChanged: (p0) => setState(() {
|
||||
@@ -290,9 +291,9 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
pwd: authorization,
|
||||
pubKeyId: usePublicKey ? _keyInfo!.id : null,
|
||||
tags: _tags,
|
||||
alterHost: _alterHostController.text == ''
|
||||
alterUrl: _alterUrlController.text == ''
|
||||
? null
|
||||
: _alterHostController.text,
|
||||
: _alterUrlController.text,
|
||||
);
|
||||
|
||||
if (widget.spi == null) {
|
||||
@@ -334,7 +335,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
if (widget.spi?.tags != null) {
|
||||
_tags = widget.spi!.tags!;
|
||||
}
|
||||
_alterHostController.text = widget.spi?.alterHost ?? '';
|
||||
_alterUrlController.text = widget.spi?.alterUrl ?? '';
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user