#25 new: sftp upload
This commit is contained in:
@@ -3,9 +3,14 @@ import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:toolbox/core/extension/navigator.dart';
|
||||
import 'package:toolbox/data/model/sftp/req.dart';
|
||||
import 'package:toolbox/data/provider/server.dart';
|
||||
import 'package:toolbox/data/provider/sftp.dart';
|
||||
import 'package:toolbox/data/res/misc.dart';
|
||||
import 'package:toolbox/locator.dart';
|
||||
import 'package:toolbox/view/page/editor.dart';
|
||||
import 'package:toolbox/view/widget/input_field.dart';
|
||||
import 'package:toolbox/view/widget/picker.dart';
|
||||
|
||||
import '../../../core/extension/numx.dart';
|
||||
import '../../../core/extension/stringx.dart';
|
||||
@@ -217,6 +222,51 @@ class _SFTPDownloadedPageState extends State<SFTPDownloadedPage> {
|
||||
);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.upload),
|
||||
title: Text(_s.upload),
|
||||
onTap: () async {
|
||||
context.pop();
|
||||
final remotePath = await showRoundDialog(
|
||||
context: context,
|
||||
title: Text(_s.remotePath),
|
||||
child: Input(
|
||||
controller: TextEditingController(text: '/'),
|
||||
onSubmitted: (p0) {
|
||||
context.pop(p0);
|
||||
},
|
||||
));
|
||||
if (remotePath == null) {
|
||||
showSnackBar(context, Text(_s.fieldMustNotEmpty));
|
||||
return;
|
||||
}
|
||||
final serverProvider = locator<ServerProvider>();
|
||||
final ids = serverProvider.serverOrder;
|
||||
var idx = 0;
|
||||
await showRoundDialog(
|
||||
context: context,
|
||||
title: Text(_s.server),
|
||||
child: Picker(
|
||||
items: ids.map((e) => Text(e)).toList(),
|
||||
onSelected: (idx_) => idx = idx_,
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => context.pop(), child: Text(_s.ok)),
|
||||
],
|
||||
);
|
||||
final id = ids[idx];
|
||||
final spi = serverProvider.servers[id]?.spi;
|
||||
if (spi == null) {
|
||||
showSnackBar(context, Text(_s.noResult));
|
||||
return;
|
||||
}
|
||||
locator<SftpProvider>().add(
|
||||
SftpReqItem(spi, remotePath, file.absolute.path),
|
||||
SftpReqType.upload,
|
||||
);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.open_in_new),
|
||||
title: Text(_s.open),
|
||||
|
||||
@@ -5,8 +5,8 @@ import 'package:provider/provider.dart';
|
||||
import '../../../core/extension/numx.dart';
|
||||
import '../../../core/utils/misc.dart';
|
||||
import '../../../core/utils/ui.dart';
|
||||
import '../../../data/model/sftp/download_status.dart';
|
||||
import '../../../data/provider/sftp_download.dart';
|
||||
import '../../../data/model/sftp/req.dart';
|
||||
import '../../../data/provider/sftp.dart';
|
||||
import '../../../data/res/ui.dart';
|
||||
import '../../widget/round_rect_card.dart';
|
||||
|
||||
@@ -57,7 +57,7 @@ class _SFTPDownloadingPageState extends State<SFTPDownloadingPage> {
|
||||
});
|
||||
}
|
||||
|
||||
Widget _wrapInCard(SftpDownloadStatus status, String? subtitle,
|
||||
Widget _wrapInCard(SftpReqStatus status, String? subtitle,
|
||||
{Widget? trailing}) {
|
||||
return RoundRectCard(
|
||||
ListTile(
|
||||
@@ -73,7 +73,7 @@ class _SFTPDownloadingPageState extends State<SFTPDownloadingPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildItem(SftpDownloadStatus status) {
|
||||
Widget _buildItem(SftpReqStatus status) {
|
||||
if (status.error != null) {
|
||||
showSnackBar(context, Text(status.error.toString()));
|
||||
status.error = null;
|
||||
|
||||
@@ -18,9 +18,9 @@ import '../../../data/model/server/server.dart';
|
||||
import '../../../data/model/server/server_private_info.dart';
|
||||
import '../../../data/model/sftp/absolute_path.dart';
|
||||
import '../../../data/model/sftp/browser_status.dart';
|
||||
import '../../../data/model/sftp/download_item.dart';
|
||||
import '../../../data/model/sftp/req.dart';
|
||||
import '../../../data/provider/server.dart';
|
||||
import '../../../data/provider/sftp_download.dart';
|
||||
import '../../../data/provider/sftp.dart';
|
||||
import '../../../data/res/path.dart';
|
||||
import '../../../data/res/ui.dart';
|
||||
import '../../../data/store/private_key.dart';
|
||||
@@ -313,6 +313,7 @@ class _SFTPPageState extends State<SFTPPage> {
|
||||
void _download(BuildContext context, SftpName name) {
|
||||
showRoundDialog(
|
||||
context: context,
|
||||
title: Text(_s.attention),
|
||||
child: Text('${_s.dl2Local(name.filename)}\n${_s.keepForeground}'),
|
||||
actions: [
|
||||
TextButton(
|
||||
@@ -325,16 +326,16 @@ class _SFTPPageState extends State<SFTPPage> {
|
||||
final remotePath = _getRemotePath(name);
|
||||
final local = '${(await sftpDir).path}$remotePath';
|
||||
final pubKeyId = widget.spi.pubKeyId;
|
||||
final key = locator<PrivateKeyStore>().get(pubKeyId)?.privateKey;
|
||||
|
||||
locator<SftpProvider>().add(
|
||||
DownloadItem(
|
||||
SftpReqItem(
|
||||
widget.spi,
|
||||
remotePath,
|
||||
local,
|
||||
),
|
||||
key: pubKeyId == null
|
||||
? null
|
||||
: locator<PrivateKeyStore>().get(pubKeyId).privateKey,
|
||||
SftpReqType.download,
|
||||
key: key,
|
||||
);
|
||||
|
||||
context.pop();
|
||||
@@ -354,6 +355,7 @@ class _SFTPPageState extends State<SFTPPage> {
|
||||
showRoundDialog(
|
||||
context: context,
|
||||
child: child,
|
||||
title: Text(_s.attention),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => context.pop(),
|
||||
|
||||
Reference in New Issue
Block a user