44 lines
1.5 KiB
Dart
44 lines
1.5 KiB
Dart
import '../../../core/transport/server_url.dart';
|
|
|
|
class FileUrls {
|
|
const FileUrls({required this.view, required this.download});
|
|
|
|
/// `GET /files?path=...`: the file inline, with its content type and ranges.
|
|
final Uri view;
|
|
|
|
/// The same file with `download=1`: an attachment disposition.
|
|
final Uri download;
|
|
}
|
|
|
|
/// Resolves the files endpoint URLs for one working-directory path.
|
|
typedef FileUrlResolver =
|
|
FileUrls? Function(String configuredEndpoint, String path);
|
|
|
|
/// The resolver the Files panel uses for thumbnails, viewing and downloads.
|
|
///
|
|
/// Production keeps [fileUrls]. The full-app capture fixture
|
|
/// (`tool/search_selection_probe_entry.dart`, `?files=1`) swaps in a resolver
|
|
/// whose urls point to bundled capture files, because its static server has no `/files`
|
|
/// route; widget tests swap in one that ignores the fake gateway's missing
|
|
/// endpoint. Restore it after a test.
|
|
FileUrlResolver resolveFileUrls = fileUrls;
|
|
|
|
/// Builds the two same-origin HTTP URLs used by the files endpoint.
|
|
FileUrls? fileUrls(String configuredEndpoint, String path) {
|
|
final value = path;
|
|
if (value.trim().isEmpty) return null;
|
|
try {
|
|
Uri make({required bool download}) => ServerUrl.resourceUri(
|
|
configuredEndpoint,
|
|
'/files',
|
|
query: <String, String>{'path': value, if (download) 'download': '1'},
|
|
);
|
|
return FileUrls(
|
|
view: make(download: false),
|
|
download: make(download: true),
|
|
);
|
|
} on FormatException {
|
|
return null;
|
|
}
|
|
}
|