Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opt.: sftp home & back #533

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@ linter:
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
library_private_types_in_public_api: false
library_private_types_in_public_api: true
use_build_context_synchronously: false
depend_on_referenced_packages: false
prefer_final_locals: true
unnecessary_parenthesis: true
implicit_call_tearoffs: true
always_declare_return_types: true
always_use_package_imports: true
annotate_overrides: true
avoid_empty_else: true
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
avoid_return_types_on_setters: true

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
22 changes: 11 additions & 11 deletions lib/core/extension/ssh_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ import 'package:dartssh2/dartssh2.dart';
import 'package:fl_lib/fl_lib.dart';
import 'package:flutter/widgets.dart';

import '../../data/res/misc.dart';
import 'package:server_box/data/res/misc.dart';

typedef _OnStdout = void Function(String data, SSHSession session);
typedef _OnStdin = void Function(SSHSession session);
typedef OnStdout = void Function(String data, SSHSession session);
typedef OnStdin = void Function(SSHSession session);

typedef PwdRequestFunc = Future<String?> Function(String? user);

extension SSHClientX on SSHClient {
/// TODO: delete [exec]
Future<SSHSession> exec(
String cmd, {
_OnStdout? onStderr,
_OnStdout? onStdout,
_OnStdin? stdin,
OnStdout? onStderr,
OnStdout? onStdout,
OnStdin? stdin,
bool redirectToBash = false, // not working yet. do not use
}) async {
final session = await execute(redirectToBash ? "head -1 | bash" : cmd);
final session = await execute(redirectToBash ? 'head -1 | bash' : cmd);

if (redirectToBash) {
session.stdin.add("$cmd\n".uint8List);
session.stdin.add('$cmd\n'.uint8List);
}

final stdoutDone = Completer<void>();
Expand Down Expand Up @@ -62,9 +62,9 @@ extension SSHClientX on SSHClient {
Future<int?> execWithPwd(
String cmd, {
BuildContext? context,
_OnStdout? onStdout,
_OnStdout? onStderr,
_OnStdin? stdin,
OnStdout? onStdout,
OnStdout? onStderr,
OnStdin? stdin,
bool redirectToBash = false, // not working yet. do not use
required String id,
}) async {
Expand Down
24 changes: 12 additions & 12 deletions lib/core/route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ import 'package:server_box/view/page/ssh/page.dart';
import 'package:server_box/view/page/setting/seq/virt_key.dart';
import 'package:server_box/view/page/storage/local.dart';

import '../data/model/server/snippet.dart';
import '../view/page/editor.dart';
import '../view/page/process.dart';
import '../view/page/server/edit.dart';
import '../view/page/server/tab.dart';
import '../view/page/setting/entry.dart';
import '../view/page/setting/seq/srv_detail_seq.dart';
import '../view/page/setting/seq/srv_seq.dart';
import '../view/page/snippet/edit.dart';
import '../view/page/snippet/list.dart';
import '../view/page/storage/sftp.dart';
import '../view/page/storage/sftp_mission.dart';
import 'package:server_box/data/model/server/snippet.dart';
import 'package:server_box/view/page/editor.dart';
import 'package:server_box/view/page/process.dart';
import 'package:server_box/view/page/server/edit.dart';
import 'package:server_box/view/page/server/tab.dart';
import 'package:server_box/view/page/setting/entry.dart';
import 'package:server_box/view/page/setting/seq/srv_detail_seq.dart';
import 'package:server_box/view/page/setting/seq/srv_seq.dart';
import 'package:server_box/view/page/snippet/edit.dart';
import 'package:server_box/view/page/snippet/list.dart';
import 'package:server_box/view/page/storage/sftp.dart';
import 'package:server_box/view/page/storage/sftp_mission.dart';

class AppRoutes {
final Widget page;
Expand Down
2 changes: 1 addition & 1 deletion lib/core/utils/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:flutter/foundation.dart';
import 'package:server_box/data/model/app/error.dart';
import 'package:server_box/data/res/store.dart';

import '../../data/model/server/server_private_info.dart';
import 'package:server_box/data/model/server/server_private_info.dart';

/// Must put this func out of any Class.
///
Expand Down
2 changes: 1 addition & 1 deletion lib/core/utils/sync/icloud.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:server_box/data/model/app/backup.dart';
import 'package:server_box/data/model/app/sync.dart';
import 'package:server_box/data/res/misc.dart';

import '../../../data/model/app/error.dart';
import 'package:server_box/data/model/app/error.dart';

abstract final class ICloud {
static const _containerId = 'iCloud.tech.lolli.serverbox';
Expand Down
8 changes: 4 additions & 4 deletions lib/data/model/app/shell_func.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:server_box/core/extension/context/locale.dart';

import '../../res/build_data.dart';
import '../server/system.dart';
import 'package:server_box/data/res/build_data.dart';
import 'package:server_box/data/model/server/system.dart';

enum ShellFunc {
status,
Expand Down Expand Up @@ -47,11 +47,11 @@ enum ShellFunc {
static String getInstallShellCmd(String id) {
final scriptDir = getScriptDir(id);
final scriptPath = '$scriptDir/$scriptFile';
return """
return '''
mkdir -p $scriptDir
cat > $scriptPath
chmod 744 $scriptPath
""";
''';
}

String get flag => switch (this) {
Expand Down
48 changes: 24 additions & 24 deletions lib/data/model/container/image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ final class PodmanImg implements ContainerImg {
String toRawJson() => json.encode(toJson());

factory PodmanImg.fromJson(Map<String, dynamic> json) => PodmanImg(
repository: json["repository"],
tag: json["tag"],
id: json["Id"],
created: json["Created"],
size: json["Size"],
containers: json["Containers"],
repository: json['repository'],
tag: json['tag'],
id: json['Id'],
created: json['Created'],
size: json['Size'],
containers: json['Containers'],
);

Map<String, dynamic> toJson() => {
"repository": repository,
"tag": tag,
"Id": id,
"Created": created,
"Size": size,
"Containers": containers,
'repository': repository,
'tag': tag,
'Id': id,
'Created': created,
'Size': size,
'Containers': containers,
};
}

Expand Down Expand Up @@ -96,36 +96,36 @@ final class DockerImg implements ContainerImg {
String toRawJson() => json.encode(toJson());

factory DockerImg.fromJson(Map<String, dynamic> json) {
final containers = switch (json["Containers"]) {
final containers = switch (json['Containers']) {
final String a => a,
final Object? a => a.toString(),
};
final repo = switch (json["Repository"] ?? json["Names"]) {
final repo = switch (json['Repository'] ?? json['Names']) {
final String a => a,
final List a => a.firstOrNull.toString(),
final Object? a => a.toString(),
};
final size = switch (json["Size"]) {
final size = switch (json['Size']) {
final String a => a,
final int a => a.bytes2Str,
final Object? a => a.toString(),
};
return DockerImg(
containers: containers,
createdAt: json["CreatedAt"],
id: json["ID"] ?? json["Id"] ?? '',
createdAt: json['CreatedAt'],
id: json['ID'] ?? json['Id'] ?? '',
repository: repo,
size: size,
tag: json["Tag"],
tag: json['Tag'],
);
}

Map<String, dynamic> toJson() => {
"Containers": containers,
"CreatedAt": createdAt,
"ID": id,
"Repository": repository,
"Size": size,
"Tag": tag,
'Containers': containers,
'CreatedAt': createdAt,
'ID': id,
'Repository': repository,
'Size': size,
'Tag': tag,
};
}
32 changes: 16 additions & 16 deletions lib/data/model/container/ps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,29 @@ final class PodmanPs implements ContainerPs {
String toRawJson() => json.encode(toJson());

factory PodmanPs.fromJson(Map<String, dynamic> json) => PodmanPs(
command: json["Command"] == null
command: json['Command'] == null
? []
: List<String>.from(json["Command"]!.map((x) => x)),
: List<String>.from(json['Command']!.map((x) => x)),
created:
json["Created"] == null ? null : DateTime.parse(json["Created"]),
exited: json["Exited"],
id: json["Id"],
image: json["Image"],
names: json["Names"] == null
json['Created'] == null ? null : DateTime.parse(json['Created']),
exited: json['Exited'],
id: json['Id'],
image: json['Image'],
names: json['Names'] == null
? []
: List<String>.from(json["Names"]!.map((x) => x)),
startedAt: json["StartedAt"],
: List<String>.from(json['Names']!.map((x) => x)),
startedAt: json['StartedAt'],
);

Map<String, dynamic> toJson() => {
"Command":
'Command':
command == null ? [] : List<dynamic>.from(command!.map((x) => x)),
"Created": created?.toIso8601String(),
"Exited": exited,
"Id": id,
"Image": image,
"Names": names == null ? [] : List<dynamic>.from(names!.map((x) => x)),
"StartedAt": startedAt,
'Created': created?.toIso8601String(),
'Exited': exited,
'Id': id,
'Image': image,
'Names': names == null ? [] : List<dynamic>.from(names!.map((x) => x)),
'StartedAt': startedAt,
};
}

Expand Down
6 changes: 3 additions & 3 deletions lib/data/model/pkg/upgrade_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class UpgradePkgInfo {
}

void _parseApt(String raw) {
final split1 = raw.split("/");
final split1 = raw.split('/');
package = split1[0];
final split2 = split1[1].split(" ");
final split2 = split1[1].split(' ');
newVersion = split2[1];
arch = split2[2];
nowVersion = split2[5].replaceFirst(']', '');
Expand All @@ -53,7 +53,7 @@ class UpgradePkgInfo {
}

void _parseZypper(String raw) {
final cols = raw.split("|");
final cols = raw.split('|');
package = cols[2].trim();
nowVersion = cols[3].trim();
newVersion = cols[4].trim();
Expand Down
2 changes: 1 addition & 1 deletion lib/data/model/server/conn.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../../res/misc.dart';
import 'package:server_box/data/res/misc.dart';

class Conn {
final int maxConn;
Expand Down
20 changes: 10 additions & 10 deletions lib/data/model/server/custom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ final class ServerCustom {

static ServerCustom fromJson(Map<String, dynamic> json) {
//final temperature = json["temperature"] as String?;
final pveAddr = json["pveAddr"] as String?;
final pveIgnoreCert = json["pveIgnoreCert"] as bool;
final cmds = json["cmds"] as Map<String, dynamic>?;
final preferTempDev = json["preferTempDev"] as String?;
final logoUrl = json["logoUrl"] as String?;
final pveAddr = json['pveAddr'] as String?;
final pveIgnoreCert = json['pveIgnoreCert'] as bool;
final cmds = json['cmds'] as Map<String, dynamic>?;
final preferTempDev = json['preferTempDev'] as String?;
final logoUrl = json['logoUrl'] as String?;
return ServerCustom(
//temperature: temperature,
pveAddr: pveAddr,
Expand All @@ -51,18 +51,18 @@ final class ServerCustom {
// json["temperature"] = temperature;
// }
if (pveAddr != null) {
json["pveAddr"] = pveAddr;
json['pveAddr'] = pveAddr;
}
json["pveIgnoreCert"] = pveIgnoreCert;
json['pveIgnoreCert'] = pveIgnoreCert;

if (cmds != null) {
json["cmds"] = cmds;
json['cmds'] = cmds;
}
if (preferTempDev != null) {
json["preferTempDev"] = preferTempDev;
json['preferTempDev'] = preferTempDev;
}
if (logoUrl != null) {
json["logoUrl"] = logoUrl;
json['logoUrl'] = logoUrl;
}
return json;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/data/model/server/disk.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:fl_lib/fl_lib.dart';
import 'package:server_box/data/model/server/time_seq.dart';

import '../../res/misc.dart';
import 'package:server_box/data/res/misc.dart';

class Disk {
final String fs;
Expand Down
2 changes: 1 addition & 1 deletion lib/data/model/server/net_speed.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:fl_lib/fl_lib.dart';

import 'time_seq.dart';
import 'package:server_box/data/model/server/time_seq.dart';

class NetSpeedPart extends TimeSeqIface<NetSpeedPart> {
final String device;
Expand Down
8 changes: 4 additions & 4 deletions lib/data/model/server/private_key_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ class PrivateKeyInfo {
}

PrivateKeyInfo.fromJson(Map<String, dynamic> json)
: id = json["id"].toString(),
key = json["private_key"].toString();
: id = json['id'].toString(),
key = json['private_key'].toString();

Map<String, dynamic> toJson() {
final data = <String, String>{};
data["id"] = id;
data["private_key"] = key;
data['id'] = id;
data['private_key'] = key;
return data;
}
}
Loading