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 <kimura@texas0295.top>
This commit is contained in:
Texas0295
2025-09-21 20:29:20 +08:00
parent 1a703b7eba
commit b80d91825a

View File

@@ -50,7 +50,6 @@ Completer<SnCloudFile?> putFileToPool({
Function(double progress, Duration estimate)? onProgress, Function(double progress, Duration estimate)? onProgress,
}) { }) {
final completer = Completer<SnCloudFile?>(); final completer = Completer<SnCloudFile?>();
final data = fileData.data; final data = fileData.data;
if (data is! XFile) { if (data is! XFile) {
completer.completeError( completer.completeError(
@@ -62,33 +61,34 @@ Completer<SnCloudFile?> putFileToPool({
final actualFilename = filename ?? data.name; final actualFilename = filename ?? data.name;
final actualMimetype = mimetype ?? data.mimeType ?? 'application/octet-stream'; final actualMimetype = mimetype ?? data.mimeType ?? 'application/octet-stream';
final metadata = { final dio = Dio(BaseOptions(
'filename': actualFilename, baseUrl: baseUrl,
'content-type': actualMimetype, headers: {
}; 'Authorization': 'AtField $atk',
'Accept': 'application/json',
},
));
final client = TusClient(data); final uploader = FileUploader(dio);
client final fileObj = File(data.path);
.upload(
uri: Uri.parse('$baseUrl/drive/tus'), onProgress?.call(0.0, Duration.zero);
headers: { uploader.uploadFile(
'Authorization': 'AtField $atk', file: fileObj,
'X-FilePool': poolId, fileName: actualFilename,
}, contentType: actualMimetype,
metadata: metadata, poolId: poolId,
onComplete: (lastResponse) { ).then((result) {
final resp = jsonDecode(lastResponse!.headers['x-fileinfo']!); onProgress?.call(1.0, Duration.zero);
completer.complete(SnCloudFile.fromJson(resp)); completer.complete(result);
}, }).catchError((e) {
onProgress: (progress, est) { completer.completeError(e);
onProgress?.call(progress, est); });
},
)
.catchError(completer.completeError);
return completer; return completer;
} }
Completer<SnCloudFile?> putMediaToCloud({ Completer<SnCloudFile?> putMediaToCloud({
required UniversalFile fileData, required UniversalFile fileData,
required String atk, required String atk,