From b8d24876c8c01bc720ea8aa28bdd0a05f5febd11 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 10 Nov 2025 01:56:22 +0800 Subject: [PATCH] :truck: Rename upload task to drive task --- .../{upload_task.dart => drive_task.dart} | 20 ++-- ...k.freezed.dart => drive_task.freezed.dart} | 108 +++++++++--------- .../{upload_task.g.dart => drive_task.g.dart} | 26 ++--- lib/pods/upload_tasks.dart | 50 ++++---- lib/widgets/upload_overlay.dart | 82 ++++++------- 5 files changed, 143 insertions(+), 143 deletions(-) rename lib/models/{upload_task.dart => drive_task.dart} (78%) rename lib/models/{upload_task.freezed.dart => drive_task.freezed.dart} (68%) rename lib/models/{upload_task.g.dart => drive_task.g.dart} (76%) diff --git a/lib/models/upload_task.dart b/lib/models/drive_task.dart similarity index 78% rename from lib/models/upload_task.dart rename to lib/models/drive_task.dart index c3f52268..c6f6f9a4 100644 --- a/lib/models/upload_task.dart +++ b/lib/models/drive_task.dart @@ -1,10 +1,10 @@ import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:island/models/file.dart'; -part 'upload_task.freezed.dart'; -part 'upload_task.g.dart'; +part 'drive_task.freezed.dart'; +part 'drive_task.g.dart'; -enum UploadTaskStatus { +enum DriveTaskStatus { pending, inProgress, paused, @@ -15,10 +15,10 @@ enum UploadTaskStatus { } @freezed -sealed class UploadTask with _$UploadTask { - const UploadTask._(); +sealed class DriveTask with _$DriveTask { + const DriveTask._(); - const factory UploadTask({ + const factory DriveTask({ required String id, required String taskId, required String fileName, @@ -27,7 +27,7 @@ sealed class UploadTask with _$UploadTask { required int uploadedBytes, required int totalChunks, required int uploadedChunks, - required UploadTaskStatus status, + required DriveTaskStatus status, required DateTime createdAt, required DateTime updatedAt, required String type, // Task type (e.g., 'FileUpload') @@ -38,10 +38,10 @@ sealed class UploadTask with _$UploadTask { String? bundleId, String? encryptPassword, String? expiredAt, - }) = _UploadTask; + }) = _DriveTask; - factory UploadTask.fromJson(Map json) => - _$UploadTaskFromJson(json); + factory DriveTask.fromJson(Map json) => + _$DriveTaskFromJson(json); double get progress => totalChunks > 0 ? uploadedChunks / totalChunks : 0.0; diff --git a/lib/models/upload_task.freezed.dart b/lib/models/drive_task.freezed.dart similarity index 68% rename from lib/models/upload_task.freezed.dart rename to lib/models/drive_task.freezed.dart index aad3187d..3f9752e8 100644 --- a/lib/models/upload_task.freezed.dart +++ b/lib/models/drive_task.freezed.dart @@ -3,7 +3,7 @@ // ignore_for_file: type=lint // ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark -part of 'upload_task.dart'; +part of 'drive_task.dart'; // ************************************************************************** // FreezedGenerator @@ -13,24 +13,24 @@ part of 'upload_task.dart'; T _$identity(T value) => value; /// @nodoc -mixin _$UploadTask { +mixin _$DriveTask { - String get id; String get taskId; String get fileName; String get contentType; int get fileSize; int get uploadedBytes; int get totalChunks; int get uploadedChunks; UploadTaskStatus get status; DateTime get createdAt; DateTime get updatedAt; String get type;// Task type (e.g., 'FileUpload') + String get id; String get taskId; String get fileName; String get contentType; int get fileSize; int get uploadedBytes; int get totalChunks; int get uploadedChunks; DriveTaskStatus get status; DateTime get createdAt; DateTime get updatedAt; String get type;// Task type (e.g., 'FileUpload') double? get transmissionProgress;// Local file upload progress (0.0-1.0) String? get errorMessage; SnCloudFile? get result; String? get poolId; String? get bundleId; String? get encryptPassword; String? get expiredAt; -/// Create a copy of UploadTask +/// Create a copy of DriveTask /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) @pragma('vm:prefer-inline') -$UploadTaskCopyWith get copyWith => _$UploadTaskCopyWithImpl(this as UploadTask, _$identity); +$DriveTaskCopyWith get copyWith => _$DriveTaskCopyWithImpl(this as DriveTask, _$identity); - /// Serializes this UploadTask to a JSON map. + /// Serializes this DriveTask to a JSON map. Map toJson(); @override bool operator ==(Object other) { - return identical(this, other) || (other.runtimeType == runtimeType&&other is UploadTask&&(identical(other.id, id) || other.id == id)&&(identical(other.taskId, taskId) || other.taskId == taskId)&&(identical(other.fileName, fileName) || other.fileName == fileName)&&(identical(other.contentType, contentType) || other.contentType == contentType)&&(identical(other.fileSize, fileSize) || other.fileSize == fileSize)&&(identical(other.uploadedBytes, uploadedBytes) || other.uploadedBytes == uploadedBytes)&&(identical(other.totalChunks, totalChunks) || other.totalChunks == totalChunks)&&(identical(other.uploadedChunks, uploadedChunks) || other.uploadedChunks == uploadedChunks)&&(identical(other.status, status) || other.status == status)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)&&(identical(other.type, type) || other.type == type)&&(identical(other.transmissionProgress, transmissionProgress) || other.transmissionProgress == transmissionProgress)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage)&&(identical(other.result, result) || other.result == result)&&(identical(other.poolId, poolId) || other.poolId == poolId)&&(identical(other.bundleId, bundleId) || other.bundleId == bundleId)&&(identical(other.encryptPassword, encryptPassword) || other.encryptPassword == encryptPassword)&&(identical(other.expiredAt, expiredAt) || other.expiredAt == expiredAt)); + return identical(this, other) || (other.runtimeType == runtimeType&&other is DriveTask&&(identical(other.id, id) || other.id == id)&&(identical(other.taskId, taskId) || other.taskId == taskId)&&(identical(other.fileName, fileName) || other.fileName == fileName)&&(identical(other.contentType, contentType) || other.contentType == contentType)&&(identical(other.fileSize, fileSize) || other.fileSize == fileSize)&&(identical(other.uploadedBytes, uploadedBytes) || other.uploadedBytes == uploadedBytes)&&(identical(other.totalChunks, totalChunks) || other.totalChunks == totalChunks)&&(identical(other.uploadedChunks, uploadedChunks) || other.uploadedChunks == uploadedChunks)&&(identical(other.status, status) || other.status == status)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)&&(identical(other.type, type) || other.type == type)&&(identical(other.transmissionProgress, transmissionProgress) || other.transmissionProgress == transmissionProgress)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage)&&(identical(other.result, result) || other.result == result)&&(identical(other.poolId, poolId) || other.poolId == poolId)&&(identical(other.bundleId, bundleId) || other.bundleId == bundleId)&&(identical(other.encryptPassword, encryptPassword) || other.encryptPassword == encryptPassword)&&(identical(other.expiredAt, expiredAt) || other.expiredAt == expiredAt)); } @JsonKey(includeFromJson: false, includeToJson: false) @@ -39,18 +39,18 @@ int get hashCode => Object.hashAll([runtimeType,id,taskId,fileName,contentType,f @override String toString() { - return 'UploadTask(id: $id, taskId: $taskId, fileName: $fileName, contentType: $contentType, fileSize: $fileSize, uploadedBytes: $uploadedBytes, totalChunks: $totalChunks, uploadedChunks: $uploadedChunks, status: $status, createdAt: $createdAt, updatedAt: $updatedAt, type: $type, transmissionProgress: $transmissionProgress, errorMessage: $errorMessage, result: $result, poolId: $poolId, bundleId: $bundleId, encryptPassword: $encryptPassword, expiredAt: $expiredAt)'; + return 'DriveTask(id: $id, taskId: $taskId, fileName: $fileName, contentType: $contentType, fileSize: $fileSize, uploadedBytes: $uploadedBytes, totalChunks: $totalChunks, uploadedChunks: $uploadedChunks, status: $status, createdAt: $createdAt, updatedAt: $updatedAt, type: $type, transmissionProgress: $transmissionProgress, errorMessage: $errorMessage, result: $result, poolId: $poolId, bundleId: $bundleId, encryptPassword: $encryptPassword, expiredAt: $expiredAt)'; } } /// @nodoc -abstract mixin class $UploadTaskCopyWith<$Res> { - factory $UploadTaskCopyWith(UploadTask value, $Res Function(UploadTask) _then) = _$UploadTaskCopyWithImpl; +abstract mixin class $DriveTaskCopyWith<$Res> { + factory $DriveTaskCopyWith(DriveTask value, $Res Function(DriveTask) _then) = _$DriveTaskCopyWithImpl; @useResult $Res call({ - String id, String taskId, String fileName, String contentType, int fileSize, int uploadedBytes, int totalChunks, int uploadedChunks, UploadTaskStatus status, DateTime createdAt, DateTime updatedAt, String type, double? transmissionProgress, String? errorMessage, SnCloudFile? result, String? poolId, String? bundleId, String? encryptPassword, String? expiredAt + String id, String taskId, String fileName, String contentType, int fileSize, int uploadedBytes, int totalChunks, int uploadedChunks, DriveTaskStatus status, DateTime createdAt, DateTime updatedAt, String type, double? transmissionProgress, String? errorMessage, SnCloudFile? result, String? poolId, String? bundleId, String? encryptPassword, String? expiredAt }); @@ -58,14 +58,14 @@ $SnCloudFileCopyWith<$Res>? get result; } /// @nodoc -class _$UploadTaskCopyWithImpl<$Res> - implements $UploadTaskCopyWith<$Res> { - _$UploadTaskCopyWithImpl(this._self, this._then); +class _$DriveTaskCopyWithImpl<$Res> + implements $DriveTaskCopyWith<$Res> { + _$DriveTaskCopyWithImpl(this._self, this._then); - final UploadTask _self; - final $Res Function(UploadTask) _then; + final DriveTask _self; + final $Res Function(DriveTask) _then; -/// Create a copy of UploadTask +/// Create a copy of DriveTask /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? taskId = null,Object? fileName = null,Object? contentType = null,Object? fileSize = null,Object? uploadedBytes = null,Object? totalChunks = null,Object? uploadedChunks = null,Object? status = null,Object? createdAt = null,Object? updatedAt = null,Object? type = null,Object? transmissionProgress = freezed,Object? errorMessage = freezed,Object? result = freezed,Object? poolId = freezed,Object? bundleId = freezed,Object? encryptPassword = freezed,Object? expiredAt = freezed,}) { return _then(_self.copyWith( @@ -78,7 +78,7 @@ as int,uploadedBytes: null == uploadedBytes ? _self.uploadedBytes : uploadedByte as int,totalChunks: null == totalChunks ? _self.totalChunks : totalChunks // ignore: cast_nullable_to_non_nullable as int,uploadedChunks: null == uploadedChunks ? _self.uploadedChunks : uploadedChunks // ignore: cast_nullable_to_non_nullable as int,status: null == status ? _self.status : status // ignore: cast_nullable_to_non_nullable -as UploadTaskStatus,createdAt: null == createdAt ? _self.createdAt : createdAt // ignore: cast_nullable_to_non_nullable +as DriveTaskStatus,createdAt: null == createdAt ? _self.createdAt : createdAt // ignore: cast_nullable_to_non_nullable as DateTime,updatedAt: null == updatedAt ? _self.updatedAt : updatedAt // ignore: cast_nullable_to_non_nullable as DateTime,type: null == type ? _self.type : type // ignore: cast_nullable_to_non_nullable as String,transmissionProgress: freezed == transmissionProgress ? _self.transmissionProgress : transmissionProgress // ignore: cast_nullable_to_non_nullable @@ -91,7 +91,7 @@ as String?,expiredAt: freezed == expiredAt ? _self.expiredAt : expiredAt // igno as String?, )); } -/// Create a copy of UploadTask +/// Create a copy of DriveTask /// with the given fields replaced by the non-null parameter values. @override @pragma('vm:prefer-inline') @@ -107,8 +107,8 @@ $SnCloudFileCopyWith<$Res>? get result { } -/// Adds pattern-matching-related methods to [UploadTask]. -extension UploadTaskPatterns on UploadTask { +/// Adds pattern-matching-related methods to [DriveTask]. +extension DriveTaskPatterns on DriveTask { /// A variant of `map` that fallback to returning `orElse`. /// /// It is equivalent to doing: @@ -121,10 +121,10 @@ extension UploadTaskPatterns on UploadTask { /// } /// ``` -@optionalTypeArgs TResult maybeMap(TResult Function( _UploadTask value)? $default,{required TResult orElse(),}){ +@optionalTypeArgs TResult maybeMap(TResult Function( _DriveTask value)? $default,{required TResult orElse(),}){ final _that = this; switch (_that) { -case _UploadTask() when $default != null: +case _DriveTask() when $default != null: return $default(_that);case _: return orElse(); @@ -143,10 +143,10 @@ return $default(_that);case _: /// } /// ``` -@optionalTypeArgs TResult map(TResult Function( _UploadTask value) $default,){ +@optionalTypeArgs TResult map(TResult Function( _DriveTask value) $default,){ final _that = this; switch (_that) { -case _UploadTask(): +case _DriveTask(): return $default(_that);} } /// A variant of `map` that fallback to returning `null`. @@ -161,10 +161,10 @@ return $default(_that);} /// } /// ``` -@optionalTypeArgs TResult? mapOrNull(TResult? Function( _UploadTask value)? $default,){ +@optionalTypeArgs TResult? mapOrNull(TResult? Function( _DriveTask value)? $default,){ final _that = this; switch (_that) { -case _UploadTask() when $default != null: +case _DriveTask() when $default != null: return $default(_that);case _: return null; @@ -182,9 +182,9 @@ return $default(_that);case _: /// } /// ``` -@optionalTypeArgs TResult maybeWhen(TResult Function( String id, String taskId, String fileName, String contentType, int fileSize, int uploadedBytes, int totalChunks, int uploadedChunks, UploadTaskStatus status, DateTime createdAt, DateTime updatedAt, String type, double? transmissionProgress, String? errorMessage, SnCloudFile? result, String? poolId, String? bundleId, String? encryptPassword, String? expiredAt)? $default,{required TResult orElse(),}) {final _that = this; +@optionalTypeArgs TResult maybeWhen(TResult Function( String id, String taskId, String fileName, String contentType, int fileSize, int uploadedBytes, int totalChunks, int uploadedChunks, DriveTaskStatus status, DateTime createdAt, DateTime updatedAt, String type, double? transmissionProgress, String? errorMessage, SnCloudFile? result, String? poolId, String? bundleId, String? encryptPassword, String? expiredAt)? $default,{required TResult orElse(),}) {final _that = this; switch (_that) { -case _UploadTask() when $default != null: +case _DriveTask() when $default != null: return $default(_that.id,_that.taskId,_that.fileName,_that.contentType,_that.fileSize,_that.uploadedBytes,_that.totalChunks,_that.uploadedChunks,_that.status,_that.createdAt,_that.updatedAt,_that.type,_that.transmissionProgress,_that.errorMessage,_that.result,_that.poolId,_that.bundleId,_that.encryptPassword,_that.expiredAt);case _: return orElse(); @@ -203,9 +203,9 @@ return $default(_that.id,_that.taskId,_that.fileName,_that.contentType,_that.fil /// } /// ``` -@optionalTypeArgs TResult when(TResult Function( String id, String taskId, String fileName, String contentType, int fileSize, int uploadedBytes, int totalChunks, int uploadedChunks, UploadTaskStatus status, DateTime createdAt, DateTime updatedAt, String type, double? transmissionProgress, String? errorMessage, SnCloudFile? result, String? poolId, String? bundleId, String? encryptPassword, String? expiredAt) $default,) {final _that = this; +@optionalTypeArgs TResult when(TResult Function( String id, String taskId, String fileName, String contentType, int fileSize, int uploadedBytes, int totalChunks, int uploadedChunks, DriveTaskStatus status, DateTime createdAt, DateTime updatedAt, String type, double? transmissionProgress, String? errorMessage, SnCloudFile? result, String? poolId, String? bundleId, String? encryptPassword, String? expiredAt) $default,) {final _that = this; switch (_that) { -case _UploadTask(): +case _DriveTask(): return $default(_that.id,_that.taskId,_that.fileName,_that.contentType,_that.fileSize,_that.uploadedBytes,_that.totalChunks,_that.uploadedChunks,_that.status,_that.createdAt,_that.updatedAt,_that.type,_that.transmissionProgress,_that.errorMessage,_that.result,_that.poolId,_that.bundleId,_that.encryptPassword,_that.expiredAt);} } /// A variant of `when` that fallback to returning `null` @@ -220,9 +220,9 @@ return $default(_that.id,_that.taskId,_that.fileName,_that.contentType,_that.fil /// } /// ``` -@optionalTypeArgs TResult? whenOrNull(TResult? Function( String id, String taskId, String fileName, String contentType, int fileSize, int uploadedBytes, int totalChunks, int uploadedChunks, UploadTaskStatus status, DateTime createdAt, DateTime updatedAt, String type, double? transmissionProgress, String? errorMessage, SnCloudFile? result, String? poolId, String? bundleId, String? encryptPassword, String? expiredAt)? $default,) {final _that = this; +@optionalTypeArgs TResult? whenOrNull(TResult? Function( String id, String taskId, String fileName, String contentType, int fileSize, int uploadedBytes, int totalChunks, int uploadedChunks, DriveTaskStatus status, DateTime createdAt, DateTime updatedAt, String type, double? transmissionProgress, String? errorMessage, SnCloudFile? result, String? poolId, String? bundleId, String? encryptPassword, String? expiredAt)? $default,) {final _that = this; switch (_that) { -case _UploadTask() when $default != null: +case _DriveTask() when $default != null: return $default(_that.id,_that.taskId,_that.fileName,_that.contentType,_that.fileSize,_that.uploadedBytes,_that.totalChunks,_that.uploadedChunks,_that.status,_that.createdAt,_that.updatedAt,_that.type,_that.transmissionProgress,_that.errorMessage,_that.result,_that.poolId,_that.bundleId,_that.encryptPassword,_that.expiredAt);case _: return null; @@ -234,9 +234,9 @@ return $default(_that.id,_that.taskId,_that.fileName,_that.contentType,_that.fil /// @nodoc @JsonSerializable() -class _UploadTask extends UploadTask { - const _UploadTask({required this.id, required this.taskId, required this.fileName, required this.contentType, required this.fileSize, required this.uploadedBytes, required this.totalChunks, required this.uploadedChunks, required this.status, required this.createdAt, required this.updatedAt, required this.type, this.transmissionProgress, this.errorMessage, this.result, this.poolId, this.bundleId, this.encryptPassword, this.expiredAt}): super._(); - factory _UploadTask.fromJson(Map json) => _$UploadTaskFromJson(json); +class _DriveTask extends DriveTask { + const _DriveTask({required this.id, required this.taskId, required this.fileName, required this.contentType, required this.fileSize, required this.uploadedBytes, required this.totalChunks, required this.uploadedChunks, required this.status, required this.createdAt, required this.updatedAt, required this.type, this.transmissionProgress, this.errorMessage, this.result, this.poolId, this.bundleId, this.encryptPassword, this.expiredAt}): super._(); + factory _DriveTask.fromJson(Map json) => _$DriveTaskFromJson(json); @override final String id; @override final String taskId; @@ -246,7 +246,7 @@ class _UploadTask extends UploadTask { @override final int uploadedBytes; @override final int totalChunks; @override final int uploadedChunks; -@override final UploadTaskStatus status; +@override final DriveTaskStatus status; @override final DateTime createdAt; @override final DateTime updatedAt; @override final String type; @@ -260,20 +260,20 @@ class _UploadTask extends UploadTask { @override final String? encryptPassword; @override final String? expiredAt; -/// Create a copy of UploadTask +/// Create a copy of DriveTask /// with the given fields replaced by the non-null parameter values. @override @JsonKey(includeFromJson: false, includeToJson: false) @pragma('vm:prefer-inline') -_$UploadTaskCopyWith<_UploadTask> get copyWith => __$UploadTaskCopyWithImpl<_UploadTask>(this, _$identity); +_$DriveTaskCopyWith<_DriveTask> get copyWith => __$DriveTaskCopyWithImpl<_DriveTask>(this, _$identity); @override Map toJson() { - return _$UploadTaskToJson(this, ); + return _$DriveTaskToJson(this, ); } @override bool operator ==(Object other) { - return identical(this, other) || (other.runtimeType == runtimeType&&other is _UploadTask&&(identical(other.id, id) || other.id == id)&&(identical(other.taskId, taskId) || other.taskId == taskId)&&(identical(other.fileName, fileName) || other.fileName == fileName)&&(identical(other.contentType, contentType) || other.contentType == contentType)&&(identical(other.fileSize, fileSize) || other.fileSize == fileSize)&&(identical(other.uploadedBytes, uploadedBytes) || other.uploadedBytes == uploadedBytes)&&(identical(other.totalChunks, totalChunks) || other.totalChunks == totalChunks)&&(identical(other.uploadedChunks, uploadedChunks) || other.uploadedChunks == uploadedChunks)&&(identical(other.status, status) || other.status == status)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)&&(identical(other.type, type) || other.type == type)&&(identical(other.transmissionProgress, transmissionProgress) || other.transmissionProgress == transmissionProgress)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage)&&(identical(other.result, result) || other.result == result)&&(identical(other.poolId, poolId) || other.poolId == poolId)&&(identical(other.bundleId, bundleId) || other.bundleId == bundleId)&&(identical(other.encryptPassword, encryptPassword) || other.encryptPassword == encryptPassword)&&(identical(other.expiredAt, expiredAt) || other.expiredAt == expiredAt)); + return identical(this, other) || (other.runtimeType == runtimeType&&other is _DriveTask&&(identical(other.id, id) || other.id == id)&&(identical(other.taskId, taskId) || other.taskId == taskId)&&(identical(other.fileName, fileName) || other.fileName == fileName)&&(identical(other.contentType, contentType) || other.contentType == contentType)&&(identical(other.fileSize, fileSize) || other.fileSize == fileSize)&&(identical(other.uploadedBytes, uploadedBytes) || other.uploadedBytes == uploadedBytes)&&(identical(other.totalChunks, totalChunks) || other.totalChunks == totalChunks)&&(identical(other.uploadedChunks, uploadedChunks) || other.uploadedChunks == uploadedChunks)&&(identical(other.status, status) || other.status == status)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)&&(identical(other.type, type) || other.type == type)&&(identical(other.transmissionProgress, transmissionProgress) || other.transmissionProgress == transmissionProgress)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage)&&(identical(other.result, result) || other.result == result)&&(identical(other.poolId, poolId) || other.poolId == poolId)&&(identical(other.bundleId, bundleId) || other.bundleId == bundleId)&&(identical(other.encryptPassword, encryptPassword) || other.encryptPassword == encryptPassword)&&(identical(other.expiredAt, expiredAt) || other.expiredAt == expiredAt)); } @JsonKey(includeFromJson: false, includeToJson: false) @@ -282,18 +282,18 @@ int get hashCode => Object.hashAll([runtimeType,id,taskId,fileName,contentType,f @override String toString() { - return 'UploadTask(id: $id, taskId: $taskId, fileName: $fileName, contentType: $contentType, fileSize: $fileSize, uploadedBytes: $uploadedBytes, totalChunks: $totalChunks, uploadedChunks: $uploadedChunks, status: $status, createdAt: $createdAt, updatedAt: $updatedAt, type: $type, transmissionProgress: $transmissionProgress, errorMessage: $errorMessage, result: $result, poolId: $poolId, bundleId: $bundleId, encryptPassword: $encryptPassword, expiredAt: $expiredAt)'; + return 'DriveTask(id: $id, taskId: $taskId, fileName: $fileName, contentType: $contentType, fileSize: $fileSize, uploadedBytes: $uploadedBytes, totalChunks: $totalChunks, uploadedChunks: $uploadedChunks, status: $status, createdAt: $createdAt, updatedAt: $updatedAt, type: $type, transmissionProgress: $transmissionProgress, errorMessage: $errorMessage, result: $result, poolId: $poolId, bundleId: $bundleId, encryptPassword: $encryptPassword, expiredAt: $expiredAt)'; } } /// @nodoc -abstract mixin class _$UploadTaskCopyWith<$Res> implements $UploadTaskCopyWith<$Res> { - factory _$UploadTaskCopyWith(_UploadTask value, $Res Function(_UploadTask) _then) = __$UploadTaskCopyWithImpl; +abstract mixin class _$DriveTaskCopyWith<$Res> implements $DriveTaskCopyWith<$Res> { + factory _$DriveTaskCopyWith(_DriveTask value, $Res Function(_DriveTask) _then) = __$DriveTaskCopyWithImpl; @override @useResult $Res call({ - String id, String taskId, String fileName, String contentType, int fileSize, int uploadedBytes, int totalChunks, int uploadedChunks, UploadTaskStatus status, DateTime createdAt, DateTime updatedAt, String type, double? transmissionProgress, String? errorMessage, SnCloudFile? result, String? poolId, String? bundleId, String? encryptPassword, String? expiredAt + String id, String taskId, String fileName, String contentType, int fileSize, int uploadedBytes, int totalChunks, int uploadedChunks, DriveTaskStatus status, DateTime createdAt, DateTime updatedAt, String type, double? transmissionProgress, String? errorMessage, SnCloudFile? result, String? poolId, String? bundleId, String? encryptPassword, String? expiredAt }); @@ -301,17 +301,17 @@ $Res call({ } /// @nodoc -class __$UploadTaskCopyWithImpl<$Res> - implements _$UploadTaskCopyWith<$Res> { - __$UploadTaskCopyWithImpl(this._self, this._then); +class __$DriveTaskCopyWithImpl<$Res> + implements _$DriveTaskCopyWith<$Res> { + __$DriveTaskCopyWithImpl(this._self, this._then); - final _UploadTask _self; - final $Res Function(_UploadTask) _then; + final _DriveTask _self; + final $Res Function(_DriveTask) _then; -/// Create a copy of UploadTask +/// Create a copy of DriveTask /// with the given fields replaced by the non-null parameter values. @override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? taskId = null,Object? fileName = null,Object? contentType = null,Object? fileSize = null,Object? uploadedBytes = null,Object? totalChunks = null,Object? uploadedChunks = null,Object? status = null,Object? createdAt = null,Object? updatedAt = null,Object? type = null,Object? transmissionProgress = freezed,Object? errorMessage = freezed,Object? result = freezed,Object? poolId = freezed,Object? bundleId = freezed,Object? encryptPassword = freezed,Object? expiredAt = freezed,}) { - return _then(_UploadTask( + return _then(_DriveTask( id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable as String,taskId: null == taskId ? _self.taskId : taskId // ignore: cast_nullable_to_non_nullable as String,fileName: null == fileName ? _self.fileName : fileName // ignore: cast_nullable_to_non_nullable @@ -321,7 +321,7 @@ as int,uploadedBytes: null == uploadedBytes ? _self.uploadedBytes : uploadedByte as int,totalChunks: null == totalChunks ? _self.totalChunks : totalChunks // ignore: cast_nullable_to_non_nullable as int,uploadedChunks: null == uploadedChunks ? _self.uploadedChunks : uploadedChunks // ignore: cast_nullable_to_non_nullable as int,status: null == status ? _self.status : status // ignore: cast_nullable_to_non_nullable -as UploadTaskStatus,createdAt: null == createdAt ? _self.createdAt : createdAt // ignore: cast_nullable_to_non_nullable +as DriveTaskStatus,createdAt: null == createdAt ? _self.createdAt : createdAt // ignore: cast_nullable_to_non_nullable as DateTime,updatedAt: null == updatedAt ? _self.updatedAt : updatedAt // ignore: cast_nullable_to_non_nullable as DateTime,type: null == type ? _self.type : type // ignore: cast_nullable_to_non_nullable as String,transmissionProgress: freezed == transmissionProgress ? _self.transmissionProgress : transmissionProgress // ignore: cast_nullable_to_non_nullable @@ -335,7 +335,7 @@ as String?, )); } -/// Create a copy of UploadTask +/// Create a copy of DriveTask /// with the given fields replaced by the non-null parameter values. @override @pragma('vm:prefer-inline') diff --git a/lib/models/upload_task.g.dart b/lib/models/drive_task.g.dart similarity index 76% rename from lib/models/upload_task.g.dart rename to lib/models/drive_task.g.dart index 57f517be..82e74e73 100644 --- a/lib/models/upload_task.g.dart +++ b/lib/models/drive_task.g.dart @@ -1,12 +1,12 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'upload_task.dart'; +part of 'drive_task.dart'; // ************************************************************************** // JsonSerializableGenerator // ************************************************************************** -_UploadTask _$UploadTaskFromJson(Map json) => _UploadTask( +_DriveTask _$DriveTaskFromJson(Map json) => _DriveTask( id: json['id'] as String, taskId: json['task_id'] as String, fileName: json['file_name'] as String, @@ -15,7 +15,7 @@ _UploadTask _$UploadTaskFromJson(Map json) => _UploadTask( uploadedBytes: (json['uploaded_bytes'] as num).toInt(), totalChunks: (json['total_chunks'] as num).toInt(), uploadedChunks: (json['uploaded_chunks'] as num).toInt(), - status: $enumDecode(_$UploadTaskStatusEnumMap, json['status']), + status: $enumDecode(_$DriveTaskStatusEnumMap, json['status']), createdAt: DateTime.parse(json['created_at'] as String), updatedAt: DateTime.parse(json['updated_at'] as String), type: json['type'] as String, @@ -31,7 +31,7 @@ _UploadTask _$UploadTaskFromJson(Map json) => _UploadTask( expiredAt: json['expired_at'] as String?, ); -Map _$UploadTaskToJson(_UploadTask instance) => +Map _$DriveTaskToJson(_DriveTask instance) => { 'id': instance.id, 'task_id': instance.taskId, @@ -41,7 +41,7 @@ Map _$UploadTaskToJson(_UploadTask instance) => 'uploaded_bytes': instance.uploadedBytes, 'total_chunks': instance.totalChunks, 'uploaded_chunks': instance.uploadedChunks, - 'status': _$UploadTaskStatusEnumMap[instance.status]!, + 'status': _$DriveTaskStatusEnumMap[instance.status]!, 'created_at': instance.createdAt.toIso8601String(), 'updated_at': instance.updatedAt.toIso8601String(), 'type': instance.type, @@ -54,12 +54,12 @@ Map _$UploadTaskToJson(_UploadTask instance) => 'expired_at': instance.expiredAt, }; -const _$UploadTaskStatusEnumMap = { - UploadTaskStatus.pending: 'pending', - UploadTaskStatus.inProgress: 'inProgress', - UploadTaskStatus.paused: 'paused', - UploadTaskStatus.completed: 'completed', - UploadTaskStatus.failed: 'failed', - UploadTaskStatus.expired: 'expired', - UploadTaskStatus.cancelled: 'cancelled', +const _$DriveTaskStatusEnumMap = { + DriveTaskStatus.pending: 'pending', + DriveTaskStatus.inProgress: 'inProgress', + DriveTaskStatus.paused: 'paused', + DriveTaskStatus.completed: 'completed', + DriveTaskStatus.failed: 'failed', + DriveTaskStatus.expired: 'expired', + DriveTaskStatus.cancelled: 'cancelled', }; diff --git a/lib/pods/upload_tasks.dart b/lib/pods/upload_tasks.dart index 558e08ad..9e48f78e 100644 --- a/lib/pods/upload_tasks.dart +++ b/lib/pods/upload_tasks.dart @@ -3,18 +3,18 @@ import 'dart:typed_data'; import 'package:cross_file/cross_file.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:island/models/file.dart'; -import 'package:island/models/upload_task.dart'; +import 'package:island/models/drive_task.dart'; import 'package:island/pods/network.dart'; import 'package:island/pods/websocket.dart'; import 'package:island/services/file_uploader.dart'; import 'package:island/talker.dart'; final uploadTasksProvider = - StateNotifierProvider>( + StateNotifierProvider>( (ref) => UploadTasksNotifier(ref), ); -class UploadTasksNotifier extends StateNotifier> { +class UploadTasksNotifier extends StateNotifier> { final Ref ref; StreamSubscription? _websocketSubscription; final Map> _pendingUploads = {}; @@ -73,7 +73,7 @@ class UploadTasksNotifier extends StateNotifier> { state.map((task) { if (task.taskId == taskId) { return task.copyWith( - status: UploadTaskStatus.pending, + status: DriveTaskStatus.pending, updatedAt: DateTime.now(), ); } @@ -89,7 +89,7 @@ class UploadTasksNotifier extends StateNotifier> { if (metadata != null) { talker.info('[UploadTasks] Creating task with full metadata'); // Create task with full metadata - final uploadTask = UploadTask( + final uploadTask = DriveTask( id: DateTime.now().millisecondsSinceEpoch.toString(), taskId: taskId, fileName: metadata['fileName'] as String, @@ -98,7 +98,7 @@ class UploadTasksNotifier extends StateNotifier> { uploadedBytes: 0, totalChunks: metadata['totalChunks'] as int, uploadedChunks: 0, - status: UploadTaskStatus.pending, + status: DriveTaskStatus.pending, createdAt: DateTime.now(), updatedAt: DateTime.now(), type: 'FileUpload', @@ -117,7 +117,7 @@ class UploadTasksNotifier extends StateNotifier> { } else { talker.info('[UploadTasks] No metadata found, creating minimal task'); // Create minimal task if no metadata is stored - final uploadTask = UploadTask( + final uploadTask = DriveTask( id: DateTime.now().millisecondsSinceEpoch.toString(), taskId: taskId, fileName: data['name'] as String? ?? 'Unknown file', @@ -126,7 +126,7 @@ class UploadTasksNotifier extends StateNotifier> { uploadedBytes: 0, totalChunks: 0, uploadedChunks: 0, - status: UploadTaskStatus.pending, + status: DriveTaskStatus.pending, createdAt: DateTime.now(), updatedAt: DateTime.now(), type: 'FileUpload', @@ -148,7 +148,7 @@ class UploadTasksNotifier extends StateNotifier> { final uploadedBytes = (progress / 100.0 * task.fileSize).toInt(); return task.copyWith( uploadedBytes: uploadedBytes, - status: UploadTaskStatus.inProgress, + status: DriveTaskStatus.inProgress, updatedAt: DateTime.now(), ); } @@ -163,7 +163,7 @@ class UploadTasksNotifier extends StateNotifier> { state.map((task) { if (task.taskId == taskId) { return task.copyWith( - status: UploadTaskStatus.completed, + status: DriveTaskStatus.completed, uploadedChunks: task.totalChunks, uploadedBytes: task.fileSize, // Update file information from Results if available @@ -188,7 +188,7 @@ class UploadTasksNotifier extends StateNotifier> { state.map((task) { if (task.taskId == taskId) { return task.copyWith( - status: UploadTaskStatus.failed, + status: DriveTaskStatus.failed, errorMessage: errorMessage, updatedAt: DateTime.now(), ); @@ -197,7 +197,7 @@ class UploadTasksNotifier extends StateNotifier> { }).toList(); } - void addUploadTask(UploadTask task) { + void addUploadTask(DriveTask task) { state = [...state, task]; } @@ -226,7 +226,7 @@ class UploadTasksNotifier extends StateNotifier> { void updateTaskStatus( String taskId, - UploadTaskStatus status, { + DriveTaskStatus status, { String? errorMessage, }) { state = @@ -264,26 +264,26 @@ class UploadTasksNotifier extends StateNotifier> { state .where( (task) => - task.status != UploadTaskStatus.completed && - task.status != UploadTaskStatus.failed && - task.status != UploadTaskStatus.cancelled && - task.status != UploadTaskStatus.expired, + task.status != DriveTaskStatus.completed && + task.status != DriveTaskStatus.failed && + task.status != DriveTaskStatus.cancelled && + task.status != DriveTaskStatus.expired, ) .toList(); } - UploadTask? getTask(String taskId) { + DriveTask? getTask(String taskId) { return state.where((task) => task.taskId == taskId).firstOrNull; } - List getActiveTasks() { + List getActiveTasks() { return state .where( (task) => - task.status == UploadTaskStatus.pending || - task.status == UploadTaskStatus.inProgress || - task.status == UploadTaskStatus.paused || - task.status == UploadTaskStatus.completed, + task.status == DriveTaskStatus.pending || + task.status == DriveTaskStatus.inProgress || + task.status == DriveTaskStatus.paused || + task.status == DriveTaskStatus.completed, ) .toList(); } @@ -380,7 +380,7 @@ class EnhancedFileUploader extends FileUploader { createResponse['task_id'] as String? ?? 'existing-${DateTime.now().millisecondsSinceEpoch}'; - final uploadTask = UploadTask( + final uploadTask = DriveTask( id: DateTime.now().millisecondsSinceEpoch.toString(), taskId: taskId, fileName: fileName, @@ -389,7 +389,7 @@ class EnhancedFileUploader extends FileUploader { uploadedBytes: totalSize, totalChunks: 1, // For existing files, we consider it as 1 chunk uploadedChunks: 1, - status: UploadTaskStatus.completed, + status: DriveTaskStatus.completed, createdAt: DateTime.now(), updatedAt: DateTime.now(), type: 'FileUpload', diff --git a/lib/widgets/upload_overlay.dart b/lib/widgets/upload_overlay.dart index ed92a812..a442420f 100644 --- a/lib/widgets/upload_overlay.dart +++ b/lib/widgets/upload_overlay.dart @@ -4,7 +4,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:gap/gap.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; -import 'package:island/models/upload_task.dart'; +import 'package:island/models/drive_task.dart'; import 'package:island/pods/upload_tasks.dart'; import 'package:island/services/responsive.dart'; import 'package:material_symbols_icons/material_symbols_icons.dart'; @@ -20,10 +20,10 @@ class UploadOverlay extends HookConsumerWidget { uploadTasks .where( (task) => - task.status == UploadTaskStatus.pending || - task.status == UploadTaskStatus.inProgress || - task.status == UploadTaskStatus.paused || - task.status == UploadTaskStatus.completed, + task.status == DriveTaskStatus.pending || + task.status == DriveTaskStatus.inProgress || + task.status == DriveTaskStatus.paused || + task.status == DriveTaskStatus.completed, ) .toList() ..sort((a, b) => b.createdAt.compareTo(a.createdAt)); // Newest first @@ -67,7 +67,7 @@ class UploadOverlay extends HookConsumerWidget { } class _UploadOverlayContent extends HookConsumerWidget { - final List activeTasks; + final List activeTasks; const _UploadOverlayContent({required this.activeTasks}); @@ -290,46 +290,46 @@ class _UploadOverlayContent extends HookConsumerWidget { ); } - double _getOverallProgress(List tasks) { + double _getOverallProgress(List tasks) { if (tasks.isEmpty) return 0.0; final totalProgress = tasks.fold( 0.0, (sum, task) => sum + - (task.status == UploadTaskStatus.inProgress + (task.status == DriveTaskStatus.inProgress ? task.progress - : task.status == UploadTaskStatus.completed + : task.status == DriveTaskStatus.completed ? 1 : 0), ); return totalProgress / tasks.length; } - String _getOverallProgressText(List tasks) { + String _getOverallProgressText(List tasks) { final overallProgress = _getOverallProgress(tasks); return '${(overallProgress * 100).toStringAsFixed(0)}%'; } - IconData _getOverallStatusIcon(List tasks) { + IconData _getOverallStatusIcon(List tasks) { if (tasks.isEmpty) return Symbols.upload; final hasInProgress = tasks.any( - (task) => task.status == UploadTaskStatus.inProgress, + (task) => task.status == DriveTaskStatus.inProgress, ); final hasPending = tasks.any( - (task) => task.status == UploadTaskStatus.pending, + (task) => task.status == DriveTaskStatus.pending, ); final hasPaused = tasks.any( - (task) => task.status == UploadTaskStatus.paused, + (task) => task.status == DriveTaskStatus.paused, ); final hasFailed = tasks.any( (task) => - task.status == UploadTaskStatus.failed || - task.status == UploadTaskStatus.cancelled || - task.status == UploadTaskStatus.expired, + task.status == DriveTaskStatus.failed || + task.status == DriveTaskStatus.cancelled || + task.status == DriveTaskStatus.expired, ); final hasCompleted = tasks.any( - (task) => task.status == UploadTaskStatus.completed, + (task) => task.status == DriveTaskStatus.completed, ); // Priority order: in progress > pending > paused > failed > completed @@ -348,26 +348,26 @@ class _UploadOverlayContent extends HookConsumerWidget { } } - String _getOverallStatusText(List tasks) { + String _getOverallStatusText(List tasks) { if (tasks.isEmpty) return '0 tasks'; final hasInProgress = tasks.any( - (task) => task.status == UploadTaskStatus.inProgress, + (task) => task.status == DriveTaskStatus.inProgress, ); final hasPending = tasks.any( - (task) => task.status == UploadTaskStatus.pending, + (task) => task.status == DriveTaskStatus.pending, ); final hasPaused = tasks.any( - (task) => task.status == UploadTaskStatus.paused, + (task) => task.status == DriveTaskStatus.paused, ); final hasFailed = tasks.any( (task) => - task.status == UploadTaskStatus.failed || - task.status == UploadTaskStatus.cancelled || - task.status == UploadTaskStatus.expired, + task.status == DriveTaskStatus.failed || + task.status == DriveTaskStatus.cancelled || + task.status == DriveTaskStatus.expired, ); final hasCompleted = tasks.any( - (task) => task.status == UploadTaskStatus.completed, + (task) => task.status == DriveTaskStatus.completed, ); // Priority order: in progress > pending > paused > failed > completed @@ -386,19 +386,19 @@ class _UploadOverlayContent extends HookConsumerWidget { } } - bool _hasCompletedTasks(List tasks) { + bool _hasCompletedTasks(List tasks) { return tasks.any( (task) => - task.status == UploadTaskStatus.completed || - task.status == UploadTaskStatus.failed || - task.status == UploadTaskStatus.cancelled || - task.status == UploadTaskStatus.expired, + task.status == DriveTaskStatus.completed || + task.status == DriveTaskStatus.failed || + task.status == DriveTaskStatus.cancelled || + task.status == DriveTaskStatus.expired, ); } } class UploadTaskTile extends StatefulWidget { - final UploadTask task; + final DriveTask task; const UploadTaskTile({super.key, required this.task}); @@ -507,31 +507,31 @@ class _UploadTaskTileState extends State Color color; switch (widget.task.status) { - case UploadTaskStatus.pending: + case DriveTaskStatus.pending: icon = Symbols.schedule; color = Theme.of(context).colorScheme.secondary; break; - case UploadTaskStatus.inProgress: + case DriveTaskStatus.inProgress: icon = Symbols.upload; color = Theme.of(context).colorScheme.primary; break; - case UploadTaskStatus.paused: + case DriveTaskStatus.paused: icon = Symbols.pause_circle; color = Theme.of(context).colorScheme.tertiary; break; - case UploadTaskStatus.completed: + case DriveTaskStatus.completed: icon = Symbols.check_circle; color = Colors.green; break; - case UploadTaskStatus.failed: + case DriveTaskStatus.failed: icon = Symbols.error; color = Theme.of(context).colorScheme.error; break; - case UploadTaskStatus.cancelled: + case DriveTaskStatus.cancelled: icon = Symbols.cancel; color = Theme.of(context).colorScheme.error; break; - case UploadTaskStatus.expired: + case DriveTaskStatus.expired: icon = Symbols.timer_off; color = Theme.of(context).colorScheme.error; break; @@ -640,7 +640,7 @@ class _UploadTaskTileState extends State color: Theme.of(context).colorScheme.onSurfaceVariant, ), ), - if (widget.task.status == UploadTaskStatus.inProgress) + if (widget.task.status == DriveTaskStatus.inProgress) Text( 'ETA: ${_formatDuration(widget.task.estimatedTimeRemaining)}', style: Theme.of(context).textTheme.bodySmall?.copyWith( @@ -727,7 +727,7 @@ class _UploadTaskTileState extends State } } - String _formatBytesPerSecond(UploadTask task) { + String _formatBytesPerSecond(DriveTask task) { if (task.uploadedBytes == 0) return '0 B/s'; final elapsedSeconds = DateTime.now().difference(task.createdAt).inSeconds;