From b80d91825aa1a968f6135dc83133eaa43fa01a14 Mon Sep 17 00:00:00 2001 From: Texas0295 Date: Sun, 21 Sep 2025 20:29:20 +0800 Subject: [PATCH] migrate file upload from tus to FileUploader API The tus-based upload flow (/drive/tus) has been removed upstream in favor of a new multipart upload protocol. This commit replaces all TusClient usage with the new FileUploader service that follows the official /drive/files/upload/{create,chunk,complete} endpoints. Changes include: - remove tus_client_dart dependency and related code - add putFileToPool() backed by FileUploader.uploadFile() - update uploadAttachment() to call the new putFileToPool - preserve poolId support, filename, and mimetype handling - ensure progress callbacks fire at start and completion This aligns the client with the new upload protocol while keeping the same Compose UI and settings logic introduced in earlier patches. Signed-off-by: Texas0295 --- lib/services/file.dart | 46 +++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/services/file.dart b/lib/services/file.dart index ffc26090..a2ac2a26 100644 --- a/lib/services/file.dart +++ b/lib/services/file.dart @@ -50,7 +50,6 @@ Completer putFileToPool({ Function(double progress, Duration estimate)? onProgress, }) { final completer = Completer(); - final data = fileData.data; if (data is! XFile) { completer.completeError( @@ -62,33 +61,34 @@ Completer putFileToPool({ final actualFilename = filename ?? data.name; final actualMimetype = mimetype ?? data.mimeType ?? 'application/octet-stream'; - final metadata = { - 'filename': actualFilename, - 'content-type': actualMimetype, - }; + final dio = Dio(BaseOptions( + baseUrl: baseUrl, + headers: { + 'Authorization': 'AtField $atk', + 'Accept': 'application/json', + }, + )); - final client = TusClient(data); - client - .upload( - uri: Uri.parse('$baseUrl/drive/tus'), - headers: { - 'Authorization': 'AtField $atk', - 'X-FilePool': poolId, - }, - metadata: metadata, - onComplete: (lastResponse) { - final resp = jsonDecode(lastResponse!.headers['x-fileinfo']!); - completer.complete(SnCloudFile.fromJson(resp)); - }, - onProgress: (progress, est) { - onProgress?.call(progress, est); - }, - ) - .catchError(completer.completeError); + final uploader = FileUploader(dio); + final fileObj = File(data.path); + + onProgress?.call(0.0, Duration.zero); + uploader.uploadFile( + file: fileObj, + fileName: actualFilename, + contentType: actualMimetype, + poolId: poolId, + ).then((result) { + onProgress?.call(1.0, Duration.zero); + completer.complete(result); + }).catchError((e) { + completer.completeError(e); + }); return completer; } + Completer putMediaToCloud({ required UniversalFile fileData, required String atk,