new: server tag

This commit is contained in:
lollipopkit
2023-05-30 22:44:45 +08:00
parent 92ffed6541
commit 472a441c8e
23 changed files with 239 additions and 112 deletions

View File

@@ -16,6 +16,8 @@ class ServerPrivateInfo {
late String pwd;
@HiveField(5)
String? pubKeyId;
@HiveField(6)
List<String>? tags;
late String id;
@@ -26,6 +28,7 @@ class ServerPrivateInfo {
required this.user,
required this.pwd,
this.pubKeyId,
this.tags,
}) : id = '$user@$ip:$port';
ServerPrivateInfo.fromJson(Map<String, dynamic> json) {
@@ -36,6 +39,7 @@ class ServerPrivateInfo {
pwd = json["authorization"].toString();
pubKeyId = json["pubKeyId"]?.toString();
id = '$user@$ip:$port';
tags = json["tags"]?.cast<String>();
}
Map<String, dynamic> toJson() {
@@ -46,6 +50,11 @@ class ServerPrivateInfo {
data["user"] = user;
data["authorization"] = pwd;
data["pubKeyId"] = pubKeyId;
data["tags"] = tags;
return data;
}
bool shouldReconnect(ServerPrivateInfo old) {
return id != id || pwd != old.pwd || pubKeyId != old.pubKeyId;
}
}

View File

@@ -23,13 +23,14 @@ class ServerPrivateInfoAdapter extends TypeAdapter<ServerPrivateInfo> {
user: fields[3] as String,
pwd: fields[4] as String,
pubKeyId: fields[5] as String?,
tags: (fields[6] as List?)?.cast<String>(),
);
}
@override
void write(BinaryWriter writer, ServerPrivateInfo obj) {
writer
..writeByte(6)
..writeByte(7)
..writeByte(0)
..write(obj.name)
..writeByte(1)
@@ -41,7 +42,9 @@ class ServerPrivateInfoAdapter extends TypeAdapter<ServerPrivateInfo> {
..writeByte(4)
..write(obj.pwd)
..writeByte(5)
..write(obj.pubKeyId);
..write(obj.pubKeyId)
..writeByte(6)
..write(obj.tags);
}
@override

View File

@@ -8,20 +8,16 @@ class Snippet {
late String name;
@HiveField(1)
late String script;
@HiveField(2)
List<String>? tags;
Snippet(this.name, this.script, {this.tags});
Snippet(this.name, this.script);
Snippet.fromJson(Map<String, dynamic> json) {
name = json['name'].toString();
script = json['script'].toString();
tags = json['tags'].cast<String>();
}
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};
data['name'] = name;
data['script'] = script;
data['tags'] = tags;
return data;
}
}

View File

@@ -19,20 +19,17 @@ class SnippetAdapter extends TypeAdapter<Snippet> {
return Snippet(
fields[0] as String,
fields[1] as String,
tags: (fields[2] as List?)?.cast<String>(),
);
}
@override
void write(BinaryWriter writer, Snippet obj) {
writer
..writeByte(3)
..writeByte(2)
..writeByte(0)
..write(obj.name)
..writeByte(1)
..write(obj.script)
..writeByte(2)
..write(obj.tags);
..write(obj.script);
}
@override