Implemented simple and basic file downloading
This commit is contained in:
@ -0,0 +1,21 @@
|
||||
|
||||
import 'package:marianum_mobile/api/apiResponse.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/webdav/queries/downloadFile/downloadFileParams.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/webdav/webdavApi.dart';
|
||||
|
||||
class DownloadFile extends WebdavApi<DownloadFileParams> {
|
||||
DownloadFileParams params;
|
||||
|
||||
DownloadFile(this.params) : super(params);
|
||||
|
||||
@override
|
||||
Future<ApiResponse> run() async {
|
||||
|
||||
// final file = await File(localPath).create();
|
||||
// Uint8List downloadedFile = await (await WebdavApi.webdav).download(params.webdavPath);
|
||||
// file.writeAsBytesSync(downloadedFile, flush: true, mode: FileMode.write);
|
||||
//
|
||||
// OpenFile.open(localPath);
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:marianum_mobile/api/apiParams.dart';
|
||||
|
||||
part 'downloadFileParams.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class DownloadFileParams extends ApiParams {
|
||||
String webdavSourcePath;
|
||||
String localTargetPath;
|
||||
String filename;
|
||||
|
||||
DownloadFileParams(this.webdavSourcePath, this.localTargetPath, this.filename);
|
||||
|
||||
factory DownloadFileParams.fromJson(Map<String, dynamic> json) => _$DownloadFileParamsFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$DownloadFileParamsToJson(this);
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'downloadFileParams.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
DownloadFileParams _$DownloadFileParamsFromJson(Map<String, dynamic> json) =>
|
||||
DownloadFileParams(
|
||||
json['webdavSourcePath'] as String,
|
||||
json['localTargetPath'] as String,
|
||||
json['filename'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$DownloadFileParamsToJson(DownloadFileParams instance) =>
|
||||
<String, dynamic>{
|
||||
'webdavSourcePath': instance.webdavSourcePath,
|
||||
'localTargetPath': instance.localTargetPath,
|
||||
'filename': instance.filename,
|
||||
};
|
@ -0,0 +1,14 @@
|
||||
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'downloadFileResponse.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class DownloadFileResponse {
|
||||
String path;
|
||||
|
||||
DownloadFileResponse(this.path);
|
||||
|
||||
factory DownloadFileResponse.fromJson(Map<String, dynamic> json) => _$DownloadFileResponseFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$DownloadFileResponseToJson(this);
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'downloadFileResponse.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
DownloadFileResponse _$DownloadFileResponseFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
DownloadFileResponse(
|
||||
json['path'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$DownloadFileResponseToJson(
|
||||
DownloadFileResponse instance) =>
|
||||
<String, dynamic>{
|
||||
'path': instance.path,
|
||||
};
|
@ -14,10 +14,17 @@ abstract class WebdavApi<T> extends ApiRequest {
|
||||
Future<ApiResponse> run();
|
||||
|
||||
static Future<WebDavClient> webdav = establishWebdavConnection();
|
||||
static Future<String> webdavConnectString = buildWebdavConnectString();
|
||||
|
||||
static Future<WebDavClient> establishWebdavConnection() async {
|
||||
SharedPreferences preferences = await SharedPreferences.getInstance();
|
||||
|
||||
return NextcloudClient("https://cloud.marianum-fulda.de/", username: preferences.getString("username"), password: preferences.getString("password"), loginName: preferences.getString("username")).webdav;
|
||||
}
|
||||
|
||||
static Future<String> buildWebdavConnectString() async {
|
||||
SharedPreferences preferences = await SharedPreferences.getInstance();
|
||||
|
||||
return "https://${preferences.getString("username")}:${preferences.getString("password")}@cloud.marianum-fulda.de/remote.php/dav/files/${preferences.getString("username")}/";
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user