nc-photos/lib/use_case/download_file.dart
2021-09-29 22:56:54 +08:00

31 lines
891 B
Dart

import 'package:nc_photos/account.dart';
import 'package:nc_photos/api/api.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/mobile/platform.dart'
if (dart.library.html) 'package:nc_photos/web/platform.dart' as platform;
import 'package:path/path.dart' as path;
class DownloadFile {
/// Download [file]
///
/// See [FileDownloader.downloadUrl]
Future<dynamic> call(
Account account,
File file, {
String? parentDir,
bool? shouldNotify,
}) {
final downloader = platform.FileDownloader();
final url = "${account.url}/${file.path}";
return downloader.downloadUrl(
url: url,
headers: {
"authorization": Api.getAuthorizationHeaderValue(account),
},
mimeType: file.contentType,
filename: path.basename(file.path),
parentDir: parentDir,
shouldNotify: shouldNotify,
);
}
}