fix: sftp upload (#175)

This commit is contained in:
lollipopkit
2023-12-18 16:17:57 +08:00
parent 3ff94413e4
commit dd2555fc3f
7 changed files with 18 additions and 16 deletions

View File

@@ -56,7 +56,7 @@ class ServerStatus {
SystemType system; SystemType system;
String? err; String? err;
DiskIO diskIO; DiskIO diskIO;
List<NvidiaSmiItem>? nvdia; List<NvidiaSmiItem>? nvidia;
/// Whether is connectting, parsing and etc. /// Whether is connectting, parsing and etc.
bool _isBusy = false; bool _isBusy = false;
@@ -74,7 +74,7 @@ class ServerStatus {
required this.system, required this.system,
required this.diskIO, required this.diskIO,
this.err, this.err,
this.nvdia, this.nvidia,
}); });
} }

View File

@@ -113,8 +113,8 @@ Future<ServerStatus> _getLinuxStatus(ServerStatusUpdateReq req) async {
} }
try { try {
final nvdia = NvidiaSmi.fromXml(StatusCmdType.nvdia.find(segments)); final nvidia = NvidiaSmi.fromXml(StatusCmdType.nvidia.find(segments));
req.ss.nvdia = nvdia; req.ss.nvidia = nvidia;
} catch (e, s) { } catch (e, s) {
Loggers.parse.warning(e, s); Loggers.parse.warning(e, s);
} }

View File

@@ -154,9 +154,12 @@ Future<void> _upload(
mainSendPort.send(SftpWorkerStatus.loading); mainSendPort.send(SftpWorkerStatus.loading);
final localFile = local.openRead().cast<Uint8List>(); final localFile = local.openRead().cast<Uint8List>();
final sftp = await client.sftp(); final sftp = await client.sftp();
// If remote exists, overwrite it
final file = await sftp.open( final file = await sftp.open(
req.remotePath, req.remotePath,
mode: SftpFileOpenMode.write | SftpFileOpenMode.create, mode: SftpFileOpenMode.truncate |
SftpFileOpenMode.create |
SftpFileOpenMode.write,
); );
final writer = file.write( final writer = file.write(
localFile, localFile,

View File

@@ -42,5 +42,7 @@ abstract final class GithubIds {
'xingleiwu', 'xingleiwu',
'Cooper098', 'Cooper098',
'xushuojie', 'xushuojie',
'AniberMokie',
'LucaLin233',
}; };
} }

View File

@@ -307,8 +307,8 @@ class _ServerDetailPageState extends State<ServerDetailPage>
} }
Widget _buildGpuView(ServerStatus ss) { Widget _buildGpuView(ServerStatus ss) {
if (ss.nvdia == null) return UIs.placeholder; if (ss.nvidia == null) return UIs.placeholder;
final children = ss.nvdia!.map((e) => _buildGpuItem(e)).toList(); final children = ss.nvidia!.map((e) => _buildGpuItem(e)).toList();
return CardX( return CardX(
child: ExpandTile( child: ExpandTile(
title: const Text('GPU'), title: const Text('GPU'),

View File

@@ -144,18 +144,15 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
if (path == null) { if (path == null) {
return; return;
} }
final remotePath = _status.path?.path; final remoteDir = _status.path?.path;
if (remotePath == null) { if (remoteDir == null) {
context.showSnackBar('remote path is null'); context.showSnackBar('remote path is null');
return; return;
} }
final remotePath = '$remoteDir/${path.split('/').last}';
Loggers.app.info('SFTP upload local: $path, remote: $remotePath');
Pros.sftp.add( Pros.sftp.add(
SftpReq( SftpReq(widget.spi, remotePath, path, SftpReqType.upload),
widget.spi,
'$remotePath/${path.split('/').last}',
path,
SftpReqType.upload,
),
); );
}, },
icon: const Icon(Icons.upload_file)); icon: const Icon(Icons.upload_file));