Implemented basic Fileviewing
This commit is contained in:
@ -1,46 +1,32 @@
|
||||
// import 'package:json_annotation/json_annotation.dart';
|
||||
// import 'package:webdav_client/webdav_client.dart';
|
||||
//
|
||||
// part 'cacheableFile.g.dart';
|
||||
//
|
||||
// @JsonSerializable(explicitToJson: true)
|
||||
// class CacheableFile {
|
||||
// String? path;
|
||||
// bool? isDir;
|
||||
// String? name;
|
||||
// String? mimeType;
|
||||
// int? size;
|
||||
// String? eTag;
|
||||
// DateTime? cTime;
|
||||
// DateTime? mTime;
|
||||
//
|
||||
// CacheableFile(this.path, this.isDir, this.name, this.mimeType, this.size,
|
||||
// this.eTag, this.cTime, this.mTime);
|
||||
//
|
||||
// CacheableFile.fromDavFile(File file) {
|
||||
// path = file.path;
|
||||
// isDir = file.isDir;
|
||||
// name = file.name;
|
||||
// mimeType = file.mimeType;
|
||||
// size = file.size;
|
||||
// eTag = file.eTag;
|
||||
// cTime = file.cTime;
|
||||
// mTime = file.mTime;
|
||||
// }
|
||||
//
|
||||
// File toDavFile() {
|
||||
// return File(
|
||||
// path: path,
|
||||
// isDir: isDir,
|
||||
// name: name,
|
||||
// mimeType: mimeType,
|
||||
// size: size,
|
||||
// eTag: eTag,
|
||||
// cTime: cTime,
|
||||
// mTime: mTime
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// factory CacheableFile.fromJson(Map<String, dynamic> json) => _$CacheableFileFromJson(json);
|
||||
// Map<String, dynamic> toJson() => _$CacheableFileToJson(this);
|
||||
// }
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:nextcloud/nextcloud.dart';
|
||||
|
||||
part 'cacheableFile.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class CacheableFile {
|
||||
late String path;
|
||||
late bool isDirectory;
|
||||
late String name;
|
||||
String? mimeType;
|
||||
int? size;
|
||||
String? eTag;
|
||||
DateTime? createdAt;
|
||||
DateTime? modifiedAt;
|
||||
|
||||
CacheableFile(this.path, this.isDirectory, this.name, {this.mimeType, this.size, this.eTag, this.createdAt, this.modifiedAt});
|
||||
|
||||
CacheableFile.fromDavFile(WebDavFile file) {
|
||||
path = file.path;
|
||||
isDirectory = file.isDirectory;
|
||||
name = file.name;
|
||||
mimeType = file.mimeType;
|
||||
size = file.size;
|
||||
eTag = file.etag;
|
||||
createdAt = file.createdDate;
|
||||
modifiedAt = file.lastModified;
|
||||
}
|
||||
|
||||
factory CacheableFile.fromJson(Map<String, dynamic> json) => _$CacheableFileFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$CacheableFileToJson(this);
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'cacheableFile.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
CacheableFile _$CacheableFileFromJson(Map<String, dynamic> json) =>
|
||||
CacheableFile(
|
||||
json['path'] as String,
|
||||
json['isDirectory'] as bool,
|
||||
json['name'] as String,
|
||||
mimeType: json['mimeType'] as String?,
|
||||
size: json['size'] as int?,
|
||||
eTag: json['eTag'] as String?,
|
||||
createdAt: json['createdAt'] == null
|
||||
? null
|
||||
: DateTime.parse(json['createdAt'] as String),
|
||||
modifiedAt: json['modifiedAt'] == null
|
||||
? null
|
||||
: DateTime.parse(json['modifiedAt'] as String),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$CacheableFileToJson(CacheableFile instance) =>
|
||||
<String, dynamic>{
|
||||
'path': instance.path,
|
||||
'isDirectory': instance.isDirectory,
|
||||
'name': instance.name,
|
||||
'mimeType': instance.mimeType,
|
||||
'size': instance.size,
|
||||
'eTag': instance.eTag,
|
||||
'createdAt': instance.createdAt?.toIso8601String(),
|
||||
'modifiedAt': instance.modifiedAt?.toIso8601String(),
|
||||
};
|
@ -1,21 +1,18 @@
|
||||
//
|
||||
// import 'package:marianum_mobile/api/apiParams.dart';
|
||||
// import 'package:marianum_mobile/api/apiResponse.dart';
|
||||
// import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/cacheableFile.dart';
|
||||
// import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/listFilesParams.dart';
|
||||
// import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/listFilesResponse.dart';
|
||||
// import 'package:marianum_mobile/api/marianumcloud/webdav/webdavApi.dart';
|
||||
// import 'package:webdav_client/webdav_client.dart';
|
||||
//
|
||||
// class ListFiles extends WebdavApi<ListFilesParams> {
|
||||
// ListFilesParams params;
|
||||
//
|
||||
// ListFiles(this.params) : super(params);
|
||||
//
|
||||
// @override
|
||||
// Future<ListFilesResponse> run() async {
|
||||
// Set<CacheableFile> files = (await (await WebdavApi.webdav).readDir(params.path)).map((e) => CacheableFile.fromDavFile(e)).toSet();
|
||||
//
|
||||
// return ListFilesResponse(files);
|
||||
// }
|
||||
// }
|
||||
|
||||
import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/cacheableFile.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/listFilesParams.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/listFilesResponse.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/webdav/webdavApi.dart';
|
||||
|
||||
class ListFiles extends WebdavApi<ListFilesParams> {
|
||||
ListFilesParams params;
|
||||
|
||||
ListFiles(this.params) : super(params);
|
||||
|
||||
@override
|
||||
Future<ListFilesResponse> run() async {
|
||||
Set<CacheableFile> files = (await (await WebdavApi.webdav).ls(params.path)).map((e) => CacheableFile.fromDavFile(e)).toSet();
|
||||
|
||||
return ListFilesResponse(files);
|
||||
}
|
||||
}
|
@ -1,33 +1,32 @@
|
||||
// import 'dart:convert';
|
||||
// import 'dart:developer';
|
||||
//
|
||||
// import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/listFiles.dart';
|
||||
// import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/listFilesParams.dart';
|
||||
// import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/listFilesResponse.dart';
|
||||
// import 'package:marianum_mobile/api/requestCache.dart';
|
||||
// import 'package:webdav_client/webdav_client.dart';
|
||||
//
|
||||
// class ListFilesCache extends RequestCache<ListFilesResponse> {
|
||||
// String path;
|
||||
//
|
||||
// ListFilesCache({required onUpdate, required this.path}) : super(RequestCache.cacheNothing, onUpdate) {
|
||||
// String cacheName = path.replaceAll(RegExp("[^A-Za-z0-9]"), "_"); //TODO this is very evil, "/ü/" > "___" also "/ä/" > "___"
|
||||
// log(cacheName);
|
||||
//
|
||||
// start("MarianumMobile", "wd-folder-$cacheName");
|
||||
// }
|
||||
//
|
||||
// @override
|
||||
// Future<ListFilesResponse> onLoad() async {
|
||||
// log("Loading remote data");
|
||||
// ListFilesResponse data = await ListFiles(ListFilesParams(path)).run();
|
||||
// return data;
|
||||
// }
|
||||
//
|
||||
// @override
|
||||
// ListFilesResponse onLocalData(String json) {
|
||||
// log("Loading local data");
|
||||
// return ListFilesResponse.fromJson(jsonDecode(json));
|
||||
// }
|
||||
//
|
||||
// }
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/listFiles.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/listFilesParams.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/listFilesResponse.dart';
|
||||
import 'package:marianum_mobile/api/requestCache.dart';
|
||||
|
||||
class ListFilesCache extends RequestCache<ListFilesResponse> {
|
||||
String path;
|
||||
|
||||
ListFilesCache({required onUpdate, required this.path}) : super(RequestCache.cacheNothing, onUpdate) {
|
||||
String cacheName = path.replaceAll(RegExp("[^A-Za-z0-9]"), "_"); //TODO this is very evil, "/ü/" > "___" also "/ä/" > "___"
|
||||
log(cacheName);
|
||||
|
||||
start("MarianumMobile", "wd-folder-$cacheName");
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ListFilesResponse> onLoad() async {
|
||||
log("Loading remote data");
|
||||
ListFilesResponse data = await ListFiles(ListFilesParams(path)).run();
|
||||
return data;
|
||||
}
|
||||
|
||||
@override
|
||||
ListFilesResponse onLocalData(String json) {
|
||||
log("Loading local data");
|
||||
return ListFilesResponse.fromJson(jsonDecode(json));
|
||||
}
|
||||
|
||||
}
|
@ -1,16 +1,16 @@
|
||||
// import 'package:json_annotation/json_annotation.dart';
|
||||
// import 'package:marianum_mobile/api/apiResponse.dart';
|
||||
//
|
||||
// import 'cacheableFile.dart';
|
||||
//
|
||||
// part 'listFilesResponse.g.dart';
|
||||
//
|
||||
// @JsonSerializable(explicitToJson: true)
|
||||
// class ListFilesResponse extends ApiResponse {
|
||||
// Set<CacheableFile> files;
|
||||
//
|
||||
// ListFilesResponse(this.files);
|
||||
//
|
||||
// factory ListFilesResponse.fromJson(Map<String, dynamic> json) => _$ListFilesResponseFromJson(json);
|
||||
// Map<String, dynamic> toJson() => _$ListFilesResponseToJson(this);
|
||||
// }
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:marianum_mobile/api/apiResponse.dart';
|
||||
|
||||
import 'cacheableFile.dart';
|
||||
|
||||
part 'listFilesResponse.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class ListFilesResponse extends ApiResponse {
|
||||
Set<CacheableFile> files;
|
||||
|
||||
ListFilesResponse(this.files);
|
||||
|
||||
factory ListFilesResponse.fromJson(Map<String, dynamic> json) => _$ListFilesResponseFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$ListFilesResponseToJson(this);
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'listFilesResponse.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
ListFilesResponse _$ListFilesResponseFromJson(Map<String, dynamic> json) =>
|
||||
ListFilesResponse(
|
||||
(json['files'] as List<dynamic>)
|
||||
.map((e) => CacheableFile.fromJson(e as Map<String, dynamic>))
|
||||
.toSet(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ListFilesResponseToJson(ListFilesResponse instance) =>
|
||||
<String, dynamic>{
|
||||
'files': instance.files.map((e) => e.toJson()).toList(),
|
||||
};
|
@ -1,43 +1,23 @@
|
||||
// import 'dart:developer';
|
||||
//
|
||||
// import 'package:marianum_mobile/api/apiParams.dart';
|
||||
// import 'package:marianum_mobile/api/apiRequest.dart';
|
||||
// import 'package:marianum_mobile/api/webuntis/queries/authenticate/authenticate.dart';
|
||||
// import 'package:shared_preferences/shared_preferences.dart';
|
||||
// import 'package:webdav_client/webdav_client.dart';
|
||||
//
|
||||
// import '../../apiResponse.dart';
|
||||
//
|
||||
// abstract class WebdavApi<T> extends ApiRequest {
|
||||
// T genericParams;
|
||||
//
|
||||
// WebdavApi(this.genericParams) {
|
||||
// establishWebdavConnection();
|
||||
// }
|
||||
//
|
||||
// Future<ApiResponse> run();
|
||||
//
|
||||
// static Future<Client> webdav = establishWebdavConnection();
|
||||
//
|
||||
// static Future<Client> establishWebdavConnection() async {
|
||||
// SharedPreferences preferences = await SharedPreferences.getInstance();
|
||||
//
|
||||
// // Client client = newClient(
|
||||
// // "https://cloud.marianum-fulda.de/remote.php/dav/files/***REMOVED***/",
|
||||
// // user: "***REMOVED***",
|
||||
// // password: "***REMOVED***",
|
||||
// // debug: true
|
||||
// // );
|
||||
// //
|
||||
// // client.setHeaders(
|
||||
// // {
|
||||
// // "Authorization": "Bearer",
|
||||
// // "User-Agent": "Marianum Fulda/Alpha0.1 (Development build) ; https://mhsl.eu/id.html",
|
||||
// // }
|
||||
// // );
|
||||
//
|
||||
// throw UnimplementedError();
|
||||
// //return client;
|
||||
//
|
||||
// }
|
||||
// }
|
||||
import 'package:marianum_mobile/api/apiRequest.dart';
|
||||
import 'package:nextcloud/nextcloud.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../apiResponse.dart';
|
||||
|
||||
abstract class WebdavApi<T> extends ApiRequest {
|
||||
T genericParams;
|
||||
|
||||
WebdavApi(this.genericParams) {
|
||||
establishWebdavConnection();
|
||||
}
|
||||
|
||||
Future<ApiResponse> run();
|
||||
|
||||
static Future<WebDavClient> webdav = establishWebdavConnection();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user