二次开发源码提交

This commit is contained in:
2026-05-15 08:52:48 +08:00
parent 4131f7321a
commit eb35a1d067
191 changed files with 34566 additions and 0 deletions
@@ -0,0 +1,103 @@
import 'dart:io';
import 'package:flutter/material.dart';
import '../../data/models/upload_task_model.dart';
import '../../services/upload_service.dart';
/// 上传管理Provider
class UploadManagerProvider extends ChangeNotifier {
final UploadService _uploadService = UploadService.instance;
bool _isInitialized = false;
bool _shouldShowDialog = false;
bool get showUploadDialog => _shouldShowDialog && _uploadService.allTasks.isNotEmpty;
List<UploadTaskModel> get allTasks => _uploadService.allTasks;
List<UploadTaskModel> get activeTasks => _uploadService.activeTasks;
/// 初始化上传管理器
Future<void> initialize() async {
if (_isInitialized) return;
await _uploadService.initialize();
_uploadService.addListener(_onServiceChanged);
_isInitialized = true;
}
void _onServiceChanged() {
notifyListeners();
}
/// 标记应该显示对话框
void markShouldShowDialog() {
_shouldShowDialog = true;
notifyListeners();
}
/// 隐藏对话框
void hideDialog() {
_shouldShowDialog = false;
notifyListeners();
}
/// 开始上传
Future<void> startUpload(
List<File> files,
String targetPath,
) async {
for (final file in files) {
// 构建目标路径 URI
String uri;
if (targetPath.startsWith('cloudreve://my')) {
uri = targetPath;
} else {
// 移除前导斜杠避免重复
String pathPart = targetPath;
if (pathPart.startsWith('/')) {
pathPart = pathPart.substring(1);
}
uri = pathPart.isEmpty ? 'cloudreve://my' : 'cloudreve://my/$pathPart';
}
final task = UploadTaskModel(
id: DateTime.now().millisecondsSinceEpoch.toString() + file.path,
file: file,
fileName: file.uri.pathSegments.last,
fileSize: await file.length(),
targetPath: uri,
);
_uploadService.addTask(task);
// 开始上传任务
_uploadService.startUpload(task);
}
}
/// 取消上传
void cancelUpload(String taskId) {
_uploadService.cancelUpload(taskId);
}
/// 重试上传
void retryUpload(String taskId) {
_uploadService.retryUpload(taskId);
}
/// 删除任务
void removeTask(String taskId) {
_uploadService.removeTask(taskId);
}
/// 清除所有已完成的任务
void clearCompletedTasks() {
_uploadService.clearCompletedTasks();
}
/// 清除失败的任务
void clearFailedTasks() {
_uploadService.clearFailedTasks();
}
@override
void dispose() {
_uploadService.removeListener(_onServiceChanged);
super.dispose();
}
}