2021-09-09 22:42:47 +02:00
|
|
|
import 'package:nc_photos/account.dart';
|
2022-10-15 16:29:18 +02:00
|
|
|
import 'package:nc_photos/entity/file_descriptor.dart';
|
2021-09-09 22:42:47 +02:00
|
|
|
import 'package:nc_photos/mobile/platform.dart'
|
|
|
|
if (dart.library.html) 'package:nc_photos/web/platform.dart' as platform;
|
2023-02-23 15:49:17 +01:00
|
|
|
import 'package:nc_photos/np_api_util.dart';
|
2021-10-02 11:12:54 +02:00
|
|
|
import 'package:nc_photos/platform/download.dart';
|
2021-09-09 22:42:47 +02:00
|
|
|
|
|
|
|
class DownloadFile {
|
2021-10-02 11:12:54 +02:00
|
|
|
/// Create a new download but don't start it yet
|
2023-09-03 11:12:57 +02:00
|
|
|
///
|
|
|
|
/// [onProgress] is not supported by all implementors. If supported, it will
|
|
|
|
/// be called with the current download progress, normalized from 0 to 1.
|
|
|
|
/// There's no guarantee that you will receive a 1 in [onProgress]
|
2021-10-02 11:12:54 +02:00
|
|
|
Download build(
|
2021-09-19 12:59:45 +02:00
|
|
|
Account account,
|
2023-04-13 17:32:31 +02:00
|
|
|
FileDescriptor file, {
|
2021-09-29 16:34:56 +02:00
|
|
|
String? parentDir,
|
2021-09-19 12:59:45 +02:00
|
|
|
bool? shouldNotify,
|
2023-09-03 11:12:57 +02:00
|
|
|
void Function(double progress)? onProgress,
|
2021-09-19 12:59:45 +02:00
|
|
|
}) {
|
2023-04-13 17:32:31 +02:00
|
|
|
final url = "${account.url}/${file.fdPath}";
|
2021-10-02 11:12:54 +02:00
|
|
|
return platform.DownloadBuilder().build(
|
2021-09-19 12:59:45 +02:00
|
|
|
url: url,
|
|
|
|
headers: {
|
2023-02-23 15:49:17 +01:00
|
|
|
"authorization": AuthUtil.fromAccount(account).toHeaderValue(),
|
2021-09-19 12:59:45 +02:00
|
|
|
},
|
2023-04-13 17:32:31 +02:00
|
|
|
mimeType: file.fdMime,
|
2021-10-02 11:29:52 +02:00
|
|
|
filename: file.filename,
|
2021-09-29 16:34:56 +02:00
|
|
|
parentDir: parentDir,
|
2021-09-19 12:59:45 +02:00
|
|
|
shouldNotify: shouldNotify,
|
2023-09-03 11:12:57 +02:00
|
|
|
onProgress: onProgress,
|
2021-09-19 12:59:45 +02:00
|
|
|
);
|
2021-09-09 22:42:47 +02:00
|
|
|
}
|
2021-10-02 11:12:54 +02:00
|
|
|
|
|
|
|
/// Download [file]
|
|
|
|
///
|
|
|
|
/// See [DownloadBuilder]
|
|
|
|
Future<dynamic> call(
|
|
|
|
Account account,
|
2023-04-13 17:32:31 +02:00
|
|
|
FileDescriptor file, {
|
2021-10-02 11:12:54 +02:00
|
|
|
String? parentDir,
|
|
|
|
bool? shouldNotify,
|
2023-09-03 11:12:57 +02:00
|
|
|
void Function(double progress)? onProgress,
|
2021-10-02 11:12:54 +02:00
|
|
|
}) =>
|
|
|
|
build(
|
|
|
|
account,
|
|
|
|
file,
|
|
|
|
parentDir: parentDir,
|
|
|
|
shouldNotify: shouldNotify,
|
2023-09-03 11:12:57 +02:00
|
|
|
onProgress: onProgress,
|
2021-10-02 11:12:54 +02:00
|
|
|
)();
|
2021-09-09 22:42:47 +02:00
|
|
|
}
|