From b1f95ee120ecc6d23f0e8cd930c94f52e7c759a5 Mon Sep 17 00:00:00 2001 From: CodeDoctorDE Date: Wed, 11 Sep 2024 21:21:08 +0200 Subject: [PATCH] Improve paths in file system --- .../lw_file_system_api/lib/src/storage.dart | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/packages/lw_file_system_api/lib/src/storage.dart b/packages/lw_file_system_api/lib/src/storage.dart index fbddab2..d888d81 100644 --- a/packages/lw_file_system_api/lib/src/storage.dart +++ b/packages/lw_file_system_api/lib/src/storage.dart @@ -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'; @@ -171,18 +172,31 @@ sealed class RemoteStorage extends ExternalStorage with RemoteStorageMappable { ); } + String buildVariantPath({ + String variant = '', + List 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 path = const [], Map 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