Skip to content

Commit

Permalink
TW-313: apply new file streams encryption
Browse files Browse the repository at this point in the history
  • Loading branch information
sherlockvn authored and hoangdat committed Aug 3, 2023
1 parent 22e69c4 commit 9acf5ea
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 217 deletions.
40 changes: 0 additions & 40 deletions lib/data/network/upload_file/file_info.dart

This file was deleted.

16 changes: 16 additions & 0 deletions lib/data/network/upload_file/file_info_extension.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

import 'package:flutter/foundation.dart';
import 'package:matrix/matrix.dart';
import 'package:mime/mime.dart';

extension FileInfoExtension on FileInfo {

String get fileExtension => fileName.split('.').last;

String get mimeType => lookupMimeType(kIsWeb ? fileName : filePath) ?? 'application/octet-stream';

Map<String, dynamic> get metadata => ({
'mimetype': mimeType,
'size': fileSize,
});
}
4 changes: 2 additions & 2 deletions lib/data/network/upload_file/upload_file_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:dio/dio.dart';
import 'package:fluffychat/data/model/upload_file_json.dart';
import 'package:fluffychat/data/network/dio_client.dart';
import 'package:fluffychat/data/network/homeserver_endpoint.dart';
import 'package:fluffychat/data/network/upload_file/file_info.dart';
import 'package:fluffychat/data/network/upload_file/file_info_extension.dart';
import 'package:fluffychat/di/global/get_it_initializer.dart';
import 'package:fluffychat/di/global/network_di.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_file_extension.dart';
Expand All @@ -24,7 +24,7 @@ class UploadFileAPI {
HomeserverEndpoint.uploadMediaServicePath.generateHomeserverIdentityEndpoint(),
data: fileInfo.readStream ?? File(fileInfo.filePath).openRead(),
queryParameters: {
fileName: fileInfo.fileName,
'fileName': fileInfo.fileName,
},
options: Options(headers: dioHeaders)
).onError((error, stackTrace) => throw Exception(error));
Expand Down
6 changes: 3 additions & 3 deletions lib/domain/usecase/room/upload_content_interactor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ class UploadContentInteractor {
final matrixFile = await entity.toMatrixFile();
final mediaConfig = await matrixClient.getConfig();
final maxMediaSize = mediaConfig.mUploadSize;
if (matrixFile != null) {
final fileSize = matrixFile.bytes.length;
if (matrixFile != null && matrixFile.bytes != null) {
final fileSize = matrixFile.bytes!.length;
Logs().d('SendImage::sendImageFileEvent(): FileSized $fileSize || maxMediaSize $maxMediaSize');
if (maxMediaSize != null && maxMediaSize < fileSize) {
yield Left(FileTooBigMatrix(FileTooBigMatrixException(fileSize, maxMediaSize)));
}
final uri = await matrixClient.uploadContent(
matrixFile.bytes,
matrixFile.bytes!,
filename: matrixFile.name,
contentType: matrixFile.mimeType,
);
Expand Down
6 changes: 0 additions & 6 deletions lib/domain/usecase/send_file_interactor.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@

import 'dart:convert';
import 'dart:typed_data';

import 'package:file_picker/file_picker.dart';
import 'package:fluffychat/data/network/upload_file/file_info.dart';
import 'package:fluffychat/presentation/extensions/room_extension.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_file_extension.dart';
import 'package:matrix/matrix.dart';
import 'package:path_provider/path_provider.dart';

Expand Down
26 changes: 0 additions & 26 deletions lib/domain/usecase/upload_file_interactor.dart

This file was deleted.

1 change: 0 additions & 1 deletion lib/pages/chat/events/message_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ class MessageContent extends StatelessWidget {
);
}
final filePath = event.getFilePath();
debugPrint('filePath: $filePath');
if (filePath != null) {
return SendingImageWidget(
filePath: filePath,
Expand Down
6 changes: 2 additions & 4 deletions lib/presentation/extensions/asset_entity_extension.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import 'dart:convert';
import 'dart:typed_data';

import 'package:fluffychat/data/network/upload_file/file_info.dart';
import 'package:fluffychat/presentation/model/image_type.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_file_extension.dart';
import 'package:fluffychat/data/network/upload_file/file_info_extension.dart';
import 'package:matrix/matrix.dart';
import 'package:photo_manager/photo_manager.dart';

Expand All @@ -27,7 +25,7 @@ extension AssetEntityExtension on AssetEntity {
return null;
}
return FileInfo(
fileName,
file.path.split('/').last,
file.path,
file.lengthSync()
);
Expand Down
Loading

0 comments on commit 9acf5ea

Please sign in to comment.