mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-18 07:44:26 +01:00
new: snippet fmt
This commit is contained in:
@@ -46,7 +46,8 @@ enum ContainerErrType {
|
||||
}
|
||||
|
||||
class ContainerErr extends Err<ContainerErrType> {
|
||||
ContainerErr({required super.type, super.message}) : super(from: ErrFrom.docker);
|
||||
ContainerErr({required super.type, super.message})
|
||||
: super(from: ErrFrom.docker);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
|
||||
18
lib/data/model/app/menu/base.dart
Normal file
18
lib/data/model/app/menu/base.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
abstract class PopMenu {
|
||||
static PopupMenuItem<T> build<T>(T t, IconData icon, String text) {
|
||||
return PopupMenuItem<T>(
|
||||
value: t,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Text(text),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,49 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:toolbox/core/extension/context/locale.dart';
|
||||
|
||||
enum ServerTabMenu {
|
||||
terminal,
|
||||
sftp,
|
||||
container,
|
||||
process,
|
||||
pkg,
|
||||
//snippet,
|
||||
;
|
||||
|
||||
IconData get icon {
|
||||
switch (this) {
|
||||
case ServerTabMenu.sftp:
|
||||
return Icons.insert_drive_file;
|
||||
//case ServerTabMenuType.snippet:
|
||||
//return Icons.code;
|
||||
case ServerTabMenu.pkg:
|
||||
return Icons.system_security_update;
|
||||
case ServerTabMenu.container:
|
||||
return Icons.view_agenda;
|
||||
case ServerTabMenu.process:
|
||||
return Icons.list_alt_outlined;
|
||||
case ServerTabMenu.terminal:
|
||||
return Icons.terminal;
|
||||
}
|
||||
}
|
||||
|
||||
String get toStr {
|
||||
switch (this) {
|
||||
case ServerTabMenu.sftp:
|
||||
return 'SFTP';
|
||||
//case ServerTabMenuType.snippet:
|
||||
//return l10n.snippet;
|
||||
case ServerTabMenu.pkg:
|
||||
return l10n.pkg;
|
||||
case ServerTabMenu.container:
|
||||
return l10n.container;
|
||||
case ServerTabMenu.process:
|
||||
return l10n.process;
|
||||
case ServerTabMenu.terminal:
|
||||
return l10n.terminal;
|
||||
}
|
||||
}
|
||||
}
|
||||
import 'package:toolbox/data/model/app/menu/base.dart';
|
||||
|
||||
enum ContainerMenu {
|
||||
start,
|
||||
@@ -108,20 +65,9 @@ enum ContainerMenu {
|
||||
}
|
||||
}
|
||||
|
||||
PopupMenuItem<ContainerMenu> get widget => _build(this, icon, toStr);
|
||||
}
|
||||
|
||||
PopupMenuItem<T> _build<T>(T t, IconData icon, String text) {
|
||||
return PopupMenuItem<T>(
|
||||
value: t,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Text(text),
|
||||
],
|
||||
),
|
||||
);
|
||||
PopupMenuItem<ContainerMenu> get widget => PopMenu.build(
|
||||
this,
|
||||
icon,
|
||||
toStr,
|
||||
);
|
||||
}
|
||||
30
lib/data/model/app/menu/server_func.dart
Normal file
30
lib/data/model/app/menu/server_func.dart
Normal file
@@ -0,0 +1,30 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:toolbox/core/extension/context/locale.dart';
|
||||
|
||||
enum ServerTabMenu {
|
||||
terminal,
|
||||
sftp,
|
||||
container,
|
||||
process,
|
||||
pkg,
|
||||
snippet,
|
||||
;
|
||||
|
||||
IconData get icon => switch (this) {
|
||||
ServerTabMenu.sftp => Icons.insert_drive_file,
|
||||
ServerTabMenu.snippet => Icons.code,
|
||||
ServerTabMenu.pkg => Icons.system_security_update,
|
||||
ServerTabMenu.container => Icons.view_agenda,
|
||||
ServerTabMenu.process => Icons.list_alt_outlined,
|
||||
ServerTabMenu.terminal => Icons.terminal,
|
||||
};
|
||||
|
||||
String get toStr => switch (this) {
|
||||
ServerTabMenu.sftp => 'SFTP',
|
||||
ServerTabMenu.snippet => l10n.snippet,
|
||||
ServerTabMenu.pkg => l10n.pkg,
|
||||
ServerTabMenu.container => l10n.container,
|
||||
ServerTabMenu.process => l10n.process,
|
||||
ServerTabMenu.terminal => l10n.terminal,
|
||||
};
|
||||
}
|
||||
@@ -15,4 +15,4 @@ enum ContainerType {
|
||||
ContainerType.docker => DockerImg.fromRawJson,
|
||||
ContainerType.podman => PodmanImg.fromRawJson,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,51 +1,54 @@
|
||||
import 'dart:convert';
|
||||
|
||||
class Containerd {
|
||||
final ContainerdClient client;
|
||||
final ContainerdClient client;
|
||||
|
||||
Containerd({
|
||||
required this.client,
|
||||
});
|
||||
Containerd({
|
||||
required this.client,
|
||||
});
|
||||
|
||||
factory Containerd.fromRawJson(String str) => Containerd.fromJson(json.decode(str));
|
||||
factory Containerd.fromRawJson(String str) =>
|
||||
Containerd.fromJson(json.decode(str));
|
||||
|
||||
String toRawJson() => json.encode(toJson());
|
||||
String toRawJson() => json.encode(toJson());
|
||||
|
||||
factory Containerd.fromJson(Map<String, dynamic> json) => Containerd(
|
||||
factory Containerd.fromJson(Map<String, dynamic> json) => Containerd(
|
||||
client: ContainerdClient.fromJson(json["Client"]),
|
||||
);
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
Map<String, dynamic> toJson() => {
|
||||
"Client": client.toJson(),
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
class ContainerdClient {
|
||||
final String apiVersion;
|
||||
final String version;
|
||||
final String goVersion;
|
||||
final String gitCommit;
|
||||
final String builtTime;
|
||||
final int built;
|
||||
final String osArch;
|
||||
final String os;
|
||||
final String apiVersion;
|
||||
final String version;
|
||||
final String goVersion;
|
||||
final String gitCommit;
|
||||
final String builtTime;
|
||||
final int built;
|
||||
final String osArch;
|
||||
final String os;
|
||||
|
||||
ContainerdClient({
|
||||
required this.apiVersion,
|
||||
required this.version,
|
||||
required this.goVersion,
|
||||
required this.gitCommit,
|
||||
required this.builtTime,
|
||||
required this.built,
|
||||
required this.osArch,
|
||||
required this.os,
|
||||
});
|
||||
ContainerdClient({
|
||||
required this.apiVersion,
|
||||
required this.version,
|
||||
required this.goVersion,
|
||||
required this.gitCommit,
|
||||
required this.builtTime,
|
||||
required this.built,
|
||||
required this.osArch,
|
||||
required this.os,
|
||||
});
|
||||
|
||||
factory ContainerdClient.fromRawJson(String str) => ContainerdClient.fromJson(json.decode(str));
|
||||
factory ContainerdClient.fromRawJson(String str) =>
|
||||
ContainerdClient.fromJson(json.decode(str));
|
||||
|
||||
String toRawJson() => json.encode(toJson());
|
||||
String toRawJson() => json.encode(toJson());
|
||||
|
||||
factory ContainerdClient.fromJson(Map<String, dynamic> json) => ContainerdClient(
|
||||
factory ContainerdClient.fromJson(Map<String, dynamic> json) =>
|
||||
ContainerdClient(
|
||||
apiVersion: json["APIVersion"],
|
||||
version: json["Version"],
|
||||
goVersion: json["GoVersion"],
|
||||
@@ -54,9 +57,9 @@ class ContainerdClient {
|
||||
built: json["Built"],
|
||||
osArch: json["OsArch"],
|
||||
os: json["Os"],
|
||||
);
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
Map<String, dynamic> toJson() => {
|
||||
"APIVersion": apiVersion,
|
||||
"Version": version,
|
||||
"GoVersion": goVersion,
|
||||
@@ -65,5 +68,5 @@ class ContainerdClient {
|
||||
"Built": built,
|
||||
"OsArch": osArch,
|
||||
"Os": os,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import 'package:toolbox/data/model/server/server_private_info.dart';
|
||||
|
||||
import '../app/tag_pickable.dart';
|
||||
|
||||
@@ -44,6 +45,30 @@ class Snippet implements TagPickable {
|
||||
|
||||
@override
|
||||
String get tagName => name;
|
||||
|
||||
String fmtWith(ServerPrivateInfo spi) {
|
||||
final fmted = script.replaceAllMapped(
|
||||
RegExp(r'\${.+?}'),
|
||||
(match) {
|
||||
final key = match.group(0);
|
||||
final func = fmtArgs[key];
|
||||
if (func == null) {
|
||||
return key!;
|
||||
}
|
||||
return func(spi);
|
||||
},
|
||||
);
|
||||
return fmted;
|
||||
}
|
||||
|
||||
static final fmtArgs = {
|
||||
r'${host}': (ServerPrivateInfo spi) => spi.ip,
|
||||
r'${port}': (ServerPrivateInfo spi) => spi.port.toString(),
|
||||
r'${user}': (ServerPrivateInfo spi) => spi.user,
|
||||
r'${pwd}': (ServerPrivateInfo spi) => spi.pwd ?? '',
|
||||
r'${id}': (ServerPrivateInfo spi) => spi.id,
|
||||
r'${name}': (ServerPrivateInfo spi) => spi.name,
|
||||
};
|
||||
}
|
||||
|
||||
class SnippetResult {
|
||||
|
||||
@@ -393,15 +393,14 @@ class ServerProvider extends ChangeNotifier {
|
||||
TryLimiter.reset(sid);
|
||||
}
|
||||
|
||||
Future<SnippetResult?> runSnippets(String id, Snippet snippet) async {
|
||||
final client = _servers[id]?.client;
|
||||
if (client == null) {
|
||||
return null;
|
||||
}
|
||||
Future<SnippetResult?> runSnippet(String id, Snippet snippet) async {
|
||||
final server = _servers[id];
|
||||
if (server == null) return null;
|
||||
final watch = Stopwatch()..start();
|
||||
final result = await client.run(snippet.script).string;
|
||||
final result = await server.client?.run(snippet.fmtWith(server.spi)).string;
|
||||
final time = watch.elapsed;
|
||||
watch.stop();
|
||||
if (result == null) return null;
|
||||
return SnippetResult(
|
||||
dest: _servers[id]?.spi.name,
|
||||
result: result,
|
||||
@@ -409,10 +408,10 @@ class ServerProvider extends ChangeNotifier {
|
||||
);
|
||||
}
|
||||
|
||||
Future<List<SnippetResult?>> runSnippetsMulti(
|
||||
List<String> ids,
|
||||
Snippet snippet,
|
||||
) async {
|
||||
return await Future.wait(ids.map((id) async => runSnippets(id, snippet)));
|
||||
}
|
||||
// Future<List<SnippetResult?>> runSnippetsMulti(
|
||||
// List<String> ids,
|
||||
// Snippet snippet,
|
||||
// ) async {
|
||||
// return await Future.wait(ids.map((id) async => runSnippet(id, snippet)));
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
class BuildData {
|
||||
static const String name = "ServerBox";
|
||||
static const int build = 709;
|
||||
static const int build = 712;
|
||||
static const String engine = "3.16.7";
|
||||
static const String buildAt = "2024-01-19 17:32:15";
|
||||
static const int modifications = 2;
|
||||
static const int script = 34;
|
||||
static const String buildAt = "2024-01-21 15:41:48";
|
||||
static const int modifications = 5;
|
||||
static const int script = 35;
|
||||
}
|
||||
|
||||
@@ -52,5 +52,6 @@ abstract final class GithubIds {
|
||||
'luckyreny',
|
||||
'aliuzzz',
|
||||
'58fly',
|
||||
'Potterli20',
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user