feat: Introduce FileVisibility enum and refactor FileUploadService to use it instead of magic strings for file access levels.
This commit is contained in:
@@ -10,18 +10,18 @@ class FileUploadService extends BaseCoreService {
|
||||
/// Uploads a file with optional visibility and category.
|
||||
///
|
||||
/// [filePath] is the local path to the file.
|
||||
/// [visibility] can be 'public' or 'private'.
|
||||
/// [visibility] can be [FileVisibility.public] or [FileVisibility.private].
|
||||
/// [category] is an optional metadata field.
|
||||
Future<ApiResponse> uploadFile({
|
||||
required String filePath,
|
||||
required String fileName,
|
||||
String visibility = 'private',
|
||||
FileVisibility visibility = FileVisibility.private,
|
||||
String? category,
|
||||
}) async {
|
||||
return action(() async {
|
||||
final FormData formData = FormData.fromMap(<String, dynamic>{
|
||||
'file': await MultipartFile.fromFile(filePath, filename: fileName),
|
||||
'visibility': visibility,
|
||||
'visibility': visibility.value,
|
||||
if (category != null) 'category': category,
|
||||
});
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ library;
|
||||
export 'src/core/services/api_services/api_response.dart';
|
||||
export 'src/core/services/api_services/base_api_service.dart';
|
||||
export 'src/core/services/api_services/base_core_service.dart';
|
||||
export 'src/core/services/api_services/file_visibility.dart';
|
||||
|
||||
// Users & Membership
|
||||
export 'src/entities/users/user.dart';
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
/// Represents the accessibility level of an uploaded file.
|
||||
enum FileVisibility {
|
||||
/// File is accessible only to authenticated owners/authorized users.
|
||||
private('private'),
|
||||
|
||||
/// File is accessible publicly via its URL.
|
||||
public('public');
|
||||
|
||||
/// Creates a [FileVisibility].
|
||||
const FileVisibility(this.value);
|
||||
|
||||
/// The string value expected by the backend.
|
||||
final String value;
|
||||
}
|
||||
Reference in New Issue
Block a user