|
|
@ -7,6 +7,8 @@ abstract interface class FilesBlocEvents { |
|
|
|
|
|
|
|
|
|
|
|
void openFile(final List<String> path, final String etag, final String? mimeType); |
|
|
|
void openFile(final List<String> path, final String etag, final String? mimeType); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void shareFileNative(final List<String> path, final String etag); |
|
|
|
|
|
|
|
|
|
|
|
void delete(final List<String> path); |
|
|
|
void delete(final List<String> path); |
|
|
|
|
|
|
|
|
|
|
|
void rename(final List<String> path, final String name); |
|
|
|
void rename(final List<String> path, final String name); |
|
|
@ -84,15 +86,8 @@ class FilesBloc extends InteractiveBloc implements FilesBlocEvents, FilesBlocSta |
|
|
|
void openFile(final List<String> path, final String etag, final String? mimeType) { |
|
|
|
void openFile(final List<String> path, final String etag, final String? mimeType) { |
|
|
|
wrapAction( |
|
|
|
wrapAction( |
|
|
|
() async { |
|
|
|
() async { |
|
|
|
final cacheDir = await getApplicationCacheDirectory(); |
|
|
|
final file = await _cacheFile(path, etag); |
|
|
|
final file = File(p.join(cacheDir.path, 'files', etag.replaceAll('"', ''), path.last)); |
|
|
|
|
|
|
|
if (!file.existsSync()) { |
|
|
|
|
|
|
|
debugPrint('Downloading ${Uri(pathSegments: path)} since it does not exist'); |
|
|
|
|
|
|
|
if (!file.parent.existsSync()) { |
|
|
|
|
|
|
|
await file.parent.create(recursive: true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
await _downloadFile(path, file); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
final result = await OpenFile.open(file.path, type: mimeType); |
|
|
|
final result = await OpenFile.open(file.path, type: mimeType); |
|
|
|
if (result.type != ResultType.done) { |
|
|
|
if (result.type != ResultType.done) { |
|
|
|
throw const UnableToOpenFileException(); |
|
|
|
throw const UnableToOpenFileException(); |
|
|
@ -102,6 +97,18 @@ class FilesBloc extends InteractiveBloc implements FilesBlocEvents, FilesBlocSta |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
|
|
|
void shareFileNative(final List<String> path, final String etag) { |
|
|
|
|
|
|
|
wrapAction( |
|
|
|
|
|
|
|
() async { |
|
|
|
|
|
|
|
final file = await _cacheFile(path, etag); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await Share.shareXFiles([XFile(file.path)]); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
disableTimeout: true, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
Future<void> refresh() async { |
|
|
|
Future<void> refresh() async { |
|
|
|
await browser.refresh(); |
|
|
|
await browser.refresh(); |
|
|
@ -164,6 +171,21 @@ class FilesBloc extends InteractiveBloc implements FilesBlocEvents, FilesBlocSta |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<File> _cacheFile(final List<String> path, final String etag) async { |
|
|
|
|
|
|
|
final cacheDir = await getApplicationCacheDirectory(); |
|
|
|
|
|
|
|
final file = File(p.join(cacheDir.path, 'files', etag.replaceAll('"', ''), path.last)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!file.existsSync()) { |
|
|
|
|
|
|
|
debugPrint('Downloading ${Uri(pathSegments: path)} since it does not exist'); |
|
|
|
|
|
|
|
if (!file.parent.existsSync()) { |
|
|
|
|
|
|
|
await file.parent.create(recursive: true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
await _downloadFile(path, file); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return file; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Future<void> _downloadFile( |
|
|
|
Future<void> _downloadFile( |
|
|
|
final List<String> path, |
|
|
|
final List<String> path, |
|
|
|
final File file, |
|
|
|
final File file, |
|
|
|