Skip to content

Commit

Permalink
Improve paths in file system
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Sep 11, 2024
1 parent 722afff commit b1f95ee
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions packages/lw_file_system_api/lib/src/storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:convert';
import 'dart:typed_data';

import 'package:dart_mappable/dart_mappable.dart';
import 'package:path/path.dart' as p;

part 'storage.mapper.dart';

Expand Down Expand Up @@ -171,18 +172,31 @@ sealed class RemoteStorage extends ExternalStorage with RemoteStorageMappable {
);
}

String buildVariantPath({
String variant = '',
List<String> path = const [],
}) {
var currentPath = p.joinAll([
getBasePath(),
if (variant.isNotEmpty) paths[variant] ?? '',
...path,
]);
if (currentPath.startsWith('/')) {
currentPath = currentPath.substring(1);
}
return currentPath;
}

Uri? buildVariantUri({
String variant = '',
List<String> path = const [],
Map<String, String> query = const {},
}) {
final current = paths[variant];
return current?.isEmpty ?? true
? null
: buildUri(
path: [...current!.split('/'), ...path],
query: query,
);
final current = buildVariantPath(variant: variant, path: path);
return buildUri(
path: current.split('/'),
query: query,
);
}

@override
Expand Down

0 comments on commit b1f95ee

Please sign in to comment.