Filter out invalid files

This commit is contained in:
Ming Ming 2021-07-16 17:25:01 +08:00
parent 679c0dbae2
commit 368a6a6755

View file

@ -60,7 +60,7 @@ class FileWebdavDataSource implements FileDataSource {
final xml = XmlDocument.parse(response.body);
final files = WebdavFileParser()(xml);
// _log.fine("[list] Parsed files: [$files]");
return files.map((e) {
return files.where((element) => _validateFile(element)).map((e) {
if (e.metadata == null || e.metadata.fileEtag == e.etag) {
return e;
} else {
@ -328,10 +328,14 @@ class FileAppDbDataSource implements FileDataSource {
if (results?.isNotEmpty == true) {
final entries = results
.map((e) => AppDbFileEntry.fromJson(e.cast<String, dynamic>()));
return entries.map((e) {
_log.info("[_doList] ${e.path}[${e.index}]");
return e.data;
}).reduce((value, element) => value + element);
return entries
.map((e) {
_log.info("[_doList] ${e.path}[${e.index}]");
return e.data;
})
.reduce((value, element) => value + element)
.where((element) => _validateFile(element))
.toList();
} else {
throw CacheNotFoundException("No entry: $path");
}
@ -720,4 +724,9 @@ Future<void> _cacheListResults(
}
}
bool _validateFile(File f) {
// See: https://gitlab.com/nkming2/nc-photos/-/issues/9
return f.lastModified != null;
}
final _log = Logger("entity.file.data_source");