Skip to content

Commit

Permalink
fix: fixing dir creation
Browse files Browse the repository at this point in the history
  • Loading branch information
RaulRodrigo06 committed Oct 3, 2023
1 parent 7556645 commit 2429e82
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/src/utils/ds_directory_formatter.util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ abstract class DSDirectoryFormatter {
required String fileName,
}) async {
String dir = path.dirname(filePath);
final String formattedDir = _formatDir(type: type, dir: dir);
final dirExists = await Directory(formattedDir).exists();
if (!dirExists) {
await Directory(formattedDir).create(recursive: true);
}
final String formattedDir = await _formatDir(type: type, dir: dir);
String newName = path.join(formattedDir, fileName);
await File(filePath).rename(newName);
return newName;
Expand All @@ -29,10 +25,16 @@ abstract class DSDirectoryFormatter {
return mediaPath;
}

static String _formatDir({required DSFileType type, required String dir}) {
return dir.replaceAll(
static Future<String> _formatDir(
{required DSFileType type, required String dir}) async {
final formattedDir = dir.replaceAll(
dir.split('/').last,
'BlipDesk/Media/${type.name.capitalizeFirst}',
);
final dirExists = await Directory(formattedDir).exists();
if (!dirExists) {
await Directory(formattedDir).create(recursive: true);
}
return formattedDir;
}
}

0 comments on commit 2429e82

Please sign in to comment.