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:
@@ -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,
|
|
||||||
};
|
|
||||||
|
|
||||||
final client = TusClient(data);
|
|
||||||
client
|
|
||||||
.upload(
|
|
||||||
uri: Uri.parse('$baseUrl/drive/tus'),
|
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'AtField $atk',
|
'Authorization': 'AtField $atk',
|
||||||
'X-FilePool': poolId,
|
'Accept': 'application/json',
|
||||||
},
|
},
|
||||||
metadata: metadata,
|
));
|
||||||
onComplete: (lastResponse) {
|
|
||||||
final resp = jsonDecode(lastResponse!.headers['x-fileinfo']!);
|
final uploader = FileUploader(dio);
|
||||||
completer.complete(SnCloudFile.fromJson(resp));
|
final fileObj = File(data.path);
|
||||||
},
|
|
||||||
onProgress: (progress, est) {
|
onProgress?.call(0.0, Duration.zero);
|
||||||
onProgress?.call(progress, est);
|
uploader.uploadFile(
|
||||||
},
|
file: fileObj,
|
||||||
)
|
fileName: actualFilename,
|
||||||
.catchError(completer.completeError);
|
contentType: actualMimetype,
|
||||||
|
poolId: poolId,
|
||||||
|
).then((result) {
|
||||||
|
onProgress?.call(1.0, Duration.zero);
|
||||||
|
completer.complete(result);
|
||||||
|
}).catchError((e) {
|
||||||
|
completer.completeError(e);
|
||||||
|
});
|
||||||
|
|
||||||
return completer;
|
return completer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Completer<SnCloudFile?> putMediaToCloud({
|
Completer<SnCloudFile?> putMediaToCloud({
|
||||||
required UniversalFile fileData,
|
required UniversalFile fileData,
|
||||||
required String atk,
|
required String atk,
|
||||||
|
Reference in New Issue
Block a user