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 xml = XmlDocument.parse(response.body);
final files = WebdavFileParser()(xml); final files = WebdavFileParser()(xml);
// _log.fine("[list] Parsed files: [$files]"); // _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) { if (e.metadata == null || e.metadata.fileEtag == e.etag) {
return e; return e;
} else { } else {
@ -328,10 +328,14 @@ class FileAppDbDataSource implements FileDataSource {
if (results?.isNotEmpty == true) { if (results?.isNotEmpty == true) {
final entries = results final entries = results
.map((e) => AppDbFileEntry.fromJson(e.cast<String, dynamic>())); .map((e) => AppDbFileEntry.fromJson(e.cast<String, dynamic>()));
return entries.map((e) { return entries
.map((e) {
_log.info("[_doList] ${e.path}[${e.index}]"); _log.info("[_doList] ${e.path}[${e.index}]");
return e.data; return e.data;
}).reduce((value, element) => value + element); })
.reduce((value, element) => value + element)
.where((element) => _validateFile(element))
.toList();
} else { } else {
throw CacheNotFoundException("No entry: $path"); 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"); final _log = Logger("entity.file.data_source");