Skip to content

Commit

Permalink
♻️refactor(http): add network security & include messages (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
SantiagoGaonaC committed Oct 24, 2023
1 parent 7e53442 commit d191be3
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 20 deletions.
1 change: 1 addition & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher"
android:requestLegacyExternalStorage="true"
android:networkSecurityConfig="@xml/network_security_config"
android:usesCleartextTraffic="true">
<activity
android:name=".MainActivity"
Expand Down
5 changes: 5 additions & 0 deletions android/app/src/main/res/xml/network_security_config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">capyfile1.bucaramanga.upb.edu.co</domain>
</domain-config>
</network-security-config>
16 changes: 11 additions & 5 deletions lib/features/auth/presentation/providers/share_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,18 @@ class ShareNotifier extends StateNotifier<ShareState> {
}

Future<bool> unShareFile(String fileUUID, String otherUsername) async {
removeUserFromShareList(
otherUsername); //Todo: remove here when delete endpoint is done
try {
await fileRepository.unShareFile(fileUUID, otherUsername);
//TODO: using here removeUserFromShareList(otherUsername);
return true;
final response =
await fileRepository.unShareFile(fileUUID, otherUsername);
if (response) {
removeUserFromShareList(otherUsername);
state = state.copyWith(errorMessage: '');
return true;
} else {
state = state.copyWith(
errorMessage: 'Error when using unShareFile, response is false');
}
return false;
} on CustomError catch (e) {
state = state.copyWith(errorMessage: e.message);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ class FilesDatasourceImpl extends FileDataSource {
if (e.type == DioExceptionType.connectionTimeout) {
throw CustomError('Review your internet connection');
}


throw Exception(e.toString());
} catch (e) {
throw Exception(e.toString());
Expand All @@ -320,6 +322,9 @@ class FilesDatasourceImpl extends FileDataSource {
if (e.type == DioExceptionType.connectionTimeout) {
throw CustomError('Review your internet connection');
}
if (e.response?.statusCode == 500) {
throw CustomError('Internal Server Error');
}
throw Exception(e.toString());
} catch (e) {
throw Exception(e.toString());
Expand All @@ -345,7 +350,10 @@ class FilesDatasourceImpl extends FileDataSource {
throw CustomError('Token Wrong');
}
if (e.response?.statusCode == 404) {
throw CustomError('File $fileUUID not found');
throw CustomError('File $fileUUID not found (Server)');
}
if (e.response?.statusCode == 500) {
throw CustomError('Internal Server Error');
}
if (e.type == DioExceptionType.connectionTimeout) {
throw CustomError('Review your internet connection');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,15 @@ class FilesGetNotifier extends StateNotifier<FilesGetState> {
}

Future<bool> deleteFile(List<String> fileUUID) async {
removeFileFromfilesList(fileUUID); //Todo: remove here when delete endpoint is done
try {
final response = await filesRepository.deleteFile(fileUUID);
//TODO: using here removeFileFromfilesList(fileUUID);
return response;
if (response) {
removeFileFromfilesList(fileUUID);
return true;
} else {
state = state.copyWith(errorMessage: 'Failed to delete file');
return false;
}
} on CustomError catch (e) {
state = state.copyWith(errorMessage: e.message);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,22 @@ class FileOrFolderWidgetState extends ConsumerState<FilesTwoColumnsView> {
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: Text(
widget.file.name,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 16),
textAlign: TextAlign.center,
Flexible(
child: Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: Text(
widget.file.name,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 16),
textAlign: TextAlign.center,
),
),
),
],
),


],
),
),
Expand Down
3 changes: 1 addition & 2 deletions lib/features/shared/widgets/drive/dialog_rename_folder.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:login_mobile/features/shared/shared.dart';

class DialogWidget extends StatelessWidget {
final String? title;
Expand All @@ -18,7 +17,7 @@ class DialogWidget extends StatelessWidget {

@override
Widget build(BuildContext context) {
final textStyles = Theme.of(context).textTheme;
//final textStyles = Theme.of(context).textTheme;

return AlertDialog(
title: Text(title ?? ''),
Expand Down
7 changes: 6 additions & 1 deletion windows/flutter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ include(${EPHEMERAL_DIR}/generated_config.cmake)
# https://github.com/flutter/flutter/issues/57146.
set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper")

# Set fallback configurations for older versions of the flutter tool.
if (NOT DEFINED FLUTTER_TARGET_PLATFORM)
set(FLUTTER_TARGET_PLATFORM "windows-x64")
endif()

# === Flutter Library ===
set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll")

Expand Down Expand Up @@ -92,7 +97,7 @@ add_custom_command(
COMMAND ${CMAKE_COMMAND} -E env
${FLUTTER_TOOL_ENVIRONMENT}
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
windows-x64 $<CONFIG>
${FLUTTER_TARGET_PLATFORM} $<CONFIG>
VERBATIM
)
add_custom_target(flutter_assemble DEPENDS
Expand Down

0 comments on commit d191be3

Please sign in to comment.