-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
415c7ed
commit 9b8134e
Showing
14 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,3 +52,5 @@ pubspec.lock | |
firebase.json | ||
lib/firebase_options.dart | ||
firepit-log.txt | ||
|
||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import 'package:cloudinary/cloudinary.dart'; | ||
import 'package:poster/core/data/env/env.dart'; | ||
|
||
Cloudinary createCloudinaryClient() => | ||
Cloudinary.unsignedConfig(cloudName: Env.cloudinaryCloudName); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import 'package:cloudinary/cloudinary.dart'; | ||
import 'package:get_it/get_it.dart'; | ||
import 'package:poster/core/data/cloudinary/cloudinary_client.dart'; | ||
import 'package:poster/core/di/provide_singleton.dart'; | ||
|
||
extension CloudinaryModule on GetIt { | ||
List<Type> registerCloudinaryModule() => | ||
[provideSingleton<Cloudinary>(() => createCloudinaryClient())]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import 'package:envied/envied.dart'; | ||
|
||
part 'env.g.dart'; | ||
|
||
@envied | ||
final class Env { | ||
@EnviedField(varName: 'CLOUDINARY_CLOUD_NAME', obfuscate: true, defaultValue: 'placeholder') | ||
static final String cloudinaryCloudName = _Env.cloudinaryCloudName; | ||
|
||
@EnviedField(varName: 'CLOUDINARY_UPLOAD_PRESET', obfuscate: true, defaultValue: 'placeholder') | ||
static final String cloudinaryUploadPreset = _Env.cloudinaryUploadPreset; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import 'package:get_it/get_it.dart'; | ||
import 'package:poster/core/data/image/image_repository_impl.dart'; | ||
import 'package:poster/core/di/provide_singleton.dart'; | ||
import 'package:poster/core/domain/image/image_repository.dart'; | ||
|
||
extension ImageModule on GetIt { | ||
List<Type> registerImageModule() => [ | ||
provideSingleton<ImageRepository>(() => ImageRepositoryImpl(client: this())), | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'package:cloudinary/cloudinary.dart'; | ||
import 'package:fpdart/fpdart.dart'; | ||
import 'package:image_picker/image_picker.dart'; | ||
import 'package:poster/core/data/env/env.dart'; | ||
import 'package:poster/core/domain/image/image_repository.dart'; | ||
|
||
final class ImageRepositoryImpl extends ImageRepository { | ||
final Cloudinary _client; | ||
ImageRepositoryImpl({required Cloudinary client}) : _client = client; | ||
|
||
@override | ||
Future<Either<Exception, String>> upload(XFile file) async { | ||
final response = await _client.unsignedUpload( | ||
file: file.path, | ||
uploadPreset: Env.cloudinaryUploadPreset, | ||
fileBytes: await file.readAsBytes(), | ||
fileName: file.name, | ||
resourceType: CloudinaryResourceType.image, | ||
); | ||
|
||
final url = response.secureUrl; | ||
|
||
if (response.isSuccessful && url != null) { | ||
return Either.right(url); | ||
} | ||
|
||
return Either.left(Exception( | ||
'Error uploading image: ${response.statusCode} - ${response.error}' | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
import 'package:get_it/get_it.dart'; | ||
import 'package:poster/core/data/cloudinary/di/cloudinary_module.dart'; | ||
import 'package:poster/core/data/dio/di/dio_module.dart'; | ||
import 'package:poster/core/data/image/di/image_module.dart'; | ||
import 'package:poster/core/data/post/di/post_module.dart'; | ||
import 'package:poster/core/data/profile/di/profile_module.dart'; | ||
|
||
extension CoreModule on GetIt { | ||
List<Type> registerCoreModule() { | ||
registerPostModule(); | ||
registerDio(); | ||
return [...registerProfileModule()]; | ||
return [ | ||
...registerProfileModule(), | ||
...registerCloudinaryModule(), | ||
...registerImageModule(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import 'package:fpdart/fpdart.dart'; | ||
import 'package:image_picker/image_picker.dart'; | ||
|
||
abstract class ImageRepository { | ||
Future<Either<Exception, String>> upload(XFile file); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters