From 4e27368526c4f2117daf61ab6b993d247db7a6b6 Mon Sep 17 00:00:00 2001 From: Mati Date: Tue, 7 Nov 2023 14:37:02 -0300 Subject: [PATCH 1/6] feat(path utils): introduces getFileTypeFromMime and getBasenameWithoutExtension PE-4923 --- lib/src/utils/path_utils.dart | 10 ++++++++++ test/src/utils/path_utils_test.dart | 22 +++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/src/utils/path_utils.dart b/lib/src/utils/path_utils.dart index cb01cc0..85fe77b 100644 --- a/lib/src/utils/path_utils.dart +++ b/lib/src/utils/path_utils.dart @@ -88,6 +88,16 @@ String getFileExtension({ } } +String getFileTypeFromMime({ + required String contentType, +}) { + return contentType.substring(contentType.lastIndexOf('/') + 1); +} + +String getBasenameWithoutExtension(String fileName) { + return path.basenameWithoutExtension(fileName); +} + Future _getDefaultIOSDir() async { final iosDirectory = await path_provider.getApplicationDocumentsDirectory(); final iosDownloadsDirectory = Directory('${iosDirectory.path}/Downloads/'); diff --git a/test/src/utils/path_utils_test.dart b/test/src/utils/path_utils_test.dart index e773216..1aa86cf 100644 --- a/test/src/utils/path_utils_test.dart +++ b/test/src/utils/path_utils_test.dart @@ -3,7 +3,7 @@ import 'package:ardrive_io/src/utils/path_utils.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { - group('test method getFolderNameFromPath', () { + group('getFolderNameFromPath method', () { test('should return correct folder name', () { expect(getBasenameFromPath('some-folder'), 'some-folder'); expect(getBasenameFromPath('/some-folder'), 'some-folder'); @@ -17,7 +17,7 @@ void main() { throwsA(const TypeMatcher())); }); }); - group('test method getDirname', () { + group('getDirname method', () { test('should return correct dirname', () { expect(getDirname('/some-folder/file'), '/some-folder'); expect(getDirname('/some-folder/path/file.png'), '/some-folder/path'); @@ -32,7 +32,7 @@ void main() { }); }); - group('test method getFileExtension', () { + group('getFileExtension method', () { test('should return the extension from contentType and return with the .', () { /// .pdf @@ -112,4 +112,20 @@ void main() { expect(ext, 'conf'); }); }); + + group('getFileTypeFromMime method', () { + test('should return the file type from mimetype', () { + final type = getFileTypeFromMime(contentType: 'application/pdf'); + + expect(type, 'pdf'); + }); + }); + + group('getBasenameWithoutExtension method', () { + test('should return the basename without extension', () { + final basename = getBasenameWithoutExtension('file.pdf'); + + expect(basename, 'file'); + }); + }); } From 51ad6b3c3c0f1912857427ce9e37561def3ea62f Mon Sep 17 00:00:00 2001 From: Mati Date: Tue, 7 Nov 2023 14:55:17 -0300 Subject: [PATCH 2/6] feat(path utils): nit PE-4923 --- lib/src/utils/path_utils.dart | 8 +++----- test/src/utils/path_utils_test.dart | 4 +++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/src/utils/path_utils.dart b/lib/src/utils/path_utils.dart index 85fe77b..601c648 100644 --- a/lib/src/utils/path_utils.dart +++ b/lib/src/utils/path_utils.dart @@ -88,14 +88,12 @@ String getFileExtension({ } } -String getFileTypeFromMime({ - required String contentType, -}) { +String getFileTypeFromMime({required String contentType}) { return contentType.substring(contentType.lastIndexOf('/') + 1); } -String getBasenameWithoutExtension(String fileName) { - return path.basenameWithoutExtension(fileName); +String getBasenameWithoutExtension({required String filePath}) { + return path.basenameWithoutExtension(filePath); } Future _getDefaultIOSDir() async { diff --git a/test/src/utils/path_utils_test.dart b/test/src/utils/path_utils_test.dart index 1aa86cf..9964f0c 100644 --- a/test/src/utils/path_utils_test.dart +++ b/test/src/utils/path_utils_test.dart @@ -123,7 +123,9 @@ void main() { group('getBasenameWithoutExtension method', () { test('should return the basename without extension', () { - final basename = getBasenameWithoutExtension('file.pdf'); + final basename = getBasenameWithoutExtension( + filePath: '/hola/que/tal/file.pdf', + ); expect(basename, 'file'); }); From bd97a88d2aa356af75296727bb8883a9efd2b0f6 Mon Sep 17 00:00:00 2001 From: Mati Date: Tue, 7 Nov 2023 16:34:38 -0300 Subject: [PATCH 3/6] test(path utils): improves test cases PE-4923 --- test/src/utils/path_utils_test.dart | 38 ++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/test/src/utils/path_utils_test.dart b/test/src/utils/path_utils_test.dart index 9964f0c..06613f1 100644 --- a/test/src/utils/path_utils_test.dart +++ b/test/src/utils/path_utils_test.dart @@ -116,9 +116,18 @@ void main() { group('getFileTypeFromMime method', () { test('should return the file type from mimetype', () { final type = getFileTypeFromMime(contentType: 'application/pdf'); - expect(type, 'pdf'); }); + + test('should return the file type for a different mimetype', () { + final type = getFileTypeFromMime(contentType: 'image/jpeg'); + expect(type, 'jpeg'); + }); + + test('should return null for an empty string', () { + final type = getFileTypeFromMime(contentType: ''); + expect(type, ''); + }); }); group('getBasenameWithoutExtension method', () { @@ -126,8 +135,35 @@ void main() { final basename = getBasenameWithoutExtension( filePath: '/hola/que/tal/file.pdf', ); + expect(basename, 'file'); + }); + + test('should return the basename without extension', () { + final basename = getBasenameWithoutExtension( + filePath: '/hola/que/tal/file.pdf.txt', + ); + expect(basename, 'file.pdf'); + }); + + test('should return the basename for a different file path', () { + final basename = getBasenameWithoutExtension( + filePath: '/another/path/to/different.file', + ); + expect(basename, 'different'); + }); + test('should return the basename for a file path without extension', () { + final basename = getBasenameWithoutExtension( + filePath: '/path/to/file', + ); expect(basename, 'file'); }); + + test('should return an empty string for an empty string', () { + final basename = getBasenameWithoutExtension( + filePath: '', + ); + expect(basename, ''); + }); }); } From 58ea54d67916e1ef2eb6836037a988bfac47a7c0 Mon Sep 17 00:00:00 2001 From: Thiago Carvalho Date: Tue, 21 Nov 2023 16:20:15 -0300 Subject: [PATCH 4/6] chore: bump version --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 55339c7..2ccd40b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: ardrive_io description: A new Flutter package project. -version: 1.4.1 +version: 1.4.2 homepage: publish_to: none From 2d994b438523cfb34d085f590ec7eac8314bea3b Mon Sep 17 00:00:00 2001 From: Karl Prieb Date: Mon, 27 Nov 2023 10:39:21 -0300 Subject: [PATCH 5/6] update ardriveapp dependencies repo --- pubspec.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 2ccd40b..a2c58c6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -13,7 +13,7 @@ dependencies: sdk: flutter file_picker: git: - url: https://github.com/ar-io/flutter_file_picker + url: https://github.com/ardriveapp/flutter_file_picker ref: master path_provider: ^2.0.11 permission_handler: ^11.0.0 @@ -25,7 +25,7 @@ dependencies: security_scoped_resource: ^0.0.1 file_saver: git: - url: https://github.com/thiagocarvalhodev/file_saver + url: https://github.com/ardriveapp/file_saver ref: fix-extension device_info_plus: ^9.0.3 async: ^2.9.0 From bddc7a61d1f8a8bea0fbfb9fbf86b256ccfeaeab Mon Sep 17 00:00:00 2001 From: Thiago Carvalho Date: Mon, 27 Nov 2023 10:42:54 -0300 Subject: [PATCH 6/6] Update pubspec.yaml --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index a2c58c6..8e20cbe 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: ardrive_io description: A new Flutter package project. -version: 1.4.2 +version: 1.4.3 homepage: publish_to: none