mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
feat: import servers from ~/.ssh/config (#873)
This commit is contained in:
@@ -56,6 +56,7 @@ abstract class Spi with _$Spi {
|
||||
@override
|
||||
String toString() => 'Spi<$oldId>';
|
||||
|
||||
/// Parse the [id], if it's null or empty, generate a new one.
|
||||
static String parseId(Object? id) {
|
||||
if (id == null || id is! String || id.isEmpty) return ShortId.generate();
|
||||
return id;
|
||||
@@ -83,20 +84,26 @@ extension Spix on Spi {
|
||||
return newSpi.id;
|
||||
}
|
||||
|
||||
/// Json encode to string.
|
||||
String toJsonString() => json.encode(toJson());
|
||||
|
||||
bool shouldReconnect(Spi old) {
|
||||
return user != old.user ||
|
||||
ip != old.ip ||
|
||||
port != old.port ||
|
||||
pwd != old.pwd ||
|
||||
keyId != old.keyId ||
|
||||
alterUrl != old.alterUrl ||
|
||||
jumpId != old.jumpId ||
|
||||
custom?.cmds != old.custom?.cmds;
|
||||
/// Returns true if the connection info is the same as [other].
|
||||
bool isSameAs(Spi other) {
|
||||
return user == other.user &&
|
||||
ip == other.ip &&
|
||||
port == other.port &&
|
||||
pwd == other.pwd &&
|
||||
keyId == other.keyId &&
|
||||
jumpId == other.jumpId;
|
||||
}
|
||||
|
||||
(String ip, String usr, int port) fromStringUrl() {
|
||||
/// Returns true if the connection should be re-established.
|
||||
bool shouldReconnect(Spi old) {
|
||||
return !isSameAs(old) || alterUrl != old.alterUrl || custom?.cmds != old.custom?.cmds;
|
||||
}
|
||||
|
||||
/// Parse the [alterUrl] to (ip, user, port).
|
||||
(String ip, String usr, int port) parseAlterUrl() {
|
||||
if (alterUrl == null) {
|
||||
throw SSHErr(type: SSHErrType.connect, message: 'alterUrl is null');
|
||||
}
|
||||
@@ -141,5 +148,6 @@ extension Spix on Spi {
|
||||
id: 'id',
|
||||
);
|
||||
|
||||
/// Returns true if the user is 'root'.
|
||||
bool get isRoot => user == 'root';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user