Fix some known issues and add some new functions
Android APK Release / Build Android APK (push) Failing after 52m53s

This commit is contained in:
2026-05-25 20:03:59 +08:00
parent 74abb4a1c5
commit 39d8361080
8 changed files with 587 additions and 221 deletions
+116 -17
View File
@@ -8,6 +8,64 @@ class FileUtils {
final cleanPath = path.startsWith('/') ? path.substring(1) : path; final cleanPath = path.startsWith('/') ? path.substring(1) : path;
return 'cloudreve://my/$cleanPath'; return 'cloudreve://my/$cleanPath';
} }
static String toCloudreveUriWithQuery(
String path,
Map<String, Object?> queryParameters,
) {
final baseUri = toCloudreveUri(path);
final filteredQuery = <String, String>{};
for (final entry in queryParameters.entries) {
final value = entry.value;
if (value != null) {
filteredQuery[entry.key] = value.toString();
}
}
if (filteredQuery.isEmpty) return baseUri;
final query = Uri(queryParameters: filteredQuery).query;
final separator = baseUri.contains('?') ? '&' : '?';
return '$baseUri$separator$query';
}
static String toRelativePath(String path) {
const prefix = 'cloudreve://my';
if (!path.startsWith(prefix)) {
return path.isEmpty ? '/' : path;
}
var relative = path.substring(prefix.length);
final queryIndex = relative.indexOf('?');
if (queryIndex != -1) {
relative = relative.substring(0, queryIndex);
}
return relative.isEmpty ? '/' : relative;
}
static String decodePathForDisplay(String path) {
final relativePath = toRelativePath(path);
return relativePath.split('/').map(decodePathSegment).join('/');
}
static String decodePathSegment(String value) {
var decoded = value;
for (var i = 0; i < 5; i++) {
try {
final next = Uri.decodeComponent(decoded);
if (next == decoded) break;
decoded = next;
} on FormatException {
break;
}
}
return decoded;
}
/// 获取文件扩展名 /// 获取文件扩展名
static String getFileExtension(String fileName) { static String getFileExtension(String fileName) {
final dotIndex = fileName.lastIndexOf('.'); final dotIndex = fileName.lastIndexOf('.');
@@ -18,24 +76,27 @@ class FileUtils {
/// 判断是否为图片文件 /// 判断是否为图片文件
static bool isImageFile(String fileName) { static bool isImageFile(String fileName) {
const imageExtensions = [ const imageExtensions = [
'jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'svg', 'heic' 'jpg',
'jpeg',
'png',
'gif',
'webp',
'bmp',
'svg',
'heic',
]; ];
return imageExtensions.contains(getFileExtension(fileName)); return imageExtensions.contains(getFileExtension(fileName));
} }
/// 判断是否为视频文件 /// 判断是否为视频文件
static bool isVideoFile(String fileName) { static bool isVideoFile(String fileName) {
const videoExtensions = [ const videoExtensions = ['mp4', 'webm', 'mkv', 'avi', 'mov', 'flv', 'wmv'];
'mp4', 'webm', 'mkv', 'avi', 'mov', 'flv', 'wmv'
];
return videoExtensions.contains(getFileExtension(fileName)); return videoExtensions.contains(getFileExtension(fileName));
} }
/// 判断是否为音频文件 /// 判断是否为音频文件
static bool isAudioFile(String fileName) { static bool isAudioFile(String fileName) {
const audioExtensions = [ const audioExtensions = ['mp3', 'wav', 'ogg', 'flac', 'aac', 'm4a'];
'mp3', 'wav', 'ogg', 'flac', 'aac', 'm4a'
];
return audioExtensions.contains(getFileExtension(fileName)); return audioExtensions.contains(getFileExtension(fileName));
} }
@@ -47,7 +108,14 @@ class FileUtils {
/// 判断是否为文本文件 /// 判断是否为文本文件
static bool isTextFile(String fileName) { static bool isTextFile(String fileName) {
const textExtensions = [ const textExtensions = [
'txt', 'md', 'json', 'xml', 'yaml', 'yml', 'ini', 'conf' 'txt',
'md',
'json',
'xml',
'yaml',
'yml',
'ini',
'conf',
]; ];
return textExtensions.contains(getFileExtension(fileName)); return textExtensions.contains(getFileExtension(fileName));
} }
@@ -55,33 +123,64 @@ class FileUtils {
/// 判断是否为代码文件 /// 判断是否为代码文件
static bool isCodeFile(String fileName) { static bool isCodeFile(String fileName) {
const codeExtensions = [ const codeExtensions = [
'js', 'ts', 'tsx', 'jsx', 'dart', 'java', 'py', 'c', 'cpp', 'js',
'h', 'hpp', 'cs', 'php', 'rb', 'go', 'rs', 'swift', 'kt', 'ts',
'html', 'css', 'scss', 'less', 'sql', 'sh', 'bat' 'tsx',
'jsx',
'dart',
'java',
'py',
'c',
'cpp',
'h',
'hpp',
'cs',
'php',
'rb',
'go',
'rs',
'swift',
'kt',
'html',
'css',
'scss',
'less',
'sql',
'sh',
'bat',
]; ];
return codeExtensions.contains(getFileExtension(fileName)); return codeExtensions.contains(getFileExtension(fileName));
} }
/// 判断是否为压缩文件 /// 判断是否为压缩文件
static bool isArchiveFile(String fileName) { static bool isArchiveFile(String fileName) {
const archiveExtensions = [ const archiveExtensions = ['zip', 'rar', '7z', 'tar', 'gz', 'bz2'];
'zip', 'rar', '7z', 'tar', 'gz', 'bz2'
];
return archiveExtensions.contains(getFileExtension(fileName)); return archiveExtensions.contains(getFileExtension(fileName));
} }
/// 判断是否为文档文件 /// 判断是否为文档文件
static bool isDocumentFile(String fileName) { static bool isDocumentFile(String fileName) {
const docExtensions = [ const docExtensions = [
'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'odt', 'ods', 'odp' 'doc',
'docx',
'xls',
'xlsx',
'ppt',
'pptx',
'odt',
'ods',
'odp',
]; ];
return docExtensions.contains(getFileExtension(fileName)); return docExtensions.contains(getFileExtension(fileName));
} }
/// 判断是否可预览 /// 判断是否可预览
static bool isPreviewable(String fileName) { static bool isPreviewable(String fileName) {
return isImageFile(fileName) || isVideoFile(fileName) || return isImageFile(fileName) ||
isPdfFile(fileName) || isTextFile(fileName) || isCodeFile(fileName); isVideoFile(fileName) ||
isPdfFile(fileName) ||
isTextFile(fileName) ||
isCodeFile(fileName);
} }
/// 获取MIME类型 /// 获取MIME类型
+204 -69
View File
@@ -56,7 +56,10 @@ class _FilesPageState extends State<FilesPage> {
Future.delayed(const Duration(milliseconds: 100), () { Future.delayed(const Duration(milliseconds: 100), () {
if (mounted) { if (mounted) {
final fileManager = Provider.of<FileManagerProvider>(context, listen: false); final fileManager = Provider.of<FileManagerProvider>(
context,
listen: false,
);
final screenWidth = MediaQuery.of(context).size.width; final screenWidth = MediaQuery.of(context).size.width;
if (screenWidth >= 1000) { if (screenWidth >= 1000) {
fileManager.setViewType(FileViewType.grid); fileManager.setViewType(FileViewType.grid);
@@ -67,7 +70,10 @@ class _FilesPageState extends State<FilesPage> {
fileManager.loadFiles(); fileManager.loadFiles();
_isFirstLoad = false; _isFirstLoad = false;
} }
final downloadManager = Provider.of<DownloadManagerProvider>(context, listen: false); final downloadManager = Provider.of<DownloadManagerProvider>(
context,
listen: false,
);
downloadManager.initialize(); downloadManager.initialize();
} }
}); });
@@ -75,8 +81,13 @@ class _FilesPageState extends State<FilesPage> {
// 上传完成 → 自动刷新当前目录文件列表 // 上传完成 → 自动刷新当前目录文件列表
UploadService.instance.onUploadCompleted = (targetPath, fileName) { UploadService.instance.onUploadCompleted = (targetPath, fileName) {
if (!mounted) return; if (!mounted) return;
final fileManager = Provider.of<FileManagerProvider>(context, listen: false); final fileManager = Provider.of<FileManagerProvider>(
final normalizedCurrent = FileUtils.toCloudreveUri(fileManager.currentPath); context,
listen: false,
);
final normalizedCurrent = FileUtils.toCloudreveUri(
fileManager.currentPath,
);
if (targetPath == normalizedCurrent) { if (targetPath == normalizedCurrent) {
final fileUri = targetPath.endsWith('/') final fileUri = targetPath.endsWith('/')
? '$targetPath$fileName' ? '$targetPath$fileName'
@@ -168,8 +179,14 @@ class _FilesPageState extends State<FilesPage> {
if (fileManager.currentPath == '/') { if (fileManager.currentPath == '/') {
return const Text('文件'); return const Text('文件');
} }
final segments = fileManager.currentPath.split('/').where((s) => s.isNotEmpty).toList(); final segments = FileUtils.toRelativePath(
return Text(segments.isNotEmpty ? segments.last : '文件'); fileManager.currentPath,
).split('/').where((s) => s.isNotEmpty).toList();
return Text(
segments.isNotEmpty
? FileUtils.decodePathSegment(segments.last)
: '文件',
);
} }
return _buildMobileBreadcrumb(context, fileManager); return _buildMobileBreadcrumb(context, fileManager);
}, },
@@ -178,10 +195,15 @@ class _FilesPageState extends State<FilesPage> {
); );
} }
Widget _buildMobileBreadcrumb(BuildContext context, FileManagerProvider fileManager) { Widget _buildMobileBreadcrumb(
BuildContext context,
FileManagerProvider fileManager,
) {
final theme = Theme.of(context); final theme = Theme.of(context);
final colorScheme = theme.colorScheme; final colorScheme = theme.colorScheme;
final pathParts = fileManager.currentPath.split('/'); final pathParts = FileUtils.toRelativePath(
fileManager.currentPath,
).split('/');
pathParts.removeWhere((part) => part.isEmpty); pathParts.removeWhere((part) => part.isEmpty);
return SizedBox( return SizedBox(
@@ -194,22 +216,30 @@ class _FilesPageState extends State<FilesPage> {
label: '文件', label: '文件',
icon: LucideIcons.home, icon: LucideIcons.home,
color: colorScheme.primary, color: colorScheme.primary,
onTap: () => fileManager.currentPath != '/' ? fileManager.enterFolder('/') : null, onTap: () => fileManager.currentPath != '/'
? fileManager.enterFolder('/')
: null,
), ),
for (int i = 0; i < pathParts.length; i++) ...[ for (int i = 0; i < pathParts.length; i++) ...[
Padding( Padding(
padding: const EdgeInsets.symmetric(horizontal: 2), padding: const EdgeInsets.symmetric(horizontal: 2),
child: Icon(LucideIcons.chevronRight, size: 14, color: theme.hintColor.withValues(alpha: 0.5)), child: Icon(
LucideIcons.chevronRight,
size: 14,
color: theme.hintColor.withValues(alpha: 0.5),
),
), ),
_buildBreadcrumbChip( _buildBreadcrumbChip(
context, context,
label: pathParts[i], label: FileUtils.decodePathSegment(pathParts[i]),
icon: null, icon: null,
color: colorScheme.primary, color: colorScheme.primary,
isLast: i == pathParts.length - 1, isLast: i == pathParts.length - 1,
onTap: () { onTap: () {
final targetPath = '/${pathParts.sublist(0, i + 1).join('/')}'; final targetPath = '/${pathParts.sublist(0, i + 1).join('/')}';
if (targetPath != fileManager.currentPath) fileManager.enterFolder(targetPath); if (targetPath != fileManager.currentPath) {
fileManager.enterFolder(targetPath);
}
}, },
), ),
], ],
@@ -233,7 +263,9 @@ class _FilesPageState extends State<FilesPage> {
height: 28, height: 28,
padding: const EdgeInsets.symmetric(horizontal: 8), padding: const EdgeInsets.symmetric(horizontal: 8),
decoration: BoxDecoration( decoration: BoxDecoration(
color: isLast ? color.withValues(alpha: 0.15) : color.withValues(alpha: 0.06), color: isLast
? color.withValues(alpha: 0.15)
: color.withValues(alpha: 0.06),
borderRadius: BorderRadius.circular(14), borderRadius: BorderRadius.circular(14),
), ),
child: Row( child: Row(
@@ -267,7 +299,9 @@ class _FilesPageState extends State<FilesPage> {
Consumer<FileManagerProvider>( Consumer<FileManagerProvider>(
builder: (context, fileManager, child) { builder: (context, fileManager, child) {
return IconButton( return IconButton(
icon: Icon(fileManager.isLoading ? Icons.hourglass_empty : Icons.refresh), icon: Icon(
fileManager.isLoading ? Icons.hourglass_empty : Icons.refresh,
),
onPressed: () => fileManager.refreshFiles(), onPressed: () => fileManager.refreshFiles(),
tooltip: '刷新', tooltip: '刷新',
); );
@@ -287,14 +321,19 @@ class _FilesPageState extends State<FilesPage> {
: FileViewType.list, : FileViewType.list,
); );
}, },
tooltip: fileManager.viewType == FileViewType.list ? '网格视图' : '列表视图', tooltip: fileManager.viewType == FileViewType.list
? '网格视图'
: '列表视图',
); );
}, },
), ),
IconButton( IconButton(
icon: const Icon(Icons.add), icon: const Icon(Icons.add),
onPressed: () { onPressed: () {
final fileManager = Provider.of<FileManagerProvider>(context, listen: false); final fileManager = Provider.of<FileManagerProvider>(
context,
listen: false,
);
FileOperationDialogs.showCreateDialog(context, fileManager); FileOperationDialogs.showCreateDialog(context, fileManager);
}, },
tooltip: '新建', tooltip: '新建',
@@ -306,7 +345,8 @@ class _FilesPageState extends State<FilesPage> {
), ),
IconButton( IconButton(
icon: const Icon(Icons.cloud_download), icon: const Icon(Icons.cloud_download),
onPressed: () => Provider.of<NavigationProvider>(context, listen: false).setIndex(2), onPressed: () =>
Provider.of<NavigationProvider>(context, listen: false).setIndex(2),
tooltip: '下载', tooltip: '下载',
), ),
]; ];
@@ -328,7 +368,9 @@ class _FilesPageState extends State<FilesPage> {
: FileViewType.list, : FileViewType.list,
); );
}, },
tooltip: fileManager.viewType == FileViewType.list ? '网格视图' : '列表视图', tooltip: fileManager.viewType == FileViewType.list
? '网格视图'
: '列表视图',
); );
}, },
), ),
@@ -380,8 +422,16 @@ class _FilesPageState extends State<FilesPage> {
isDark: isDark, isDark: isDark,
colorScheme: colorScheme, colorScheme: colorScheme,
onTap: () { onTap: () {
final fileManager = Provider.of<FileManagerProvider>(context, listen: false); final fileManager = Provider.of<FileManagerProvider>(
_onFabSubAction(() => FileOperationDialogs.showCreateDialog(context, fileManager)); context,
listen: false,
);
_onFabSubAction(
() => FileOperationDialogs.showCreateDialog(
context,
fileManager,
),
);
}, },
), ),
_buildFabSubItem( _buildFabSubItem(
@@ -391,7 +441,10 @@ class _FilesPageState extends State<FilesPage> {
label: '离线下载', label: '离线下载',
isDark: isDark, isDark: isDark,
colorScheme: colorScheme, colorScheme: colorScheme,
onTap: () => _onFabSubAction(() => Navigator.of(context).pushNamed(RouteNames.remoteDownload)), onTap: () => _onFabSubAction(
() =>
Navigator.of(context).pushNamed(RouteNames.remoteDownload),
),
), ),
Consumer<FileManagerProvider>( Consumer<FileManagerProvider>(
builder: (context, fileManager, _) { builder: (context, fileManager, _) {
@@ -477,7 +530,10 @@ class _FilesPageState extends State<FilesPage> {
child: BackdropFilter( child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10), filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10),
child: Container( child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 7), padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 7,
),
decoration: BoxDecoration( decoration: BoxDecoration(
color: isDark color: isDark
? Colors.white.withValues(alpha: 0.12) ? Colors.white.withValues(alpha: 0.12)
@@ -558,7 +614,8 @@ class _FilesPageState extends State<FilesPage> {
final isDesktop = MediaQuery.of(context).size.width >= 1000; final isDesktop = MediaQuery.of(context).size.width >= 1000;
final child = _buildFileList(context); final child = _buildFileList(context);
if (!isDesktop || !Platform.isWindows && !Platform.isLinux && !Platform.isMacOS) { if (!isDesktop ||
!Platform.isWindows && !Platform.isLinux && !Platform.isMacOS) {
return child; return child;
} }
@@ -582,13 +639,19 @@ class _FilesPageState extends State<FilesPage> {
strokeAlign: BorderSide.strokeAlignOutside, strokeAlign: BorderSide.strokeAlignOutside,
), ),
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
color: Theme.of(context).colorScheme.surface.withValues(alpha: 0.85), color: Theme.of(
context,
).colorScheme.surface.withValues(alpha: 0.85),
), ),
child: Center( child: Center(
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Icon(LucideIcons.upload, size: 48, color: Theme.of(context).colorScheme.primary), Icon(
LucideIcons.upload,
size: 48,
color: Theme.of(context).colorScheme.primary,
),
const SizedBox(height: 12), const SizedBox(height: 12),
Text( Text(
'释放文件以上传到当前目录', '释放文件以上传到当前目录',
@@ -618,8 +681,14 @@ class _FilesPageState extends State<FilesPage> {
} }
if (files.isEmpty) return; if (files.isEmpty) return;
final uploadManager = Provider.of<UploadManagerProvider>(context, listen: false); final uploadManager = Provider.of<UploadManagerProvider>(
final fileManager = Provider.of<FileManagerProvider>(context, listen: false); context,
listen: false,
);
final fileManager = Provider.of<FileManagerProvider>(
context,
listen: false,
);
uploadManager.markShouldShowDialog(); uploadManager.markShouldShowDialog();
uploadManager.startUpload(files, fileManager.currentPath); uploadManager.startUpload(files, fileManager.currentPath);
ToastHelper.info('已添加 ${files.length} 个文件到上传队列'); ToastHelper.info('已添加 ${files.length} 个文件到上传队列');
@@ -649,12 +718,19 @@ class _FilesPageState extends State<FilesPage> {
); );
} }
Widget _buildErrorView(BuildContext context, FileManagerProvider fileManager) { Widget _buildErrorView(
BuildContext context,
FileManagerProvider fileManager,
) {
return Center( return Center(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Icon(Icons.error_outline, size: 64, color: Theme.of(context).colorScheme.error), Icon(
Icons.error_outline,
size: 64,
color: Theme.of(context).colorScheme.error,
),
const SizedBox(height: 16), const SizedBox(height: 16),
Text( Text(
fileManager.errorMessage!, fileManager.errorMessage!,
@@ -705,7 +781,9 @@ class _FilesPageState extends State<FilesPage> {
itemCount: fileManager.files.length, itemCount: fileManager.files.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
final file = fileManager.files[index]; final file = fileManager.files[index];
final isSelected = fileManager.selectedFiles.contains(file.path); final isSelected = fileManager.selectedFiles.contains(
file.path,
);
return FileListItem( return FileListItem(
key: ValueKey('file_${file.id}'), key: ValueKey('file_${file.id}'),
@@ -727,13 +805,37 @@ class _FilesPageState extends State<FilesPage> {
} }
}, },
onSelect: () => fileManager.toggleSelection(file.path), onSelect: () => fileManager.toggleSelection(file.path),
onDownload: !file.isFolder ? () => _downloadFile(context, fileManager, file) : null, onDownload: !file.isFolder
onOpenInBrowser: !file.isFolder ? () => _openInBrowser(context, file) : null, ? () => _downloadFile(context, fileManager, file)
onRename: () => FileOperationDialogs.showRenameDialog(context, fileManager, file), : null,
onMove: () => FileOperationDialogs.showMoveDialog(context, fileManager, file, false), onOpenInBrowser: !file.isFolder
onCopy: () => FileOperationDialogs.showMoveDialog(context, fileManager, file, true), ? () => _openInBrowser(context, file)
onShare: () => FileOperationDialogs.showShareDialog(context, file), : null,
onDelete: () => FileOperationDialogs.showDeleteSingleConfirmation(context, fileManager, file), onRename: () => FileOperationDialogs.showRenameDialog(
context,
fileManager,
file,
),
onMove: () => FileOperationDialogs.showMoveDialog(
context,
fileManager,
file,
false,
),
onCopy: () => FileOperationDialogs.showMoveDialog(
context,
fileManager,
file,
true,
),
onShare: () =>
FileOperationDialogs.showShareDialog(context, file),
onDelete: () =>
FileOperationDialogs.showDeleteSingleConfirmation(
context,
fileManager,
file,
),
onInfo: () => _showFileInfo(file), onInfo: () => _showFileInfo(file),
); );
}, },
@@ -762,7 +864,8 @@ class _FilesPageState extends State<FilesPage> {
crossAxisCount = 5; crossAxisCount = 5;
} }
final itemWidth = (availableWidth - spacing * (crossAxisCount - 1)) / crossAxisCount; final itemWidth =
(availableWidth - spacing * (crossAxisCount - 1)) / crossAxisCount;
final childAspectRatio = itemWidth / 160; final childAspectRatio = itemWidth / 160;
final showCheckbox = fileManager.hasSelection; final showCheckbox = fileManager.hasSelection;
@@ -802,13 +905,36 @@ class _FilesPageState extends State<FilesPage> {
} }
}, },
onSelect: () => fileManager.toggleSelection(file.path), onSelect: () => fileManager.toggleSelection(file.path),
onDownload: !file.isFolder ? () => _downloadFile(context, fileManager, file) : null, onDownload: !file.isFolder
onOpenInBrowser: !file.isFolder ? () => _openInBrowser(context, file) : null, ? () => _downloadFile(context, fileManager, file)
onRename: () => FileOperationDialogs.showRenameDialog(context, fileManager, file), : null,
onMove: () => FileOperationDialogs.showMoveDialog(context, fileManager, file, false), onOpenInBrowser: !file.isFolder
onCopy: () => FileOperationDialogs.showMoveDialog(context, fileManager, file, true), ? () => _openInBrowser(context, file)
onShare: () => FileOperationDialogs.showShareDialog(context, file), : null,
onDelete: () => FileOperationDialogs.showDeleteSingleConfirmation(context, fileManager, file), onRename: () => FileOperationDialogs.showRenameDialog(
context,
fileManager,
file,
),
onMove: () => FileOperationDialogs.showMoveDialog(
context,
fileManager,
file,
false,
),
onCopy: () => FileOperationDialogs.showMoveDialog(
context,
fileManager,
file,
true,
),
onShare: () =>
FileOperationDialogs.showShareDialog(context, file),
onDelete: () => FileOperationDialogs.showDeleteSingleConfirmation(
context,
fileManager,
file,
),
onInfo: () => _showFileInfo(file), onInfo: () => _showFileInfo(file),
); );
}, },
@@ -829,30 +955,30 @@ class _FilesPageState extends State<FilesPage> {
onCancel: () => fileManager.clearSelection(), onCancel: () => fileManager.clearSelection(),
onRename: fileManager.selectedFiles.length == 1 onRename: fileManager.selectedFiles.length == 1
? () => FileOperationDialogs.showRenameDialog( ? () => FileOperationDialogs.showRenameDialog(
context, context,
fileManager, fileManager,
fileManager.files.firstWhere( fileManager.files.firstWhere(
(f) => f.path == fileManager.selectedFiles.first, (f) => f.path == fileManager.selectedFiles.first,
), ),
) )
: null, : null,
onMove: () => FileOperationDialogs.showBatchMoveDialog( onMove: () => FileOperationDialogs.showBatchMoveDialog(
context, context,
fileManager, fileManager,
fileManager.selectedFiles, fileManager.selectedFiles,
false, false,
), ),
onCopy: () => FileOperationDialogs.showBatchMoveDialog( onCopy: () => FileOperationDialogs.showBatchMoveDialog(
context, context,
fileManager, fileManager,
fileManager.selectedFiles, fileManager.selectedFiles,
true, true,
), ),
onDelete: () => FileOperationDialogs.showDeleteConfirmation( onDelete: () => FileOperationDialogs.showDeleteConfirmation(
context, context,
fileManager, fileManager,
fileManager.selectedFiles, fileManager.selectedFiles,
), ),
); );
} }
@@ -876,11 +1002,17 @@ class _FilesPageState extends State<FilesPage> {
} else if (FileTypeUtils.isAudio(file.name)) { } else if (FileTypeUtils.isAudio(file.name)) {
Navigator.of(context).pushNamed(RouteNames.audioPreview, arguments: file); Navigator.of(context).pushNamed(RouteNames.audioPreview, arguments: file);
} else if (FileTypeUtils.isMarkdown(file.name)) { } else if (FileTypeUtils.isMarkdown(file.name)) {
Navigator.of(context).pushNamed(RouteNames.markdownPreview, arguments: file); Navigator.of(
context,
).pushNamed(RouteNames.markdownPreview, arguments: file);
} else if (FileTypeUtils.isTextCode(file.name)) { } else if (FileTypeUtils.isTextCode(file.name)) {
Navigator.of(context).pushNamed(RouteNames.documentPreview, arguments: file); Navigator.of(
context,
).pushNamed(RouteNames.documentPreview, arguments: file);
} else { } else {
ToastHelper.info('暂不支持预览 ${FileTypeUtils.getFileTypeDescription(file.name)}'); ToastHelper.info(
'暂不支持预览 ${FileTypeUtils.getFileTypeDescription(file.name)}',
);
} }
} }
@@ -889,7 +1021,10 @@ class _FilesPageState extends State<FilesPage> {
FileManagerProvider fileManager, FileManagerProvider fileManager,
FileModel file, FileModel file,
) async { ) async {
final downloadManager = Provider.of<DownloadManagerProvider>(context, listen: false); final downloadManager = Provider.of<DownloadManagerProvider>(
context,
listen: false,
);
final task = await downloadManager.addDownloadTask( final task = await downloadManager.addDownloadTask(
fileName: file.name, fileName: file.name,
fileUri: file.relativePath, fileUri: file.relativePath,
+3 -18
View File
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:lucide_icons/lucide_icons.dart'; import 'package:lucide_icons/lucide_icons.dart';
import '../../core/utils/file_utils.dart';
/// 面包屑导航组件 /// 面包屑导航组件
class FileBreadcrumb extends StatelessWidget { class FileBreadcrumb extends StatelessWidget {
@@ -14,7 +15,7 @@ class FileBreadcrumb extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final pathParts = currentPath.split('/'); final pathParts = FileUtils.toRelativePath(currentPath).split('/');
pathParts.removeWhere((part) => part.isEmpty); pathParts.removeWhere((part) => part.isEmpty);
final theme = Theme.of(context); final theme = Theme.of(context);
final colorScheme = theme.colorScheme; final colorScheme = theme.colorScheme;
@@ -54,7 +55,7 @@ class FileBreadcrumb extends StatelessWidget {
), ),
_buildBreadcrumbItem( _buildBreadcrumbItem(
context, context,
name: _decodePathSegment(pathParts[i]), name: FileUtils.decodePathSegment(pathParts[i]),
path: '/${pathParts.sublist(0, i + 1).join('/')}', path: '/${pathParts.sublist(0, i + 1).join('/')}',
icon: null, icon: null,
primaryColor: colorScheme.primary, primaryColor: colorScheme.primary,
@@ -68,22 +69,6 @@ class FileBreadcrumb extends StatelessWidget {
); );
} }
String _decodePathSegment(String value) {
var decoded = value;
for (var i = 0; i < 5; i++) {
try {
final next = Uri.decodeComponent(decoded);
if (next == decoded) break;
decoded = next;
} on FormatException {
break;
}
}
return decoded;
}
Widget _buildBreadcrumbItem( Widget _buildBreadcrumbItem(
BuildContext context, { BuildContext context, {
required String name, required String name,
+164 -77
View File
@@ -5,6 +5,7 @@ import '../../data/models/file_model.dart';
import '../../core/utils/date_utils.dart' as date_utils; import '../../core/utils/date_utils.dart' as date_utils;
import '../../core/utils/file_icon_utils.dart'; import '../../core/utils/file_icon_utils.dart';
import '../../core/utils/file_type_utils.dart'; import '../../core/utils/file_type_utils.dart';
import '../../core/utils/file_utils.dart';
import '../../services/file_service.dart'; import '../../services/file_service.dart';
import '../../router/app_router.dart'; import '../../router/app_router.dart';
import 'toast_helper.dart'; import 'toast_helper.dart';
@@ -91,52 +92,54 @@ class _FileInfoPanelState extends State<FileInfoPanel> {
child: SafeArea( child: SafeArea(
right: false, right: false,
child: Column( child: Column(
children: [ children: [
Container( Container(
padding: const EdgeInsets.only( padding: const EdgeInsets.only(
left: 16, left: 16,
right: 8, right: 8,
top: 8, top: 8,
bottom: 12, bottom: 12,
),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: theme.dividerColor.withValues(alpha: 0.2)),
), ),
), decoration: BoxDecoration(
child: Row( border: Border(
children: [ bottom: BorderSide(
FileIconUtils.buildIconWidget( color: theme.dividerColor.withValues(alpha: 0.2),
context: context,
file: widget.file,
size: 32,
iconSize: 18,
borderRadius: 8,
),
const SizedBox(width: 12),
Expanded(
child: Text(
widget.file.name,
style: theme.textTheme.titleMedium,
maxLines: 1,
overflow: TextOverflow.ellipsis,
), ),
), ),
IconButton( ),
icon: const Icon(LucideIcons.x), child: Row(
onPressed: () => Navigator.of(context).pop(), children: [
), FileIconUtils.buildIconWidget(
], context: context,
file: widget.file,
size: 32,
iconSize: 18,
borderRadius: 8,
),
const SizedBox(width: 12),
Expanded(
child: Text(
widget.file.name,
style: theme.textTheme.titleMedium,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
IconButton(
icon: const Icon(LucideIcons.x),
onPressed: () => Navigator.of(context).pop(),
),
],
),
), ),
), Expanded(
Expanded( child: _isLoading
child: _isLoading ? const Center(child: CircularProgressIndicator())
? const Center(child: CircularProgressIndicator()) : _error != null
: _error != null ? _buildError(theme)
? _buildError(theme) : _buildContent(theme, colorScheme),
: _buildContent(theme, colorScheme), ),
), ],
],
), ),
), ),
); );
@@ -147,13 +150,21 @@ class _FileInfoPanelState extends State<FileInfoPanel> {
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Icon(LucideIcons.alertCircle, size: 48, color: theme.colorScheme.error), Icon(
LucideIcons.alertCircle,
size: 48,
color: theme.colorScheme.error,
),
const SizedBox(height: 12), const SizedBox(height: 12),
Text('加载失败', style: theme.textTheme.titleSmall), Text('加载失败', style: theme.textTheme.titleSmall),
const SizedBox(height: 4), const SizedBox(height: 4),
Padding( Padding(
padding: const EdgeInsets.symmetric(horizontal: 24), padding: const EdgeInsets.symmetric(horizontal: 24),
child: Text(_error ?? '', style: TextStyle(color: theme.hintColor, fontSize: 12), textAlign: TextAlign.center), child: Text(
_error ?? '',
style: TextStyle(color: theme.hintColor, fontSize: 12),
textAlign: TextAlign.center,
),
), ),
const SizedBox(height: 12), const SizedBox(height: 12),
FilledButton.tonal(onPressed: _loadFileInfo, child: const Text('重试')), FilledButton.tonal(onPressed: _loadFileInfo, child: const Text('重试')),
@@ -168,10 +179,8 @@ class _FileInfoPanelState extends State<FileInfoPanel> {
? '文件夹' ? '文件夹'
: FileIconUtils.getFileTypeLabel(file.name); : FileIconUtils.getFileTypeLabel(file.name);
final extendedInfo = _fileInfo?.extendedInfo; final extendedInfo = _fileInfo?.extendedInfo;
final versionEntities = extendedInfo?.entities final versionEntities =
?.where((e) => e.type == 0) extendedInfo?.entities?.where((e) => e.type == 0).toList() ?? [];
.toList() ??
[];
return SingleChildScrollView( return SingleChildScrollView(
padding: const EdgeInsets.all(16), padding: const EdgeInsets.all(16),
@@ -198,15 +207,27 @@ class _FileInfoPanelState extends State<FileInfoPanel> {
const SizedBox(height: 16), const SizedBox(height: 16),
// 基本信息 // 基本信息
_buildInfoRow(LucideIcons.folderOpen, '位置', Uri.decodeComponent(file.relativePath)), _buildInfoRow(
LucideIcons.folderOpen,
'位置',
FileUtils.decodePathForDisplay(file.relativePath),
),
if (file.isFile) if (file.isFile)
_buildInfoRow( _buildInfoRow(
LucideIcons.hardDrive, LucideIcons.hardDrive,
'大小', '大小',
date_utils.DateUtils.formatFileSize(file.size), date_utils.DateUtils.formatFileSize(file.size),
), ),
_buildInfoRow(LucideIcons.calendarPlus, '创建时间', date_utils.DateUtils.formatDateTime(file.createdAt)), _buildInfoRow(
_buildInfoRow(LucideIcons.calendar, '修改时间', date_utils.DateUtils.formatDateTime(file.updatedAt)), LucideIcons.calendarPlus,
'创建时间',
date_utils.DateUtils.formatDateTime(file.createdAt),
),
_buildInfoRow(
LucideIcons.calendar,
'修改时间',
date_utils.DateUtils.formatDateTime(file.updatedAt),
),
if (file.owned != null) if (file.owned != null)
_buildInfoRow(LucideIcons.shield, '所有者', file.owned! ? '' : ''), _buildInfoRow(LucideIcons.shield, '所有者', file.owned! ? '' : ''),
@@ -215,7 +236,12 @@ class _FileInfoPanelState extends State<FileInfoPanel> {
const SizedBox(height: 12), const SizedBox(height: 12),
Divider(color: theme.dividerColor.withValues(alpha: 0.3)), Divider(color: theme.dividerColor.withValues(alpha: 0.3)),
const SizedBox(height: 8), const SizedBox(height: 8),
Text('扩展信息', style: theme.textTheme.titleSmall?.copyWith(fontWeight: FontWeight.w600)), Text(
'扩展信息',
style: theme.textTheme.titleSmall?.copyWith(
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: 8), const SizedBox(height: 8),
_buildInfoRow(LucideIcons.fingerprint, '文件ID', file.id), _buildInfoRow(LucideIcons.fingerprint, '文件ID', file.id),
if (file.primaryEntity != null) if (file.primaryEntity != null)
@@ -247,7 +273,12 @@ class _FileInfoPanelState extends State<FileInfoPanel> {
const SizedBox(height: 12), const SizedBox(height: 12),
Divider(color: theme.dividerColor.withValues(alpha: 0.3)), Divider(color: theme.dividerColor.withValues(alpha: 0.3)),
const SizedBox(height: 8), const SizedBox(height: 8),
Text('文件夹信息', style: theme.textTheme.titleSmall?.copyWith(fontWeight: FontWeight.w600)), Text(
'文件夹信息',
style: theme.textTheme.titleSmall?.copyWith(
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: 8), const SizedBox(height: 8),
_buildFolderSummary(theme, colorScheme), _buildFolderSummary(theme, colorScheme),
], ],
@@ -270,7 +301,12 @@ class _FileInfoPanelState extends State<FileInfoPanel> {
children: [ children: [
Row( Row(
children: [ children: [
Text('版本历史', style: theme.textTheme.titleSmall?.copyWith(fontWeight: FontWeight.w600)), Text(
'版本历史',
style: theme.textTheme.titleSmall?.copyWith(
fontWeight: FontWeight.w600,
),
),
const SizedBox(width: 8), const SizedBox(width: 8),
Container( Container(
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 1), padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 1),
@@ -318,7 +354,9 @@ class _FileInfoPanelState extends State<FileInfoPanel> {
required bool isPreviewable, required bool isPreviewable,
required FileModel file, required FileModel file,
}) { }) {
final shortId = entity.id.length > 6 ? entity.id.substring(0, 6) : entity.id; final shortId = entity.id.length > 6
? entity.id.substring(0, 6)
: entity.id;
final createdBy = entity.createdBy?.nickname ?? '未知'; final createdBy = entity.createdBy?.nickname ?? '未知';
return Container( return Container(
@@ -340,24 +378,32 @@ class _FileInfoPanelState extends State<FileInfoPanel> {
_buildVersionActionButton( _buildVersionActionButton(
icon: LucideIcons.externalLink, icon: LucideIcons.externalLink,
tooltip: '打开', tooltip: '打开',
onPressed: _isVersionLoading ? null : () => _openVersion(entity), onPressed: _isVersionLoading
? null
: () => _openVersion(entity),
), ),
_buildVersionActionButton( _buildVersionActionButton(
icon: LucideIcons.download, icon: LucideIcons.download,
tooltip: '下载', tooltip: '下载',
onPressed: _isVersionLoading ? null : () => _downloadVersion(entity), onPressed: _isVersionLoading
? null
: () => _downloadVersion(entity),
), ),
if (!isCurrent) ...[ if (!isCurrent) ...[
_buildVersionActionButton( _buildVersionActionButton(
icon: LucideIcons.pin, icon: LucideIcons.pin,
tooltip: '设为当前版本', tooltip: '设为当前版本',
onPressed: _isVersionLoading ? null : () => _setCurrentVersion(entity), onPressed: _isVersionLoading
? null
: () => _setCurrentVersion(entity),
), ),
_buildVersionActionButton( _buildVersionActionButton(
icon: LucideIcons.trash2, icon: LucideIcons.trash2,
tooltip: '删除', tooltip: '删除',
color: colorScheme.error, color: colorScheme.error,
onPressed: _isVersionLoading ? null : () => _deleteVersion(entity), onPressed: _isVersionLoading
? null
: () => _deleteVersion(entity),
), ),
], ],
]; ];
@@ -403,8 +449,10 @@ class _FileInfoPanelState extends State<FileInfoPanel> {
const SizedBox(height: 1), const SizedBox(height: 1),
Text( Text(
'${date_utils.DateUtils.formatDateTime(entity.createdAt)} · $createdBy', '${date_utils.DateUtils.formatDateTime(entity.createdAt)} · $createdBy',
style: const TextStyle(fontSize: 11, color: null) style: const TextStyle(
.copyWith(color: theme.hintColor), fontSize: 11,
color: null,
).copyWith(color: theme.hintColor),
maxLines: 1, maxLines: 1,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),
@@ -449,14 +497,26 @@ class _FileInfoPanelState extends State<FileInfoPanel> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
_buildInfoRow(LucideIcons.hash, 'ID', entity.id), _buildInfoRow(LucideIcons.hash, 'ID', entity.id),
_buildInfoRow(LucideIcons.hardDrive, '大小', date_utils.DateUtils.formatFileSize(entity.size)), _buildInfoRow(
_buildInfoRow(LucideIcons.calendarPlus, '创建时间', date_utils.DateUtils.formatDateTime(entity.createdAt)), LucideIcons.hardDrive,
'大小',
date_utils.DateUtils.formatFileSize(entity.size),
),
_buildInfoRow(
LucideIcons.calendarPlus,
'创建时间',
date_utils.DateUtils.formatDateTime(entity.createdAt),
),
if (createdBy != null) ...[ if (createdBy != null) ...[
_buildInfoRow(LucideIcons.user, '创建者', createdBy.nickname), _buildInfoRow(LucideIcons.user, '创建者', createdBy.nickname),
_buildInfoRow(LucideIcons.fingerprint, '创建者ID', createdBy.id), _buildInfoRow(LucideIcons.fingerprint, '创建者ID', createdBy.id),
], ],
if (entity.storagePolicy != null) if (entity.storagePolicy != null)
_buildInfoRow(LucideIcons.server, '存储策略', '${entity.storagePolicy!.name} (${entity.storagePolicy!.type})'), _buildInfoRow(
LucideIcons.server,
'存储策略',
'${entity.storagePolicy!.name} (${entity.storagePolicy!.type})',
),
if (entity.encryptedWith != null) if (entity.encryptedWith != null)
_buildInfoRow(LucideIcons.lock, '加密', entity.encryptedWith!), _buildInfoRow(LucideIcons.lock, '加密', entity.encryptedWith!),
], ],
@@ -508,9 +568,13 @@ class _FileInfoPanelState extends State<FileInfoPanel> {
} else if (FileTypeUtils.isAudio(file.name)) { } else if (FileTypeUtils.isAudio(file.name)) {
Navigator.of(context).pushNamed(RouteNames.audioPreview, arguments: args); Navigator.of(context).pushNamed(RouteNames.audioPreview, arguments: args);
} else if (FileTypeUtils.isMarkdown(file.name)) { } else if (FileTypeUtils.isMarkdown(file.name)) {
Navigator.of(context).pushNamed(RouteNames.markdownPreview, arguments: args); Navigator.of(
context,
).pushNamed(RouteNames.markdownPreview, arguments: args);
} else if (FileTypeUtils.isTextCode(file.name)) { } else if (FileTypeUtils.isTextCode(file.name)) {
Navigator.of(context).pushNamed(RouteNames.documentPreview, arguments: args); Navigator.of(
context,
).pushNamed(RouteNames.documentPreview, arguments: args);
} }
} }
@@ -561,12 +625,16 @@ class _FileInfoPanelState extends State<FileInfoPanel> {
Future<void> _deleteVersion(EntityModel entity) async { Future<void> _deleteVersion(EntityModel entity) async {
final colorScheme = Theme.of(context).colorScheme; final colorScheme = Theme.of(context).colorScheme;
final shortId = entity.id.length > 6 ? entity.id.substring(0, 6) : entity.id; final shortId = entity.id.length > 6
? entity.id.substring(0, 6)
: entity.id;
final confirmed = await showDialog<bool>( final confirmed = await showDialog<bool>(
context: context, context: context,
builder: (dialogContext) => AlertDialog( builder: (dialogContext) => AlertDialog(
title: const Text('删除版本'), title: const Text('删除版本'),
content: Text('确定要删除版本 "$shortId" (${date_utils.DateUtils.formatFileSize(entity.size)}) 吗?'), content: Text(
'确定要删除版本 "$shortId" (${date_utils.DateUtils.formatFileSize(entity.size)}) 吗?',
),
actions: [ actions: [
TextButton( TextButton(
onPressed: () => Navigator.of(dialogContext).pop(false), onPressed: () => Navigator.of(dialogContext).pop(false),
@@ -611,15 +679,29 @@ class _FileInfoPanelState extends State<FileInfoPanel> {
children: [ children: [
_buildInfoRow(LucideIcons.file, '包含文件', '${summary.files}'), _buildInfoRow(LucideIcons.file, '包含文件', '${summary.files}'),
_buildInfoRow(LucideIcons.folder, '包含文件夹', '${summary.folders}'), _buildInfoRow(LucideIcons.folder, '包含文件夹', '${summary.folders}'),
_buildInfoRow(LucideIcons.hardDrive, '总大小', date_utils.DateUtils.formatFileSize(summary.size)), _buildInfoRow(
LucideIcons.hardDrive,
'总大小',
date_utils.DateUtils.formatFileSize(summary.size),
),
if (!summary.completed) if (!summary.completed)
Padding( Padding(
padding: const EdgeInsets.only(top: 8), padding: const EdgeInsets.only(top: 8),
child: Row( child: Row(
children: [ children: [
Icon(LucideIcons.alertCircle, size: 14, color: theme.colorScheme.error), Icon(
LucideIcons.alertCircle,
size: 14,
color: theme.colorScheme.error,
),
const SizedBox(width: 6), const SizedBox(width: 6),
Text('计算未完成,结果可能不完整', style: TextStyle(fontSize: 12, color: theme.colorScheme.error)), Text(
'计算未完成,结果可能不完整',
style: TextStyle(
fontSize: 12,
color: theme.colorScheme.error,
),
),
], ],
), ),
), ),
@@ -633,7 +715,12 @@ class _FileInfoPanelState extends State<FileInfoPanel> {
} }
return _isCalculatingFolder return _isCalculatingFolder
? const Center(child: Padding(padding: EdgeInsets.all(16), child: CircularProgressIndicator())) ? const Center(
child: Padding(
padding: EdgeInsets.all(16),
child: CircularProgressIndicator(),
),
)
: SizedBox( : SizedBox(
width: double.infinity, width: double.infinity,
child: OutlinedButton.icon( child: OutlinedButton.icon(
@@ -655,13 +742,13 @@ class _FileInfoPanelState extends State<FileInfoPanel> {
const SizedBox(width: 8), const SizedBox(width: 8),
SizedBox( SizedBox(
width: 72, width: 72,
child: Text(label, style: TextStyle(fontSize: 13, color: theme.hintColor)), child: Text(
label,
style: TextStyle(fontSize: 13, color: theme.hintColor),
),
), ),
Expanded( Expanded(
child: SelectableText( child: SelectableText(value, style: const TextStyle(fontSize: 13)),
value,
style: const TextStyle(fontSize: 13),
),
), ),
], ],
), ),
+26 -12
View File
@@ -2,6 +2,7 @@ import 'package:cloudreve4_flutter/data/models/file_model.dart';
import 'package:cloudreve4_flutter/services/file_service.dart'; import 'package:cloudreve4_flutter/services/file_service.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../core/utils/app_logger.dart'; import '../../core/utils/app_logger.dart';
import '../../core/utils/file_utils.dart';
/// 文件夹选择器 /// 文件夹选择器
class FolderPicker extends StatefulWidget { class FolderPicker extends StatefulWidget {
@@ -61,7 +62,7 @@ class _FolderPickerState extends State<FolderPicker> {
void _enterFolder(FileModel folder) { void _enterFolder(FileModel folder) {
setState(() { setState(() {
_currentPath = folder.path; _currentPath = folder.relativePath;
}); });
_loadFolders(); _loadFolders();
} }
@@ -80,7 +81,10 @@ class _FolderPickerState extends State<FolderPicker> {
child: ConstrainedBox( child: ConstrainedBox(
constraints: BoxConstraints( constraints: BoxConstraints(
maxHeight: widget.maxVisibleItems != null maxHeight: widget.maxVisibleItems != null
? (widget.maxVisibleItems! * 56.0 + 40.0).clamp(80.0, maxHeight) ? (widget.maxVisibleItems! * 56.0 + 40.0).clamp(
80.0,
maxHeight,
)
: maxHeight, : maxHeight,
), ),
child: _buildListContent(context, primaryColor), child: _buildListContent(context, primaryColor),
@@ -108,7 +112,10 @@ class _FolderPickerState extends State<FolderPicker> {
children: [ children: [
Icon(Icons.folder_off, size: 48, color: Colors.grey.shade400), Icon(Icons.folder_off, size: 48, color: Colors.grey.shade400),
const SizedBox(height: 12), const SizedBox(height: 12),
Text('此文件夹为空', style: TextStyle(color: Colors.grey.shade600, fontSize: 14)), Text(
'此文件夹为空',
style: TextStyle(color: Colors.grey.shade600, fontSize: 14),
),
], ],
), ),
); );
@@ -146,7 +153,13 @@ class _FolderPickerState extends State<FolderPicker> {
), ),
const SizedBox(width: 12), const SizedBox(width: 12),
Expanded( Expanded(
child: Text(folder.name, style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w500)), child: Text(
folder.name,
style: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
),
),
), ),
Icon(Icons.chevron_right, color: Colors.grey.shade400, size: 20), Icon(Icons.chevron_right, color: Colors.grey.shade400, size: 20),
], ],
@@ -156,7 +169,7 @@ class _FolderPickerState extends State<FolderPicker> {
} }
Widget _buildBreadcrumb(BuildContext context, Color primaryColor) { Widget _buildBreadcrumb(BuildContext context, Color primaryColor) {
final pathParts = _currentPath.split('/'); final pathParts = FileUtils.toRelativePath(_currentPath).split('/');
pathParts.removeWhere((part) => part.isEmpty); pathParts.removeWhere((part) => part.isEmpty);
return Column( return Column(
@@ -180,8 +193,8 @@ class _FolderPickerState extends State<FolderPicker> {
), ),
...pathParts.asMap().entries.expand((entry) { ...pathParts.asMap().entries.expand((entry) {
final index = entry.key; final index = entry.key;
final part = entry.value; final path =
final path = '/${pathParts.sublist(0, index + 1).join('/')}'; '/${pathParts.sublist(0, index + 1).join('/')}';
return [ return [
Padding( Padding(
@@ -194,7 +207,7 @@ class _FolderPickerState extends State<FolderPicker> {
), ),
_buildBreadcrumbItem( _buildBreadcrumbItem(
context, context,
name: part, name: FileUtils.decodePathSegment(entry.value),
path: path, path: path,
isLast: index == pathParts.length - 1, isLast: index == pathParts.length - 1,
primaryColor: primaryColor, primaryColor: primaryColor,
@@ -208,13 +221,14 @@ class _FolderPickerState extends State<FolderPicker> {
const SizedBox(width: 12), const SizedBox(width: 12),
FilledButton.tonal( FilledButton.tonal(
onPressed: () { onPressed: () {
final relative = _currentPath.startsWith('cloudreve://my') final relative = FileUtils.toRelativePath(_currentPath);
? _currentPath.replaceFirst('cloudreve://my', '')
: _currentPath;
widget.onFolderSelected(relative.isEmpty ? '/' : relative); widget.onFolderSelected(relative.isEmpty ? '/' : relative);
}, },
style: FilledButton.styleFrom( style: FilledButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 8,
),
), ),
child: const Text('选择'), child: const Text('选择'),
), ),
+41 -27
View File
@@ -6,6 +6,7 @@ import 'package:provider/provider.dart';
import '../../core/utils/date_utils.dart' as date_utils; import '../../core/utils/date_utils.dart' as date_utils;
import '../../core/utils/file_icon_utils.dart'; import '../../core/utils/file_icon_utils.dart';
import '../../core/utils/file_utils.dart';
import '../../data/models/file_model.dart'; import '../../data/models/file_model.dart';
import '../../services/file_service.dart'; import '../../services/file_service.dart';
import '../../services/storage_service.dart'; import '../../services/storage_service.dart';
@@ -38,7 +39,8 @@ class SearchDialog extends StatefulWidget {
child: FadeTransition(opacity: fadeAnim, child: child), child: FadeTransition(opacity: fadeAnim, child: child),
); );
}, },
pageBuilder: (context, animation, secondaryAnimation) => const SearchDialog(), pageBuilder: (context, animation, secondaryAnimation) =>
const SearchDialog(),
); );
} }
@@ -145,8 +147,10 @@ class _SearchDialogState extends State<SearchDialog> {
// 在 async gap 之前获取所有引用 // 在 async gap 之前获取所有引用
final navProvider = Provider.of<NavigationProvider>(context, listen: false); final navProvider = Provider.of<NavigationProvider>(context, listen: false);
final fileManager = final fileManager = Provider.of<FileManagerProvider>(
Provider.of<FileManagerProvider>(context, listen: false); context,
listen: false,
);
final parentPath = _extractParentPath(file.path); final parentPath = _extractParentPath(file.path);
final filePath = file.path; final filePath = file.path;
@@ -286,16 +290,20 @@ class _SearchDialogState extends State<SearchDialog> {
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Icon(LucideIcons.alertCircle, Icon(
size: 40, color: colorScheme.error.withValues(alpha: 0.7)), LucideIcons.alertCircle,
size: 40,
color: colorScheme.error.withValues(alpha: 0.7),
),
const SizedBox(height: 8), const SizedBox(height: 8),
Text(_errorMessage!, Text(
style: TextStyle(color: theme.hintColor), _errorMessage!,
textAlign: TextAlign.center), style: TextStyle(color: theme.hintColor),
textAlign: TextAlign.center,
),
const SizedBox(height: 12), const SizedBox(height: 12),
FilledButton.tonal( FilledButton.tonal(
onPressed: () => onPressed: () => _performSearch(_searchController.text.trim()),
_performSearch(_searchController.text.trim()),
child: const Text('重试'), child: const Text('重试'),
), ),
], ],
@@ -316,12 +324,13 @@ class _SearchDialogState extends State<SearchDialog> {
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Icon(LucideIcons.searchX, Icon(
size: 40, LucideIcons.searchX,
color: theme.hintColor.withValues(alpha: 0.5)), size: 40,
color: theme.hintColor.withValues(alpha: 0.5),
),
const SizedBox(height: 8), const SizedBox(height: 8),
Text('未找到匹配文件', Text('未找到匹配文件', style: TextStyle(color: theme.hintColor)),
style: TextStyle(color: theme.hintColor)),
], ],
), ),
), ),
@@ -330,8 +339,7 @@ class _SearchDialogState extends State<SearchDialog> {
return Padding( return Padding(
padding: const EdgeInsets.symmetric(vertical: 32), padding: const EdgeInsets.symmetric(vertical: 32),
child: Center( child: Center(
child: Text('输入关键词搜索文件', child: Text('输入关键词搜索文件', style: TextStyle(color: theme.hintColor)),
style: TextStyle(color: theme.hintColor)),
), ),
); );
} }
@@ -364,17 +372,21 @@ class _SearchDialogState extends State<SearchDialog> {
children: [ children: [
Icon(LucideIcons.history, size: 16, color: theme.hintColor), Icon(LucideIcons.history, size: 16, color: theme.hintColor),
const SizedBox(width: 6), const SizedBox(width: 6),
Text('搜索历史', Text(
style: TextStyle( '搜索历史',
fontSize: 13, style: TextStyle(
fontWeight: FontWeight.w500, fontSize: 13,
color: theme.hintColor)), fontWeight: FontWeight.w500,
color: theme.hintColor,
),
),
const Spacer(), const Spacer(),
GestureDetector( GestureDetector(
onTap: _clearHistory, onTap: _clearHistory,
child: Text('清除', child: Text(
style: '清除',
TextStyle(fontSize: 12, color: colorScheme.primary)), style: TextStyle(fontSize: 12, color: colorScheme.primary),
),
), ),
], ],
), ),
@@ -416,13 +428,15 @@ class _SearchDialogState extends State<SearchDialog> {
Text( Text(
file.name, file.name,
style: const TextStyle( style: const TextStyle(
fontWeight: FontWeight.w500, fontSize: 14), fontWeight: FontWeight.w500,
fontSize: 14,
),
maxLines: 1, maxLines: 1,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),
const SizedBox(height: 2), const SizedBox(height: 2),
Text( Text(
Uri.decodeComponent(file.relativePath), FileUtils.decodePathForDisplay(file.relativePath),
style: TextStyle(fontSize: 12, color: theme.hintColor), style: TextStyle(fontSize: 12, color: theme.hintColor),
maxLines: 1, maxLines: 1,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
+1 -1
View File
@@ -213,7 +213,7 @@ class FileService {
int? pageSize, int? pageSize,
}) async { }) async {
// 构造搜索 URI: cloudreve://my?name=xxx // 构造搜索 URI: cloudreve://my?name=xxx
final cloudreveUri = '${FileUtils.toCloudreveUri(uri)}?name=$name'; final cloudreveUri = FileUtils.toCloudreveUriWithQuery(uri, {'name': name});
final params = <String, dynamic>{ final params = <String, dynamic>{
'uri': cloudreveUri, 'uri': cloudreveUri,
+32
View File
@@ -0,0 +1,32 @@
import 'package:cloudreve4_flutter/core/utils/file_utils.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('FileUtils', () {
test('decodePathForDisplay decodes encoded Chinese segments', () {
expect(
FileUtils.decodePathForDisplay(
'/%E4%B8%AD%E6%96%87/%E8%B5%84%E6%96%99',
),
'/\u4e2d\u6587/\u8d44\u6599',
);
});
test('decodePathForDisplay leaves malformed percent sequences safe', () {
expect(FileUtils.decodePathForDisplay('/100%/reports'), '/100%/reports');
});
test('toCloudreveUriWithQuery encodes query values', () {
final uri = FileUtils.toCloudreveUriWithQuery('/folder', {
'name': '\u4e2d\u6587 \u6587\u6863',
});
expect(uri, contains('cloudreve://my/folder?name='));
expect(uri, contains('%E4%B8%AD%E6%96%87'));
expect(
Uri.parse(uri).queryParameters['name'],
'\u4e2d\u6587 \u6587\u6863',
);
});
});
}