implemented file thumbnails and enhanced file type icons, added reusable FileLeading widget, and updated search to support previews
This commit is contained in:
@@ -83,9 +83,49 @@ class SearchFilesEntry {
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Derives a filename with its extension from the WebDAV-relative path.
|
||||
/// The provider's `title` is often the display name *without* the
|
||||
/// extension, which would defeat extension-based icon mapping.
|
||||
String _nameFromPath(String path) {
|
||||
final stripped = path.replaceAll(RegExp(r'^/+|/+$'), '');
|
||||
if (stripped.isEmpty) return title;
|
||||
final last = stripped.split('/').last;
|
||||
return last.isEmpty ? title : last;
|
||||
}
|
||||
|
||||
/// The files search provider exposes the numeric Nextcloud file id either
|
||||
/// as an attribute, or implicitly in the `?openfile=<id>` query parameter
|
||||
/// of [resourceUrl]. Parses both into an [int] when available — used to
|
||||
/// hit the preview endpoint directly.
|
||||
int? _extractFileId() {
|
||||
final attr = attributes?['fileId'];
|
||||
if (attr is int) return attr;
|
||||
if (attr is String) {
|
||||
final parsed = int.tryParse(attr);
|
||||
if (parsed != null) return parsed;
|
||||
}
|
||||
final url = resourceUrl;
|
||||
if (url != null) {
|
||||
final raw = Uri.tryParse(url)?.queryParameters['openfile'];
|
||||
if (raw != null) return int.tryParse(raw);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
CacheableFile? toCacheable() {
|
||||
final path = webdavPath;
|
||||
if (path == null) return null;
|
||||
return CacheableFile(path: path, isDirectory: isDirectory, name: title);
|
||||
final fileId = _extractFileId();
|
||||
return CacheableFile(
|
||||
path: path,
|
||||
isDirectory: isDirectory,
|
||||
name: _nameFromPath(path),
|
||||
fileId: fileId,
|
||||
// Search provider responses don't carry `nc:has-preview`. Probe
|
||||
// optimistically when a fileId is available — the preview endpoint
|
||||
// simply returns 404 for unsupported formats, which the file-leading
|
||||
// widget already falls back from to the typed icon.
|
||||
hasPreview: (!isDirectory && fileId != null) ? true : null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user