Merge branch 'ws-files-viewer'
# Conflicts: # app/tool/capture/README.md
This commit is contained in:
@@ -198,7 +198,16 @@ bool isMarkdownArtifact(String contentType, String name) {
|
|||||||
|
|
||||||
/// How the viewer presents an artifact in-app, or [none] when it only offers
|
/// How the viewer presents an artifact in-app, or [none] when it only offers
|
||||||
/// Open/Download.
|
/// Open/Download.
|
||||||
enum ArtifactPreviewFormat { image, video, markdown, text, table, html, none }
|
enum ArtifactPreviewFormat {
|
||||||
|
image,
|
||||||
|
video,
|
||||||
|
audio,
|
||||||
|
markdown,
|
||||||
|
text,
|
||||||
|
table,
|
||||||
|
html,
|
||||||
|
none,
|
||||||
|
}
|
||||||
|
|
||||||
/// The one rule for in-app previews, shared by the gallery's paging and the
|
/// The one rule for in-app previews, shared by the gallery's paging and the
|
||||||
/// viewer's fetch plan. Images and videos come from the content type; markdown
|
/// viewer's fetch plan. Images and videos come from the content type; markdown
|
||||||
@@ -210,6 +219,7 @@ ArtifactPreviewFormat artifactPreviewFormat(String contentType, String name) {
|
|||||||
if (isVideoContentType(contentType)) return ArtifactPreviewFormat.video;
|
if (isVideoContentType(contentType)) return ArtifactPreviewFormat.video;
|
||||||
final mime = contentType.split(';').first.trim().toLowerCase();
|
final mime = contentType.split(';').first.trim().toLowerCase();
|
||||||
final ext = _extensionOf(name);
|
final ext = _extensionOf(name);
|
||||||
|
if (mime.startsWith('audio/')) return ArtifactPreviewFormat.audio;
|
||||||
if (mime == 'text/markdown' || ext == 'md' || ext == 'markdown') {
|
if (mime == 'text/markdown' || ext == 'md' || ext == 'markdown') {
|
||||||
return ArtifactPreviewFormat.markdown;
|
return ArtifactPreviewFormat.markdown;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ enum ArtifactPreviewKind {
|
|||||||
/// fetched as bytes, never autoplayed), as the web viewer does.
|
/// fetched as bytes, never autoplayed), as the web viewer does.
|
||||||
video,
|
video,
|
||||||
|
|
||||||
|
/// A same-origin audio file, played with the shared media controller.
|
||||||
|
audio,
|
||||||
|
|
||||||
/// A CSV/TSV drawn as a table from its fetched text.
|
/// A CSV/TSV drawn as a table from its fetched text.
|
||||||
table,
|
table,
|
||||||
|
|
||||||
@@ -68,13 +71,16 @@ const String artifactPreviewExternalUrl =
|
|||||||
|
|
||||||
/// Classifies [artifact] against the configured server origin.
|
/// Classifies [artifact] against the configured server origin.
|
||||||
///
|
///
|
||||||
/// The format comes from [artifactPreviewFormat]: images are drawn from the
|
/// The format comes from [format] (the shared [artifactPreviewFormat] unless a
|
||||||
|
/// caller such as the chat Files panel has its own rule): images are drawn from the
|
||||||
/// resolved bytes, a video plays from the resolved url, markdown goes to the
|
/// resolved bytes, a video plays from the resolved url, markdown goes to the
|
||||||
/// injected builder and the text family is selectable monospace text.
|
/// injected builder and the text family is selectable monospace text.
|
||||||
/// Everything else is explicitly unsupported rather than faked.
|
/// Everything else is explicitly unsupported rather than faked.
|
||||||
ArtifactPreviewPlan planArtifactPreview({
|
ArtifactPreviewPlan planArtifactPreview({
|
||||||
required ArtifactRecord artifact,
|
required ArtifactRecord artifact,
|
||||||
required String configuredEndpoint,
|
required String configuredEndpoint,
|
||||||
|
ArtifactPreviewFormat Function(String contentType, String name) format =
|
||||||
|
artifactPreviewFormat,
|
||||||
}) {
|
}) {
|
||||||
if (!artifact.hasUrl) {
|
if (!artifact.hasUrl) {
|
||||||
return const ArtifactPreviewPlan(
|
return const ArtifactPreviewPlan(
|
||||||
@@ -98,12 +104,10 @@ ArtifactPreviewPlan planArtifactPreview({
|
|||||||
message: artifactPreviewExternalUrl,
|
message: artifactPreviewExternalUrl,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
final kind = switch (artifactPreviewFormat(
|
final kind = switch (format(artifact.contentType, artifact.name)) {
|
||||||
artifact.contentType,
|
|
||||||
artifact.name,
|
|
||||||
)) {
|
|
||||||
ArtifactPreviewFormat.image => ArtifactPreviewKind.image,
|
ArtifactPreviewFormat.image => ArtifactPreviewKind.image,
|
||||||
ArtifactPreviewFormat.video => ArtifactPreviewKind.video,
|
ArtifactPreviewFormat.video => ArtifactPreviewKind.video,
|
||||||
|
ArtifactPreviewFormat.audio => ArtifactPreviewKind.audio,
|
||||||
ArtifactPreviewFormat.markdown => ArtifactPreviewKind.markdown,
|
ArtifactPreviewFormat.markdown => ArtifactPreviewKind.markdown,
|
||||||
ArtifactPreviewFormat.text => ArtifactPreviewKind.text,
|
ArtifactPreviewFormat.text => ArtifactPreviewKind.text,
|
||||||
ArtifactPreviewFormat.table => ArtifactPreviewKind.table,
|
ArtifactPreviewFormat.table => ArtifactPreviewKind.table,
|
||||||
|
|||||||
@@ -224,6 +224,8 @@ IconData artifactKindIcon(ArtifactRecord artifact, {required bool cupertino}) {
|
|||||||
cupertino ? CupertinoIcons.photo : Icons.image_outlined,
|
cupertino ? CupertinoIcons.photo : Icons.image_outlined,
|
||||||
ArtifactPreviewFormat.video =>
|
ArtifactPreviewFormat.video =>
|
||||||
cupertino ? CupertinoIcons.film : Icons.movie_outlined,
|
cupertino ? CupertinoIcons.film : Icons.movie_outlined,
|
||||||
|
ArtifactPreviewFormat.audio =>
|
||||||
|
cupertino ? CupertinoIcons.music_note : Icons.audio_file_outlined,
|
||||||
ArtifactPreviewFormat.markdown =>
|
ArtifactPreviewFormat.markdown =>
|
||||||
cupertino ? CupertinoIcons.doc_text : Icons.article_outlined,
|
cupertino ? CupertinoIcons.doc_text : Icons.article_outlined,
|
||||||
ArtifactPreviewFormat.text =>
|
ArtifactPreviewFormat.text =>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import 'package:video_player/video_player.dart';
|
|||||||
|
|
||||||
import '../../../ui/adaptive/host.dart';
|
import '../../../ui/adaptive/host.dart';
|
||||||
|
|
||||||
/// Creates the player for one video url; tests inject a fake controller.
|
/// Creates the player for one media url; tests inject a fake controller.
|
||||||
typedef ArtifactVideoControllerFactory =
|
typedef ArtifactVideoControllerFactory =
|
||||||
VideoPlayerController Function(Uri uri);
|
VideoPlayerController Function(Uri uri);
|
||||||
|
|
||||||
@@ -13,6 +13,8 @@ VideoPlayerController defaultArtifactVideoController(Uri uri) =>
|
|||||||
|
|
||||||
const String artifactVideoPlayLabel = 'Play video';
|
const String artifactVideoPlayLabel = 'Play video';
|
||||||
const String artifactVideoPauseLabel = 'Pause video';
|
const String artifactVideoPauseLabel = 'Pause video';
|
||||||
|
const String artifactAudioPlayLabel = 'Play audio';
|
||||||
|
const String artifactAudioPauseLabel = 'Pause audio';
|
||||||
const String artifactVideoError = 'The video could not be played.';
|
const String artifactVideoError = 'The video could not be played.';
|
||||||
|
|
||||||
/// Plays one recorded same-origin video in the viewer, as the web viewer's
|
/// Plays one recorded same-origin video in the viewer, as the web viewer's
|
||||||
@@ -22,10 +24,12 @@ class ArtifactVideoPlayer extends StatefulWidget {
|
|||||||
super.key,
|
super.key,
|
||||||
required this.uri,
|
required this.uri,
|
||||||
this.controllerFactory = defaultArtifactVideoController,
|
this.controllerFactory = defaultArtifactVideoController,
|
||||||
|
this.audio = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
final Uri uri;
|
final Uri uri;
|
||||||
final ArtifactVideoControllerFactory controllerFactory;
|
final ArtifactVideoControllerFactory controllerFactory;
|
||||||
|
final bool audio;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<ArtifactVideoPlayer> createState() => _ArtifactVideoPlayerState();
|
State<ArtifactVideoPlayer> createState() => _ArtifactVideoPlayerState();
|
||||||
@@ -95,23 +99,29 @@ class _ArtifactVideoPlayerState extends State<ArtifactVideoPlayer> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
final label = value.isPlaying
|
final label = value.isPlaying
|
||||||
? artifactVideoPauseLabel
|
? (widget.audio ? artifactAudioPauseLabel : artifactVideoPauseLabel)
|
||||||
: artifactVideoPlayLabel;
|
: (widget.audio ? artifactAudioPlayLabel : artifactVideoPlayLabel);
|
||||||
final icon = cupertino
|
final icon = cupertino
|
||||||
? (value.isPlaying
|
? (value.isPlaying
|
||||||
? CupertinoIcons.pause_fill
|
? CupertinoIcons.pause_fill
|
||||||
: CupertinoIcons.play_fill)
|
: CupertinoIcons.play_fill)
|
||||||
: (value.isPlaying ? Icons.pause : Icons.play_arrow);
|
: (value.isPlaying ? Icons.pause : Icons.play_arrow);
|
||||||
return Column(
|
return Column(
|
||||||
key: const Key('artifact-video'),
|
key: Key(widget.audio ? 'artifact-audio' : 'artifact-video'),
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Flexible(
|
if (!widget.audio)
|
||||||
child: AspectRatio(
|
Flexible(
|
||||||
aspectRatio: value.aspectRatio,
|
child: AspectRatio(
|
||||||
child: VideoPlayer(_controller),
|
aspectRatio: value.aspectRatio,
|
||||||
|
child: VideoPlayer(_controller),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
else
|
||||||
|
const Padding(
|
||||||
|
padding: EdgeInsets.all(24),
|
||||||
|
child: Icon(Icons.audio_file_outlined, size: 64),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||||
child: Row(
|
child: Row(
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ class ArtifactViewerBar extends StatelessWidget {
|
|||||||
required this.count,
|
required this.count,
|
||||||
required this.fetch,
|
required this.fetch,
|
||||||
required this.fileBridge,
|
required this.fileBridge,
|
||||||
|
this.downloadResolved,
|
||||||
required this.onOpen,
|
required this.onOpen,
|
||||||
required this.onCopy,
|
required this.onCopy,
|
||||||
required this.onPrevious,
|
required this.onPrevious,
|
||||||
@@ -44,6 +45,7 @@ class ArtifactViewerBar extends StatelessWidget {
|
|||||||
final int count;
|
final int count;
|
||||||
final ArtifactFetch fetch;
|
final ArtifactFetch fetch;
|
||||||
final ArtifactFileBridge fileBridge;
|
final ArtifactFileBridge fileBridge;
|
||||||
|
final ResolvedArtifactUrl? downloadResolved;
|
||||||
final VoidCallback onOpen;
|
final VoidCallback onOpen;
|
||||||
final VoidCallback onCopy;
|
final VoidCallback onCopy;
|
||||||
final VoidCallback onPrevious;
|
final VoidCallback onPrevious;
|
||||||
@@ -123,7 +125,7 @@ class ArtifactViewerBar extends StatelessWidget {
|
|||||||
'${page.group.visit}\u0000${page.artifact.url}',
|
'${page.group.visit}\u0000${page.artifact.url}',
|
||||||
),
|
),
|
||||||
artifact: page.artifact,
|
artifact: page.artifact,
|
||||||
resolved: resolved,
|
resolved: downloadResolved ?? resolved,
|
||||||
fetch: fetch,
|
fetch: fetch,
|
||||||
bridge: fileBridge,
|
bridge: fileBridge,
|
||||||
compact: true,
|
compact: true,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import '../../../ui/adaptive/floating_bar_layout.dart';
|
|||||||
import '../actions/artifact_file_actions.dart';
|
import '../actions/artifact_file_actions.dart';
|
||||||
import '../actions/artifact_file_bridge.dart';
|
import '../actions/artifact_file_bridge.dart';
|
||||||
import '../domain/artifact_preview.dart';
|
import '../domain/artifact_preview.dart';
|
||||||
|
import '../domain/artifact_url.dart';
|
||||||
import '../domain/gallery_navigation.dart';
|
import '../domain/gallery_navigation.dart';
|
||||||
import 'artifact_html_view.dart';
|
import 'artifact_html_view.dart';
|
||||||
import 'artifact_viewer_bar.dart';
|
import 'artifact_viewer_bar.dart';
|
||||||
@@ -39,6 +40,7 @@ class ArtifactViewerBody extends StatelessWidget {
|
|||||||
required this.onCopy,
|
required this.onCopy,
|
||||||
this.fetch = fetchArtifact,
|
this.fetch = fetchArtifact,
|
||||||
this.fileBridge = const ArtifactFileBridge(),
|
this.fileBridge = const ArtifactFileBridge(),
|
||||||
|
this.downloadResolved,
|
||||||
this.text,
|
this.text,
|
||||||
this.bytes,
|
this.bytes,
|
||||||
this.error,
|
this.error,
|
||||||
@@ -73,6 +75,7 @@ class ArtifactViewerBody extends StatelessWidget {
|
|||||||
final VoidCallback onCopy;
|
final VoidCallback onCopy;
|
||||||
final ArtifactFetch fetch;
|
final ArtifactFetch fetch;
|
||||||
final ArtifactFileBridge fileBridge;
|
final ArtifactFileBridge fileBridge;
|
||||||
|
final ResolvedArtifactUrl? downloadResolved;
|
||||||
final String? text;
|
final String? text;
|
||||||
final Uint8List? bytes;
|
final Uint8List? bytes;
|
||||||
final String? error;
|
final String? error;
|
||||||
@@ -138,6 +141,7 @@ class ArtifactViewerBody extends StatelessWidget {
|
|||||||
count: count,
|
count: count,
|
||||||
fetch: fetch,
|
fetch: fetch,
|
||||||
fileBridge: fileBridge,
|
fileBridge: fileBridge,
|
||||||
|
downloadResolved: downloadResolved,
|
||||||
onOpen: onOpen,
|
onOpen: onOpen,
|
||||||
onCopy: onCopy,
|
onCopy: onCopy,
|
||||||
onPrevious: onPrevious,
|
onPrevious: onPrevious,
|
||||||
|
|||||||
@@ -111,6 +111,14 @@ class ArtifactPreviewBody extends StatelessWidget {
|
|||||||
controllerFactory: videoControllerFactory,
|
controllerFactory: videoControllerFactory,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
case ArtifactPreviewKind.audio:
|
||||||
|
return Center(
|
||||||
|
child: ArtifactVideoPlayer(
|
||||||
|
uri: plan.resolved!.uri,
|
||||||
|
controllerFactory: videoControllerFactory,
|
||||||
|
audio: true,
|
||||||
|
),
|
||||||
|
);
|
||||||
case ArtifactPreviewKind.unsupported:
|
case ArtifactPreviewKind.unsupported:
|
||||||
case ArtifactPreviewKind.unavailable:
|
case ArtifactPreviewKind.unavailable:
|
||||||
return const SizedBox.shrink();
|
return const SizedBox.shrink();
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import '../../../ui/input/arrow_key_pager.dart';
|
|||||||
import 'artifact_selection_facts.dart';
|
import 'artifact_selection_facts.dart';
|
||||||
import '../actions/artifact_file_bridge.dart';
|
import '../actions/artifact_file_bridge.dart';
|
||||||
import '../domain/artifact_groups.dart';
|
import '../domain/artifact_groups.dart';
|
||||||
|
import '../domain/artifact_kind.dart';
|
||||||
import '../domain/artifact_preview.dart';
|
import '../domain/artifact_preview.dart';
|
||||||
import '../domain/artifact_preview_failure.dart';
|
import '../domain/artifact_preview_failure.dart';
|
||||||
import '../domain/artifact_url.dart';
|
import '../domain/artifact_url.dart';
|
||||||
@@ -43,6 +44,8 @@ class ArtifactViewerPage extends StatefulWidget {
|
|||||||
required this.selectedIdentity,
|
required this.selectedIdentity,
|
||||||
this.includeExternalDocuments = false,
|
this.includeExternalDocuments = false,
|
||||||
this.configuredEndpoint = '',
|
this.configuredEndpoint = '',
|
||||||
|
this.downloadUrl,
|
||||||
|
this.previewFormat = artifactPreviewFormat,
|
||||||
this.fetch = fetchArtifact,
|
this.fetch = fetchArtifact,
|
||||||
this.markdownBuilder = defaultArtifactMarkdown,
|
this.markdownBuilder = defaultArtifactMarkdown,
|
||||||
this.openExternal = openArtifactExternally,
|
this.openExternal = openArtifactExternally,
|
||||||
@@ -60,6 +63,11 @@ class ArtifactViewerPage extends StatefulWidget {
|
|||||||
final bool includeExternalDocuments;
|
final bool includeExternalDocuments;
|
||||||
|
|
||||||
final String configuredEndpoint;
|
final String configuredEndpoint;
|
||||||
|
final String? downloadUrl;
|
||||||
|
|
||||||
|
/// The preview rule; the Files panel passes its own (every HTML previews).
|
||||||
|
final ArtifactPreviewFormat Function(String contentType, String name)
|
||||||
|
previewFormat;
|
||||||
final ArtifactFetch fetch;
|
final ArtifactFetch fetch;
|
||||||
final ArtifactMarkdownBuilder markdownBuilder;
|
final ArtifactMarkdownBuilder markdownBuilder;
|
||||||
final ArtifactExternalOpen openExternal;
|
final ArtifactExternalOpen openExternal;
|
||||||
@@ -110,6 +118,7 @@ class _ArtifactViewerPageState extends State<ArtifactViewerPage>
|
|||||||
return planArtifactPreview(
|
return planArtifactPreview(
|
||||||
artifact: page.artifact,
|
artifact: page.artifact,
|
||||||
configuredEndpoint: widget.configuredEndpoint,
|
configuredEndpoint: widget.configuredEndpoint,
|
||||||
|
format: widget.previewFormat,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,6 +233,9 @@ class _ArtifactViewerPageState extends State<ArtifactViewerPage>
|
|||||||
Widget buildFrame(BuildContext context, {required bool fullscreen}) {
|
Widget buildFrame(BuildContext context, {required bool fullscreen}) {
|
||||||
final page = _page;
|
final page = _page;
|
||||||
final plan = _plan;
|
final plan = _plan;
|
||||||
|
final downloadResolved = widget.downloadUrl == null
|
||||||
|
? null
|
||||||
|
: resolveArtifactUrl(widget.configuredEndpoint, widget.downloadUrl!);
|
||||||
final title = page == null
|
final title = page == null
|
||||||
? artifactViewerTitle
|
? artifactViewerTitle
|
||||||
: artifactDisplayName(page.artifact);
|
: artifactDisplayName(page.artifact);
|
||||||
@@ -266,6 +278,7 @@ class _ArtifactViewerPageState extends State<ArtifactViewerPage>
|
|||||||
status: _status,
|
status: _status,
|
||||||
fetch: widget.fetch,
|
fetch: widget.fetch,
|
||||||
fileBridge: widget.fileBridge,
|
fileBridge: widget.fileBridge,
|
||||||
|
downloadResolved: downloadResolved,
|
||||||
onPrevious: () => _step(-1),
|
onPrevious: () => _step(-1),
|
||||||
onNext: () => _step(1),
|
onNext: () => _step(1),
|
||||||
// A failure is never cached, so loading again fetches afresh.
|
// A failure is never cached, so loading again fetches afresh.
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class FilesController extends ChangeNotifier {
|
|||||||
filter = '';
|
filter = '';
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (_disposed || request != _request) return;
|
if (_disposed || request != _request) return;
|
||||||
error = '$e';
|
error = "Couldn't load this folder.";
|
||||||
} finally {
|
} finally {
|
||||||
if (!_disposed && request == _request) {
|
if (!_disposed && request == _request) {
|
||||||
loading = false;
|
loading = false;
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import '../../../ui/adaptive/host.dart';
|
||||||
|
import '../../artifacts/actions/artifact_transfer.dart';
|
||||||
|
import '../../artifacts/domain/artifact_kind.dart';
|
||||||
|
import '../../artifacts/ui/artifact_external_open.dart';
|
||||||
|
import '../data/directory_listing.dart';
|
||||||
|
import 'files_download.dart';
|
||||||
|
import 'files_models.dart';
|
||||||
|
import 'files_preview.dart';
|
||||||
|
import 'files_urls.dart';
|
||||||
|
|
||||||
|
/// Details and host-native actions for a file the embedded viewer cannot show.
|
||||||
|
void showFileDetails(
|
||||||
|
BuildContext context, {
|
||||||
|
required DirectoryEntry entry,
|
||||||
|
required FileUrls? urls,
|
||||||
|
required Future<ArtifactTransferResult> Function()? download,
|
||||||
|
required ArtifactExternalOpen openExternal,
|
||||||
|
}) {
|
||||||
|
final cupertino = usesCupertinoHost(context);
|
||||||
|
Widget content(BuildContext sheet) {
|
||||||
|
Future<void> open() async {
|
||||||
|
var opened = false;
|
||||||
|
try {
|
||||||
|
opened = await openExternal(urls!.view);
|
||||||
|
} catch (_) {
|
||||||
|
/* keep the sheet and download action available */
|
||||||
|
}
|
||||||
|
if (opened && sheet.mounted) Navigator.pop(sheet);
|
||||||
|
}
|
||||||
|
|
||||||
|
final body = SafeArea(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(20),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
entry.name,
|
||||||
|
style: cupertino
|
||||||
|
? CupertinoTheme.of(sheet).textTheme.navTitleTextStyle
|
||||||
|
: Theme.of(sheet).textTheme.titleLarge,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
Text(
|
||||||
|
'${artifactKindLabel(artifactKind(fileContentType(entry.name), entry.name))} · ${fileSizeLabel(entry.size)}',
|
||||||
|
),
|
||||||
|
Text('Modified: ${fileModifiedLabel(entry.modified)}'),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Text(
|
||||||
|
urls == null
|
||||||
|
? 'No server address is configured, so this file cannot be fetched.'
|
||||||
|
: 'This file type cannot be previewed here.',
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
if (download != null) FileDownloadButton(download: download),
|
||||||
|
if (urls != null)
|
||||||
|
cupertino
|
||||||
|
? CupertinoButton(
|
||||||
|
onPressed: open,
|
||||||
|
child: const Text('Open externally'),
|
||||||
|
)
|
||||||
|
: TextButton.icon(
|
||||||
|
onPressed: open,
|
||||||
|
icon: const Icon(Icons.open_in_new),
|
||||||
|
label: const Text('Open externally'),
|
||||||
|
),
|
||||||
|
if (cupertino)
|
||||||
|
CupertinoButton(
|
||||||
|
onPressed: () => Navigator.pop(sheet),
|
||||||
|
child: const Text('Close'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return cupertino
|
||||||
|
? CupertinoPopupSurface(
|
||||||
|
child: DefaultTextStyle(
|
||||||
|
style: CupertinoTheme.of(sheet).textTheme.textStyle,
|
||||||
|
child: body,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: body;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cupertino) {
|
||||||
|
showCupertinoModalPopup<void>(context: context, builder: content);
|
||||||
|
} else {
|
||||||
|
showModalBottomSheet<void>(
|
||||||
|
context: context,
|
||||||
|
showDragHandle: true,
|
||||||
|
builder: content,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,141 @@
|
|||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import '../../../ui/adaptive/host.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
|
import '../../artifacts/actions/artifact_file.dart';
|
||||||
|
import '../../artifacts/actions/artifact_file_bridge.dart';
|
||||||
|
import '../../artifacts/actions/artifact_transfer.dart';
|
||||||
|
import '../../artifacts/ui/artifact_viewer_fetch.dart';
|
||||||
|
import '../data/directory_listing.dart';
|
||||||
|
import 'files_preview.dart';
|
||||||
|
import 'files_urls.dart';
|
||||||
|
|
||||||
|
const String fileDownloadFailed = 'Could not download the file. Try again.';
|
||||||
|
|
||||||
|
/// Opens an attachment url in the browser (web only); tests inject a recorder.
|
||||||
|
typedef FileUrlLauncher = Future<bool> Function(Uri url);
|
||||||
|
|
||||||
|
Future<bool> launchFileUrl(Uri url) =>
|
||||||
|
launchUrl(url, mode: LaunchMode.externalApplication);
|
||||||
|
|
||||||
|
/// Downloads one working-directory file.
|
||||||
|
///
|
||||||
|
/// On the web the browser handles the `download=1` url itself: the attachment
|
||||||
|
/// disposition makes it save the file with its own name, so no bytes pass
|
||||||
|
/// through the app. Everywhere else the bytes are fetched from the inline url
|
||||||
|
/// and handed to the host through the artifact file bridge (system "Save as"),
|
||||||
|
/// exactly as an artifact download is.
|
||||||
|
Future<ArtifactTransferResult> downloadFile({
|
||||||
|
required DirectoryEntry entry,
|
||||||
|
required FileUrls urls,
|
||||||
|
ArtifactFileBridge bridge = const ArtifactFileBridge(),
|
||||||
|
ArtifactFetch fetch = fetchArtifact,
|
||||||
|
FileUrlLauncher launch = launchFileUrl,
|
||||||
|
}) async {
|
||||||
|
try {
|
||||||
|
if (kIsWeb) {
|
||||||
|
final opened = await launch(urls.download);
|
||||||
|
return opened
|
||||||
|
? ArtifactTransferResult(
|
||||||
|
ArtifactTransferState.saved,
|
||||||
|
'Downloading ${entry.name}.',
|
||||||
|
)
|
||||||
|
: const ArtifactTransferResult(
|
||||||
|
ArtifactTransferState.failed,
|
||||||
|
fileDownloadFailed,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
final ArtifactFetchResult result;
|
||||||
|
try {
|
||||||
|
result = await fetch(urls.view);
|
||||||
|
} on ArtifactFetchException {
|
||||||
|
return const ArtifactTransferResult(
|
||||||
|
ArtifactTransferState.failed,
|
||||||
|
fileDownloadFailed,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (!result.ok) {
|
||||||
|
return const ArtifactTransferResult(
|
||||||
|
ArtifactTransferState.failed,
|
||||||
|
fileDownloadFailed,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return await bridge.saveFile(
|
||||||
|
ArtifactFile(
|
||||||
|
name: entry.name,
|
||||||
|
mimeType: fileContentType(entry.name),
|
||||||
|
bytes: result.bytes,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} catch (_) {
|
||||||
|
return const ArtifactTransferResult(
|
||||||
|
ArtifactTransferState.failed,
|
||||||
|
fileDownloadFailed,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The Download button of the unviewable-file sheet, with its outcome below.
|
||||||
|
class FileDownloadButton extends StatefulWidget {
|
||||||
|
const FileDownloadButton({super.key, required this.download});
|
||||||
|
|
||||||
|
/// Runs the transfer; the sheet's owner binds the entry, urls and bridge.
|
||||||
|
final Future<ArtifactTransferResult> Function() download;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<FileDownloadButton> createState() => _FileDownloadButtonState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _FileDownloadButtonState extends State<FileDownloadButton> {
|
||||||
|
bool _busy = false;
|
||||||
|
String? _status;
|
||||||
|
|
||||||
|
Future<void> _download() async {
|
||||||
|
if (_busy) return;
|
||||||
|
setState(() {
|
||||||
|
_busy = true;
|
||||||
|
_status = null;
|
||||||
|
});
|
||||||
|
String status;
|
||||||
|
try {
|
||||||
|
status = (await widget.download()).message;
|
||||||
|
} catch (_) {
|
||||||
|
status = fileDownloadFailed;
|
||||||
|
}
|
||||||
|
if (!mounted) return;
|
||||||
|
setState(() {
|
||||||
|
_busy = false;
|
||||||
|
_status = status.isEmpty ? null : status;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) => Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
if (usesCupertinoHost(context))
|
||||||
|
CupertinoButton.filled(
|
||||||
|
onPressed: _busy ? null : _download,
|
||||||
|
child: _busy
|
||||||
|
? const CupertinoActivityIndicator()
|
||||||
|
: const Text('Download'),
|
||||||
|
)
|
||||||
|
else
|
||||||
|
FilledButton.icon(
|
||||||
|
onPressed: _busy ? null : _download,
|
||||||
|
icon: _busy
|
||||||
|
? const SizedBox(
|
||||||
|
width: 18,
|
||||||
|
height: 18,
|
||||||
|
child: CircularProgressIndicator(strokeWidth: 2),
|
||||||
|
)
|
||||||
|
: const Icon(Icons.download_outlined),
|
||||||
|
label: const Text('Download'),
|
||||||
|
),
|
||||||
|
if (_status != null)
|
||||||
|
Padding(padding: const EdgeInsets.only(top: 8), child: Text(_status!)),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import '../../../ui/layout/app_overflow_menu.dart';
|
||||||
|
import '../data/directory_listing.dart';
|
||||||
|
import '../ui/sessions/chat_adaptive.dart';
|
||||||
|
import 'files_controller.dart';
|
||||||
|
import 'files_models.dart';
|
||||||
|
|
||||||
|
class FilesHeader extends StatelessWidget {
|
||||||
|
const FilesHeader({
|
||||||
|
super.key,
|
||||||
|
required this.controller,
|
||||||
|
required this.filter,
|
||||||
|
});
|
||||||
|
final FilesController controller;
|
||||||
|
final TextEditingController filter;
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final listing = controller.listing;
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(12, 8, 8, 4),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
if (listing?.parent != null)
|
||||||
|
IconButton(
|
||||||
|
tooltip: 'Back',
|
||||||
|
onPressed: controller.loading
|
||||||
|
? null
|
||||||
|
: () => controller.open(listing!.parent),
|
||||||
|
icon: const Icon(Icons.arrow_back),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
homeRelativeLabel(
|
||||||
|
listing?.home ?? '',
|
||||||
|
listing?.path ?? controller.initialPath,
|
||||||
|
),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
tooltip: 'Refresh',
|
||||||
|
onPressed: controller.loading ? null : controller.retry,
|
||||||
|
icon: const Icon(Icons.refresh),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
tooltip: controller.view == FilesViewMode.list
|
||||||
|
? 'Grid view'
|
||||||
|
: 'List view',
|
||||||
|
onPressed: () => controller.setView(
|
||||||
|
controller.view == FilesViewMode.list
|
||||||
|
? FilesViewMode.grid
|
||||||
|
: FilesViewMode.list,
|
||||||
|
),
|
||||||
|
icon: Icon(
|
||||||
|
controller.view == FilesViewMode.list
|
||||||
|
? Icons.grid_view
|
||||||
|
: Icons.view_list,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
AppOverflowMenu<FilesSortKey>(
|
||||||
|
label: 'Sort',
|
||||||
|
onSelected: (_, key) =>
|
||||||
|
controller.setSort(controller.sort.reverseOr(key)),
|
||||||
|
actions: [
|
||||||
|
for (final key in FilesSortKey.values)
|
||||||
|
AppMenuAction(
|
||||||
|
value: key,
|
||||||
|
label:
|
||||||
|
'${key.name}${controller.sort.key == key ? (controller.sort.ascending ? ' ↑' : ' ↓') : ''}',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
if (listing != null)
|
||||||
|
SingleChildScrollView(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
for (final crumb in folderCrumbs(listing.home, listing.path))
|
||||||
|
chatControlsStyleOf(context) == ChatControlsStyle.cupertino
|
||||||
|
? CupertinoButton(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 6),
|
||||||
|
onPressed: controller.loading
|
||||||
|
? null
|
||||||
|
: () => controller.open(crumb.path),
|
||||||
|
child: Text(crumb.label),
|
||||||
|
)
|
||||||
|
: TextButton(
|
||||||
|
onPressed: controller.loading
|
||||||
|
? null
|
||||||
|
: () => controller.open(crumb.path),
|
||||||
|
child: Text(crumb.label),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child:
|
||||||
|
chatControlsStyleOf(context) == ChatControlsStyle.cupertino
|
||||||
|
? CupertinoSearchTextField(
|
||||||
|
controller: filter,
|
||||||
|
onChanged: controller.setFilter,
|
||||||
|
placeholder: 'Filter files',
|
||||||
|
)
|
||||||
|
: TextField(
|
||||||
|
controller: filter,
|
||||||
|
onChanged: controller.setFilter,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
prefixIcon: Icon(Icons.search),
|
||||||
|
hintText: 'Filter files',
|
||||||
|
isDense: true,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
tooltip: 'Show hidden files',
|
||||||
|
onPressed: () =>
|
||||||
|
controller.toggleHidden(!controller.showHidden),
|
||||||
|
icon: Icon(
|
||||||
|
controller.showHidden
|
||||||
|
? Icons.visibility
|
||||||
|
: Icons.visibility_off,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import '../../artifacts/domain/artifact_kind.dart';
|
import '../../artifacts/domain/artifact_kind.dart';
|
||||||
import '../data/directory_listing.dart';
|
import '../data/directory_listing.dart';
|
||||||
|
import 'files_preview.dart';
|
||||||
|
|
||||||
/// Chooses the same broad kind glyphs used by the artifact gallery.
|
/// Chooses the same broad kind glyphs used by the artifact gallery.
|
||||||
IconData fileIcon(DirectoryEntry entry) {
|
IconData fileIcon(DirectoryEntry entry) {
|
||||||
if (entry.isDir) return Icons.folder_outlined;
|
if (entry.isDir) return Icons.folder_outlined;
|
||||||
|
|
||||||
switch (artifactKind('', entry.name)) {
|
switch (artifactKind(fileContentType(entry.name), entry.name)) {
|
||||||
case ArtifactKind.image:
|
case ArtifactKind.image:
|
||||||
return Icons.image_outlined;
|
return Icons.image_outlined;
|
||||||
case ArtifactKind.video:
|
case ArtifactKind.video:
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import '../data/directory_listing.dart';
|
import '../data/directory_listing.dart';
|
||||||
|
import 'files_preview.dart';
|
||||||
import '../../artifacts/domain/artifact_kind.dart';
|
import '../../artifacts/domain/artifact_kind.dart';
|
||||||
|
|
||||||
enum FilesViewMode { list, grid }
|
enum FilesViewMode { list, grid }
|
||||||
@@ -39,14 +40,15 @@ List<DirectoryEntry> sortFileEntries(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
String fileKind(DirectoryEntry entry) =>
|
String fileKind(DirectoryEntry entry) => entry.isDir
|
||||||
entry.isDir ? 'Folder' : artifactKind('', entry.name).name;
|
? 'Folder'
|
||||||
|
: artifactKind(fileContentType(entry.name), entry.name).name;
|
||||||
|
|
||||||
String fileSizeLabel(int? size) {
|
String fileSizeLabel(int? size) {
|
||||||
if (size == null) return '—';
|
if (size == null) return '—';
|
||||||
if (size < 1024) return '$size B';
|
if (size < 1024) return '$size B';
|
||||||
final units = ['KiB', 'MiB', 'GiB', 'TiB'];
|
final units = ['KiB', 'MiB', 'GiB', 'TiB'];
|
||||||
var value = size.toDouble();
|
var value = size / 1024;
|
||||||
var unit = 0;
|
var unit = 0;
|
||||||
while (value >= 1024 && unit < units.length - 1) {
|
while (value >= 1024 && unit < units.length - 1) {
|
||||||
value /= 1024;
|
value /= 1024;
|
||||||
@@ -54,3 +56,12 @@ String fileSizeLabel(int? size) {
|
|||||||
}
|
}
|
||||||
return '${value.toStringAsFixed(value >= 10 ? 0 : 1)} ${units[unit]}';
|
return '${value.toStringAsFixed(value >= 10 ? 0 : 1)} ${units[unit]}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A compact local timestamp; keep missing or malformed values unobtrusive.
|
||||||
|
String fileModifiedLabel(String? value) {
|
||||||
|
final date = DateTime.tryParse(value ?? '')?.toLocal();
|
||||||
|
if (date == null) return 'Unknown';
|
||||||
|
String two(int n) => n.toString().padLeft(2, '0');
|
||||||
|
return '${date.year}-${two(date.month)}-${two(date.day)} '
|
||||||
|
'${two(date.hour)}:${two(date.minute)}';
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import '../../../core/transport/pipelines_client.dart';
|
||||||
import '../data/directory_listing.dart';
|
import '../data/directory_listing.dart';
|
||||||
import '../ui/sessions/chat_adaptive.dart';
|
import '../ui/sessions/chat_adaptive.dart';
|
||||||
import 'files_controller.dart';
|
import 'files_controller.dart';
|
||||||
import 'files_icons.dart';
|
import 'files_icons.dart';
|
||||||
import 'files_models.dart';
|
import 'files_models.dart';
|
||||||
|
import 'files_thumbnail.dart';
|
||||||
|
import 'files_viewer.dart';
|
||||||
|
import 'files_header.dart';
|
||||||
|
import '../../../ui/layout/app_overflow_menu.dart';
|
||||||
|
|
||||||
const double filesPanelMinWidth = 280;
|
const double filesPanelMinWidth = 280;
|
||||||
const double filesPanelMaxWidth = 420;
|
const double filesPanelMaxWidth = 420;
|
||||||
@@ -13,10 +17,21 @@ const double filesPanelFraction = .30;
|
|||||||
double filesPanelWidth(double available) => (available * filesPanelFraction)
|
double filesPanelWidth(double available) => (available * filesPanelFraction)
|
||||||
.clamp(filesPanelMinWidth, filesPanelMaxWidth);
|
.clamp(filesPanelMinWidth, filesPanelMaxWidth);
|
||||||
|
|
||||||
|
/// The two explicit actions of a file's row or tile menu.
|
||||||
|
enum FileAction { open, download }
|
||||||
|
|
||||||
class FilesPanel extends StatefulWidget {
|
class FilesPanel extends StatefulWidget {
|
||||||
const FilesPanel({super.key, required this.controller, this.onOpen});
|
const FilesPanel({
|
||||||
|
super.key,
|
||||||
|
required this.controller,
|
||||||
|
this.onOpen,
|
||||||
|
this.viewer = const FilesViewer(),
|
||||||
|
});
|
||||||
final FilesController controller;
|
final FilesController controller;
|
||||||
final ValueChanged<DirectoryEntry>? onOpen;
|
final ValueChanged<DirectoryEntry>? onOpen;
|
||||||
|
|
||||||
|
/// Opens and downloads files; tests inject one that never fetches.
|
||||||
|
final FilesViewer viewer;
|
||||||
@override
|
@override
|
||||||
State<FilesPanel> createState() => _FilesPanelState();
|
State<FilesPanel> createState() => _FilesPanelState();
|
||||||
}
|
}
|
||||||
@@ -24,6 +39,7 @@ class FilesPanel extends StatefulWidget {
|
|||||||
class _FilesPanelState extends State<FilesPanel> {
|
class _FilesPanelState extends State<FilesPanel> {
|
||||||
late final TextEditingController _filter = TextEditingController();
|
late final TextEditingController _filter = TextEditingController();
|
||||||
FilesController get controller => widget.controller;
|
FilesController get controller => widget.controller;
|
||||||
|
String get _endpoint => configuredGatewayEndpoint(controller.gateway);
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@@ -32,7 +48,10 @@ class _FilesPanelState extends State<FilesPanel> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _changed() {
|
void _changed() {
|
||||||
if (mounted) setState(() {});
|
if (mounted) {
|
||||||
|
if (_filter.text != controller.filter) _filter.text = controller.filter;
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -45,6 +64,7 @@ class _FilesPanelState extends State<FilesPanel> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final listing = controller.listing;
|
final listing = controller.listing;
|
||||||
|
final entries = controller.entries;
|
||||||
if (controller.missingDirectory) {
|
if (controller.missingDirectory) {
|
||||||
return const _FilesMessage('This chat has no working directory.');
|
return const _FilesMessage('This chat has no working directory.');
|
||||||
}
|
}
|
||||||
@@ -52,7 +72,7 @@ class _FilesPanelState extends State<FilesPanel> {
|
|||||||
color: Theme.of(context).colorScheme.surface,
|
color: Theme.of(context).colorScheme.surface,
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
_header(context, listing),
|
FilesHeader(controller: controller, filter: _filter),
|
||||||
if (controller.error != null)
|
if (controller.error != null)
|
||||||
ChatErrorNotice(
|
ChatErrorNotice(
|
||||||
message: controller.error!,
|
message: controller.error!,
|
||||||
@@ -60,13 +80,19 @@ class _FilesPanelState extends State<FilesPanel> {
|
|||||||
),
|
),
|
||||||
if (controller.loading && listing == null)
|
if (controller.loading && listing == null)
|
||||||
const Expanded(child: ChatLoadingIndicator())
|
const Expanded(child: ChatLoadingIndicator())
|
||||||
else if (listing != null &&
|
else if (listing != null && entries.isEmpty && !controller.loading)
|
||||||
controller.entries.isEmpty &&
|
Expanded(
|
||||||
!controller.loading)
|
child: _FilesMessage(
|
||||||
const Expanded(child: _FilesMessage('This folder is empty.'))
|
controller.filter.isEmpty
|
||||||
|
? 'This folder is empty.'
|
||||||
|
: 'No files match your filter.',
|
||||||
|
),
|
||||||
|
)
|
||||||
else
|
else
|
||||||
Expanded(
|
Expanded(
|
||||||
child: controller.view == FilesViewMode.grid ? _grid() : _list(),
|
child: controller.view == FilesViewMode.grid
|
||||||
|
? _grid(entries)
|
||||||
|
: _list(entries),
|
||||||
),
|
),
|
||||||
if (listing?.truncated == true)
|
if (listing?.truncated == true)
|
||||||
const Padding(
|
const Padding(
|
||||||
@@ -78,137 +104,55 @@ class _FilesPanelState extends State<FilesPanel> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _header(BuildContext context, DirectoryListing? listing) => Padding(
|
Widget _list(List<DirectoryEntry> entries) => ListView.builder(
|
||||||
padding: const EdgeInsets.fromLTRB(12, 8, 8, 4),
|
itemCount: entries.length,
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
if (listing?.parent != null)
|
|
||||||
IconButton(
|
|
||||||
tooltip: 'Back',
|
|
||||||
onPressed: controller.loading
|
|
||||||
? null
|
|
||||||
: () => controller.open(listing!.parent),
|
|
||||||
icon: const Icon(Icons.arrow_back),
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
homeRelativeLabel(
|
|
||||||
listing?.home ?? '',
|
|
||||||
listing?.path ?? controller.initialPath,
|
|
||||||
),
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
IconButton(
|
|
||||||
tooltip: 'Refresh',
|
|
||||||
onPressed: controller.loading ? null : controller.retry,
|
|
||||||
icon: const Icon(Icons.refresh),
|
|
||||||
),
|
|
||||||
IconButton(
|
|
||||||
tooltip: controller.view == FilesViewMode.list
|
|
||||||
? 'Grid view'
|
|
||||||
: 'List view',
|
|
||||||
onPressed: () => controller.setView(
|
|
||||||
controller.view == FilesViewMode.list
|
|
||||||
? FilesViewMode.grid
|
|
||||||
: FilesViewMode.list,
|
|
||||||
),
|
|
||||||
icon: Icon(
|
|
||||||
controller.view == FilesViewMode.list
|
|
||||||
? Icons.grid_view
|
|
||||||
: Icons.view_list,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
PopupMenuButton<FilesSortKey>(
|
|
||||||
initialValue: controller.sort.key,
|
|
||||||
tooltip: 'Sort',
|
|
||||||
onSelected: (key) =>
|
|
||||||
controller.setSort(controller.sort.reverseOr(key)),
|
|
||||||
itemBuilder: (_) => [
|
|
||||||
for (final key in FilesSortKey.values)
|
|
||||||
PopupMenuItem(value: key, child: Text(key.name)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: chatControlsStyleOf(context) == ChatControlsStyle.cupertino
|
|
||||||
? CupertinoSearchTextField(
|
|
||||||
controller: _filter,
|
|
||||||
onChanged: controller.setFilter,
|
|
||||||
placeholder: 'Filter files',
|
|
||||||
)
|
|
||||||
: TextField(
|
|
||||||
controller: _filter,
|
|
||||||
onChanged: controller.setFilter,
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
prefixIcon: Icon(Icons.search),
|
|
||||||
hintText: 'Filter files',
|
|
||||||
isDense: true,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
IconButton(
|
|
||||||
tooltip: 'Show hidden files',
|
|
||||||
onPressed: () => controller.toggleHidden(!controller.showHidden),
|
|
||||||
icon: Icon(
|
|
||||||
controller.showHidden ? Icons.visibility : Icons.visibility_off,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
Widget _list() => ListView.builder(
|
|
||||||
itemCount: controller.entries.length,
|
|
||||||
itemBuilder: (_, index) {
|
itemBuilder: (_, index) {
|
||||||
final entry = controller.entries[index];
|
final entry = entries[index];
|
||||||
return ListTile(
|
return ListTile(
|
||||||
onTap: () => entry.isDir
|
onTap: () => entry.isDir ? controller.open(entry.path) : _open(entry),
|
||||||
? controller.open(entry.path)
|
leading: Icon(fileIcon(entry)),
|
||||||
: widget.onOpen?.call(entry),
|
title: Text(entry.name, maxLines: 2, overflow: TextOverflow.ellipsis),
|
||||||
leading: Icon(
|
|
||||||
fileIcon(entry),
|
|
||||||
),
|
|
||||||
title: Text(entry.name),
|
|
||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
entry.isDir
|
entry.isDir
|
||||||
? 'Folder'
|
? 'Folder'
|
||||||
: '${entry.modified ?? 'Unknown'} · ${fileSizeLabel(entry.size)}',
|
: '${fileModifiedLabel(entry.modified)} · ${fileSizeLabel(entry.size)}',
|
||||||
),
|
),
|
||||||
trailing: entry.isDir ? null : Text(fileKind(entry)),
|
trailing: entry.isDir
|
||||||
|
? null
|
||||||
|
: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [Text(fileKind(entry)), _menu(entry)],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
Widget _grid() => GridView.builder(
|
Widget _grid(List<DirectoryEntry> entries) => GridView.builder(
|
||||||
padding: const EdgeInsets.all(12),
|
padding: const EdgeInsets.all(12),
|
||||||
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
|
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
|
||||||
maxCrossAxisExtent: 180,
|
maxCrossAxisExtent: 180,
|
||||||
childAspectRatio: 1.25,
|
childAspectRatio: .85,
|
||||||
),
|
),
|
||||||
itemCount: controller.entries.length,
|
itemCount: entries.length,
|
||||||
itemBuilder: (_, index) {
|
itemBuilder: (_, index) {
|
||||||
final entry = controller.entries[index];
|
final entry = entries[index];
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () => entry.isDir
|
onTap: () => entry.isDir ? controller.open(entry.path) : _open(entry),
|
||||||
? controller.open(entry.path)
|
|
||||||
: widget.onOpen?.call(entry),
|
|
||||||
child: Card(
|
child: Card(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(12),
|
padding: const EdgeInsets.all(12),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
children: [
|
||||||
Icon(
|
Align(
|
||||||
fileIcon(entry),
|
alignment: Alignment.centerRight,
|
||||||
size: 32,
|
child: entry.isDir
|
||||||
|
? const SizedBox(height: 48)
|
||||||
|
: _menu(entry),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Center(
|
||||||
|
child: FileThumbnail(entry: entry, endpoint: _endpoint),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Text(
|
Text(
|
||||||
@@ -224,6 +168,32 @@ class _FilesPanelState extends State<FilesPanel> {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/// Open and Download for one file; a folder has no menu (nothing to save).
|
||||||
|
Widget _menu(DirectoryEntry entry) => AppOverflowMenu<FileAction>(
|
||||||
|
label: 'File actions',
|
||||||
|
sheetTitle: entry.name,
|
||||||
|
onSelected: (_, action) => switch (action) {
|
||||||
|
FileAction.open => _open(entry),
|
||||||
|
FileAction.download => widget.viewer.download(
|
||||||
|
context,
|
||||||
|
endpoint: _endpoint,
|
||||||
|
entry: entry,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
actions: const [
|
||||||
|
AppMenuAction(value: FileAction.open, label: 'Open'),
|
||||||
|
AppMenuAction(value: FileAction.download, label: 'Download'),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
void _open(DirectoryEntry entry) {
|
||||||
|
if (widget.onOpen != null) {
|
||||||
|
widget.onOpen!(entry);
|
||||||
|
} else {
|
||||||
|
widget.viewer.open(context, endpoint: _endpoint, entry: entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _FilesMessage extends StatelessWidget {
|
class _FilesMessage extends StatelessWidget {
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
import '../../artifacts/domain/artifact_kind.dart';
|
||||||
|
|
||||||
|
/// The media type the files endpoint serves for [name], from its extension.
|
||||||
|
///
|
||||||
|
/// The server sets the real `Content-Type` on the wire; this is the client's
|
||||||
|
/// own classification for choosing a viewer, a thumbnail and a download type.
|
||||||
|
String fileContentType(String name) {
|
||||||
|
final dot = name.lastIndexOf('.');
|
||||||
|
final ext = dot == -1 ? '' : name.substring(dot + 1).toLowerCase();
|
||||||
|
return _types[ext] ?? 'application/octet-stream';
|
||||||
|
}
|
||||||
|
|
||||||
|
const Map<String, String> _types = {
|
||||||
|
'svg': 'image/svg+xml',
|
||||||
|
'ico': 'image/x-icon',
|
||||||
|
'bmp': 'image/bmp',
|
||||||
|
'avif': 'image/avif',
|
||||||
|
'dart': 'text/plain',
|
||||||
|
'png': 'image/png',
|
||||||
|
'jpg': 'image/jpeg',
|
||||||
|
'jpeg': 'image/jpeg',
|
||||||
|
'gif': 'image/gif',
|
||||||
|
'webp': 'image/webp',
|
||||||
|
'mp4': 'video/mp4',
|
||||||
|
'webm': 'video/webm',
|
||||||
|
'mov': 'video/quicktime',
|
||||||
|
'mp3': 'audio/mpeg',
|
||||||
|
'wav': 'audio/wav',
|
||||||
|
'm4a': 'audio/mp4',
|
||||||
|
'pdf': 'application/pdf',
|
||||||
|
'json': 'application/json',
|
||||||
|
'csv': 'text/csv',
|
||||||
|
'tsv': 'text/tab-separated-values',
|
||||||
|
'html': 'text/html',
|
||||||
|
'htm': 'text/html',
|
||||||
|
'md': 'text/markdown',
|
||||||
|
'markdown': 'text/markdown',
|
||||||
|
'txt': 'text/plain',
|
||||||
|
'log': 'text/plain',
|
||||||
|
'zip': 'application/zip',
|
||||||
|
'gz': 'application/gzip',
|
||||||
|
'tar': 'application/x-tar',
|
||||||
|
};
|
||||||
|
|
||||||
|
/// How the Files panel's viewer presents [name].
|
||||||
|
///
|
||||||
|
/// Unlike the artifact gallery, which keeps a turn's `session.html` export (and
|
||||||
|
/// its repairs) external-only, every HTML document in a working directory
|
||||||
|
/// previews inertly here: a file called `session.html` in a folder is just a
|
||||||
|
/// web page. Everything else follows the shared [artifactPreviewFormat] rule.
|
||||||
|
ArtifactPreviewFormat filePreviewFormat(String contentType, String name) {
|
||||||
|
final mime = contentType.split(';').first.trim().toLowerCase();
|
||||||
|
final lower = name.toLowerCase();
|
||||||
|
if (mime == 'image/svg+xml' ||
|
||||||
|
mime == 'text/html' ||
|
||||||
|
lower.endsWith('.html') ||
|
||||||
|
lower.endsWith('.htm')) {
|
||||||
|
return ArtifactPreviewFormat.html;
|
||||||
|
}
|
||||||
|
return artifactPreviewFormat(contentType, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether the Files panel opens [name] in the in-app viewer rather than the
|
||||||
|
/// unviewable sheet (PDFs open externally and are not previewable here).
|
||||||
|
bool isPreviewableFile(String name) =>
|
||||||
|
filePreviewFormat(fileContentType(name), name) !=
|
||||||
|
ArtifactPreviewFormat.none;
|
||||||
|
|
||||||
|
/// Whether [name] is an image the grid draws as a thumbnail.
|
||||||
|
bool isThumbnailFile(String name) =>
|
||||||
|
filePreviewFormat(fileContentType(name), name) ==
|
||||||
|
ArtifactPreviewFormat.image;
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../data/directory_listing.dart';
|
||||||
|
import 'files_icons.dart';
|
||||||
|
import 'files_preview.dart';
|
||||||
|
import 'files_urls.dart';
|
||||||
|
|
||||||
|
/// The logical size of a grid thumbnail.
|
||||||
|
const double filesThumbnailSize = 56;
|
||||||
|
|
||||||
|
/// The largest decode scale a thumbnail is allowed, so a 4x display still
|
||||||
|
/// decodes a 56 dp tile to at most 224 px per side.
|
||||||
|
const double filesThumbnailMaxScale = 4;
|
||||||
|
|
||||||
|
/// The pixel edge a thumbnail decodes to: the tile size at the display's pixel
|
||||||
|
/// ratio, bounded. The shared [PaintingBinding.imageCache] then holds a few
|
||||||
|
/// hundred KiB at most per image instead of a full-size decode.
|
||||||
|
int filesThumbnailDecodeSize(double devicePixelRatio) =>
|
||||||
|
(filesThumbnailSize * devicePixelRatio.clamp(1, filesThumbnailMaxScale))
|
||||||
|
.round();
|
||||||
|
|
||||||
|
/// A grid tile's picture: an image file's own bytes from the files endpoint,
|
||||||
|
/// decoded at tile size, with the kind glyph while loading and when the fetch
|
||||||
|
/// or decode fails. Non-image files show the kind glyph.
|
||||||
|
class FileThumbnail extends StatefulWidget {
|
||||||
|
const FileThumbnail({super.key, required this.entry, required this.endpoint});
|
||||||
|
|
||||||
|
final DirectoryEntry entry;
|
||||||
|
final String endpoint;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<FileThumbnail> createState() => _FileThumbnailState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _FileThumbnailState extends State<FileThumbnail> {
|
||||||
|
ImageProvider? _provider;
|
||||||
|
String? _url;
|
||||||
|
int? _decode;
|
||||||
|
|
||||||
|
// Keep the shared image cache unchanged. Scrolled-out thumbnails release
|
||||||
|
// their decoded cache entry, bounding retention to the lazily built tiles.
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_provider?.evict();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final entry = widget.entry;
|
||||||
|
final endpoint = widget.endpoint;
|
||||||
|
final icon = Icon(fileIcon(entry), size: 32);
|
||||||
|
if (entry.isDir || !isThumbnailFile(entry.name)) return icon;
|
||||||
|
final urls = resolveFileUrls(endpoint, entry.path);
|
||||||
|
if (urls == null) return icon;
|
||||||
|
final decode = filesThumbnailDecodeSize(
|
||||||
|
MediaQuery.devicePixelRatioOf(context),
|
||||||
|
);
|
||||||
|
if (_url != urls.view.toString() || _decode != decode) {
|
||||||
|
_provider?.evict();
|
||||||
|
_url = urls.view.toString();
|
||||||
|
_decode = decode;
|
||||||
|
_provider = ResizeImage.resizeIfNeeded(
|
||||||
|
decode,
|
||||||
|
decode,
|
||||||
|
NetworkImage(_url!),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
final scheme = Theme.of(context).colorScheme;
|
||||||
|
final placeholder = Container(
|
||||||
|
width: filesThumbnailSize,
|
||||||
|
height: filesThumbnailSize,
|
||||||
|
alignment: Alignment.center,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: scheme.surfaceContainerHighest,
|
||||||
|
borderRadius: BorderRadius.circular(6),
|
||||||
|
),
|
||||||
|
child: icon,
|
||||||
|
);
|
||||||
|
return ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(6),
|
||||||
|
child: Image(
|
||||||
|
image: _provider!,
|
||||||
|
width: filesThumbnailSize,
|
||||||
|
height: filesThumbnailSize,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
|
||||||
|
semanticLabel: entry.name,
|
||||||
|
loadingBuilder: (_, child, progress) =>
|
||||||
|
progress == null ? child : placeholder,
|
||||||
|
errorBuilder: (_, _, _) => icon,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
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 {
|
||||||
|
final endpoint = ServerUrl.validate(configuredEndpoint);
|
||||||
|
final base = Uri.parse(
|
||||||
|
endpoint.httpUrl,
|
||||||
|
).replace(path: '/files', query: null, fragment: null);
|
||||||
|
Uri make({required bool download}) => base.replace(
|
||||||
|
queryParameters: <String, String>{
|
||||||
|
'path': value,
|
||||||
|
if (download) 'download': '1',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return FileUrls(
|
||||||
|
view: make(download: false),
|
||||||
|
download: make(download: true),
|
||||||
|
);
|
||||||
|
} on FormatException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../../../ui/adaptive/host.dart';
|
||||||
|
import '../../artifacts/actions/artifact_file_bridge.dart';
|
||||||
|
import '../../artifacts/actions/artifact_transfer.dart';
|
||||||
|
import '../../artifacts/domain/artifact_groups.dart';
|
||||||
|
import '../../artifacts/domain/artifact_kind.dart';
|
||||||
|
import '../../artifacts/domain/artifact_record.dart';
|
||||||
|
import '../../artifacts/domain/gallery_navigation.dart';
|
||||||
|
import '../../artifacts/ui/artifact_external_open.dart';
|
||||||
|
import '../../artifacts/ui/artifact_viewer_fetch.dart';
|
||||||
|
import '../../artifacts/ui/artifact_viewer_page.dart';
|
||||||
|
import '../data/directory_listing.dart';
|
||||||
|
import 'files_download.dart';
|
||||||
|
import 'files_details.dart';
|
||||||
|
import 'files_preview.dart';
|
||||||
|
import 'files_urls.dart';
|
||||||
|
|
||||||
|
/// Opens and downloads one working-directory file from the Files panel.
|
||||||
|
///
|
||||||
|
/// Previewable files (images, video, audio, markdown, text, tables, HTML) open
|
||||||
|
/// in the shared artifact viewer over the inline `/files` url; a PDF goes to
|
||||||
|
/// the host's external handler; anything else gets a sheet with Download and
|
||||||
|
/// Open externally. The host capabilities are injectable so tests never fetch.
|
||||||
|
class FilesViewer {
|
||||||
|
const FilesViewer({
|
||||||
|
this.bridge = const ArtifactFileBridge(),
|
||||||
|
this.fetch = fetchArtifact,
|
||||||
|
this.openExternal = openArtifactExternally,
|
||||||
|
this.launch = launchFileUrl,
|
||||||
|
});
|
||||||
|
|
||||||
|
final ArtifactFileBridge bridge;
|
||||||
|
final ArtifactFetch fetch;
|
||||||
|
final ArtifactExternalOpen openExternal;
|
||||||
|
final FileUrlLauncher launch;
|
||||||
|
|
||||||
|
Future<void> open(
|
||||||
|
BuildContext context, {
|
||||||
|
required String endpoint,
|
||||||
|
required DirectoryEntry entry,
|
||||||
|
}) async {
|
||||||
|
final urls = resolveFileUrls(endpoint, entry.path);
|
||||||
|
if (urls == null) {
|
||||||
|
_showSheet(context, entry, null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final type = fileContentType(entry.name);
|
||||||
|
if (artifactKind(type, entry.name) == ArtifactKind.pdf) {
|
||||||
|
var opened = false;
|
||||||
|
try {
|
||||||
|
opened = await openExternal(urls.view);
|
||||||
|
} catch (_) {
|
||||||
|
/* show fallback actions below */
|
||||||
|
}
|
||||||
|
if (!opened && context.mounted) _showSheet(context, entry, urls);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!isPreviewableFile(entry.name)) {
|
||||||
|
_showSheet(context, entry, urls);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final artifact = ArtifactRecord(
|
||||||
|
name: entry.name,
|
||||||
|
url: urls.view.toString(),
|
||||||
|
contentType: type,
|
||||||
|
sizeBytes: entry.size ?? 0,
|
||||||
|
raw: const {},
|
||||||
|
);
|
||||||
|
final group = ArtifactGroup(
|
||||||
|
stageKey: 'Files',
|
||||||
|
visit: 1,
|
||||||
|
artifacts: [artifact],
|
||||||
|
);
|
||||||
|
final page = ArtifactViewerPage(
|
||||||
|
groups: [group],
|
||||||
|
selectedIdentity: artifactVisitIdentityOf(group, artifact),
|
||||||
|
configuredEndpoint: endpoint,
|
||||||
|
downloadUrl: urls.download.toString(),
|
||||||
|
previewFormat: filePreviewFormat,
|
||||||
|
fetch: fetch,
|
||||||
|
openExternal: openExternal,
|
||||||
|
fileBridge: bridge,
|
||||||
|
);
|
||||||
|
if (!context.mounted) return;
|
||||||
|
Navigator.of(context).push<void>(
|
||||||
|
usesCupertinoHost(context)
|
||||||
|
? CupertinoPageRoute<void>(builder: (_) => page)
|
||||||
|
: MaterialPageRoute<void>(builder: (_) => page),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Downloads [entry] straight from a row or tile menu and reports the
|
||||||
|
/// outcome (a snack bar, or an alert for a failure on a host without one);
|
||||||
|
/// without urls the sheet explains instead.
|
||||||
|
Future<void> download(
|
||||||
|
BuildContext context, {
|
||||||
|
required String endpoint,
|
||||||
|
required DirectoryEntry entry,
|
||||||
|
}) async {
|
||||||
|
final urls = resolveFileUrls(endpoint, entry.path);
|
||||||
|
if (urls == null) {
|
||||||
|
_showSheet(context, entry, null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final messenger = ScaffoldMessenger.maybeOf(context);
|
||||||
|
final result = await _download(entry, urls);
|
||||||
|
if (result.message.isEmpty) return;
|
||||||
|
if (messenger != null) {
|
||||||
|
messenger.showSnackBar(SnackBar(content: Text(result.message)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// A Cupertino host has no snack bar; a failure still has to be said.
|
||||||
|
if (result.state != ArtifactTransferState.failed || !context.mounted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await showAdaptiveDialog<void>(
|
||||||
|
context: context,
|
||||||
|
builder: (dialog) => AlertDialog.adaptive(
|
||||||
|
title: Text(entry.name),
|
||||||
|
content: Text(result.message),
|
||||||
|
actions: [
|
||||||
|
if (usesCupertinoHost(dialog))
|
||||||
|
CupertinoDialogAction(
|
||||||
|
onPressed: () => Navigator.pop(dialog),
|
||||||
|
child: const Text('OK'),
|
||||||
|
)
|
||||||
|
else
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(dialog),
|
||||||
|
child: const Text('OK'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<ArtifactTransferResult> _download(
|
||||||
|
DirectoryEntry entry,
|
||||||
|
FileUrls urls,
|
||||||
|
) => downloadFile(
|
||||||
|
entry: entry,
|
||||||
|
urls: urls,
|
||||||
|
bridge: bridge,
|
||||||
|
fetch: fetch,
|
||||||
|
launch: launch,
|
||||||
|
);
|
||||||
|
|
||||||
|
void _showSheet(BuildContext context, DirectoryEntry entry, FileUrls? urls) =>
|
||||||
|
showFileDetails(
|
||||||
|
context,
|
||||||
|
entry: entry,
|
||||||
|
urls: urls,
|
||||||
|
download: urls == null ? null : () => _download(entry, urls),
|
||||||
|
openExternal: openExternal,
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -113,6 +113,10 @@ void main() {
|
|||||||
artifactPreviewFormat('text/html', 'report.html'),
|
artifactPreviewFormat('text/html', 'report.html'),
|
||||||
ArtifactPreviewFormat.html,
|
ArtifactPreviewFormat.html,
|
||||||
);
|
);
|
||||||
|
expect(
|
||||||
|
artifactPreviewFormat('audio/mpeg', 'recording.mp3'),
|
||||||
|
ArtifactPreviewFormat.audio,
|
||||||
|
);
|
||||||
expect(
|
expect(
|
||||||
artifactPreviewFormat('', 'session-repair-3-ab12.html'),
|
artifactPreviewFormat('', 'session-repair-3-ab12.html'),
|
||||||
ArtifactPreviewFormat.none,
|
ArtifactPreviewFormat.none,
|
||||||
|
|||||||
@@ -0,0 +1,280 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:pipelines_app/features/chat/files/files_preview.dart';
|
||||||
|
import 'package:pipelines_app/features/artifacts/domain/artifact_kind.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pipelines_app/core/api_gateway.dart';
|
||||||
|
import 'package:pipelines_app/core/transport/pipelines_client.dart';
|
||||||
|
import 'package:pipelines_app/features/artifacts/actions/artifact_file_bridge.dart';
|
||||||
|
import 'package:pipelines_app/features/artifacts/actions/artifact_transfer.dart';
|
||||||
|
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_fetch.dart';
|
||||||
|
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_page.dart';
|
||||||
|
import 'package:pipelines_app/features/chat/files/files_controller.dart';
|
||||||
|
import 'package:pipelines_app/features/chat/files/files_models.dart';
|
||||||
|
import 'package:pipelines_app/features/chat/files/files_panel.dart';
|
||||||
|
import 'package:pipelines_app/features/chat/files/files_thumbnail.dart';
|
||||||
|
import 'package:pipelines_app/features/chat/files/files_urls.dart';
|
||||||
|
import 'package:pipelines_app/features/chat/files/files_viewer.dart';
|
||||||
|
|
||||||
|
class Gateway extends PipelinesClient {
|
||||||
|
@override
|
||||||
|
Uri get endpoint => Uri.parse('ws://example.test/connect');
|
||||||
|
bool fail = false;
|
||||||
|
@override
|
||||||
|
Stream<JsonMap> get frames => const Stream.empty();
|
||||||
|
@override
|
||||||
|
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
||||||
|
if (fail) throw StateError('internal transport secret');
|
||||||
|
return {
|
||||||
|
'directory_listing': {
|
||||||
|
'path': '/home/demo',
|
||||||
|
'home': '/home',
|
||||||
|
'entries': [
|
||||||
|
for (final name in [
|
||||||
|
'notes.txt',
|
||||||
|
'picture.png',
|
||||||
|
'archive.zip',
|
||||||
|
'report.pdf',
|
||||||
|
])
|
||||||
|
{'name': name, 'path': '/home/demo/$name', 'size': 1234},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
late FileUrlResolver original;
|
||||||
|
setUp(() {
|
||||||
|
original = resolveFileUrls;
|
||||||
|
resolveFileUrls = (_, path) => fileUrls('ws://example.test/connect', path);
|
||||||
|
});
|
||||||
|
tearDown(() => resolveFileUrls = original);
|
||||||
|
Future<FilesController> pump(
|
||||||
|
WidgetTester tester, {
|
||||||
|
Gateway? gateway,
|
||||||
|
FilesViewer? viewer,
|
||||||
|
}) async {
|
||||||
|
final controller = FilesController(
|
||||||
|
gateway: gateway ?? Gateway(),
|
||||||
|
initialPath: '/home/demo',
|
||||||
|
);
|
||||||
|
addTearDown(controller.dispose);
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: Scaffold(
|
||||||
|
body: FilesPanel(
|
||||||
|
controller: controller,
|
||||||
|
viewer: viewer ?? const FilesViewer(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
return controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
testWidgets('text tap opens shared viewer and fetches inline URL', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
Uri? fetched;
|
||||||
|
await pump(
|
||||||
|
tester,
|
||||||
|
viewer: FilesViewer(
|
||||||
|
fetch: (url) async {
|
||||||
|
fetched = url;
|
||||||
|
return ArtifactFetchResult(
|
||||||
|
status: 200,
|
||||||
|
bytes: utf8.encode('A text file preview'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.tap(find.text('notes.txt'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.byType(ArtifactViewerPage), findsOneWidget);
|
||||||
|
expect(find.text('A text file preview'), findsOneWidget);
|
||||||
|
expect(fetched?.queryParameters['path'], '/home/demo/notes.txt');
|
||||||
|
expect(fetched?.queryParameters.containsKey('download'), isFalse);
|
||||||
|
});
|
||||||
|
testWidgets('image tap opens shared image viewer', (tester) async {
|
||||||
|
await pump(
|
||||||
|
tester,
|
||||||
|
viewer: FilesViewer(
|
||||||
|
fetch: (_) async => ArtifactFetchResult(
|
||||||
|
status: 200,
|
||||||
|
bytes: base64Decode(
|
||||||
|
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.tap(find.text('picture.png'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.byType(ArtifactViewerPage), findsOneWidget);
|
||||||
|
expect(find.byType(Image), findsWidgets);
|
||||||
|
});
|
||||||
|
testWidgets('unknown file has metadata and a working download', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
String? saved;
|
||||||
|
await pump(
|
||||||
|
tester,
|
||||||
|
viewer: FilesViewer(
|
||||||
|
fetch: (_) async =>
|
||||||
|
ArtifactFetchResult(status: 200, bytes: utf8.encode('bytes')),
|
||||||
|
bridge: ArtifactFileBridge(
|
||||||
|
download: (file) async {
|
||||||
|
saved = file.name;
|
||||||
|
return const ArtifactTransferResult(
|
||||||
|
ArtifactTransferState.saved,
|
||||||
|
'Saved file.',
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.tap(find.text('archive.zip'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(
|
||||||
|
find.text('This file type cannot be previewed here.'),
|
||||||
|
findsOneWidget,
|
||||||
|
);
|
||||||
|
await tester.tap(find.text('Download'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(saved, 'archive.zip');
|
||||||
|
expect(find.text('Saved file.'), findsOneWidget);
|
||||||
|
});
|
||||||
|
for (final grid in [false, true]) {
|
||||||
|
testWidgets(
|
||||||
|
'${grid ? 'grid' : 'list'} PDF menu downloads without opening',
|
||||||
|
(tester) async {
|
||||||
|
String? saved;
|
||||||
|
var opened = false;
|
||||||
|
final controller = await pump(
|
||||||
|
tester,
|
||||||
|
viewer: FilesViewer(
|
||||||
|
fetch: (_) async => ArtifactFetchResult(
|
||||||
|
status: 200,
|
||||||
|
bytes: utf8.encode('pdf bytes'),
|
||||||
|
),
|
||||||
|
openExternal: (_) async {
|
||||||
|
opened = true;
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
bridge: ArtifactFileBridge(
|
||||||
|
download: (file) async {
|
||||||
|
saved = file.name;
|
||||||
|
return const ArtifactTransferResult(
|
||||||
|
ArtifactTransferState.saved,
|
||||||
|
'Saved',
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if (grid) {
|
||||||
|
controller.setView(FilesViewMode.grid);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
}
|
||||||
|
await tester.tap(find.byTooltip('File actions').last);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.text('Open'), findsOneWidget);
|
||||||
|
await tester.tap(find.text('Download'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(saved, 'report.pdf');
|
||||||
|
expect(opened, isFalse);
|
||||||
|
expect(tester.takeException(), isNull);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
testWidgets('thumbnail error falls back to icon and decode stays bounded', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
final controller = await pump(tester);
|
||||||
|
controller.setView(FilesViewMode.grid);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.byType(FileThumbnail), findsNWidgets(4));
|
||||||
|
expect(find.byIcon(Icons.image_outlined), findsOneWidget);
|
||||||
|
expect(filesThumbnailDecodeSize(10), 224);
|
||||||
|
expect(tester.takeException(), isNull);
|
||||||
|
});
|
||||||
|
testWidgets('Cupertino unknown file and menu use native controls', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
final controller = FilesController(
|
||||||
|
gateway: Gateway(),
|
||||||
|
initialPath: '/home/demo',
|
||||||
|
);
|
||||||
|
addTearDown(controller.dispose);
|
||||||
|
await tester.pumpWidget(
|
||||||
|
CupertinoApp(
|
||||||
|
home: CupertinoPageScaffold(child: FilesPanel(controller: controller)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
await tester.tap(find.text('archive.zip'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.text('Download'), findsOneWidget);
|
||||||
|
expect(find.byType(CupertinoButton), findsWidgets);
|
||||||
|
expect(tester.takeException(), isNull);
|
||||||
|
});
|
||||||
|
testWidgets('PDF external-open failures keep download available', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
await pump(
|
||||||
|
tester,
|
||||||
|
viewer: FilesViewer(
|
||||||
|
openExternal: (_) async => throw StateError('no handler'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.tap(find.text('report.pdf'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.text('Download'), findsOneWidget);
|
||||||
|
expect(tester.takeException(), isNull);
|
||||||
|
});
|
||||||
|
testWidgets('download thrown host errors become feedback', (tester) async {
|
||||||
|
await pump(
|
||||||
|
tester,
|
||||||
|
viewer: FilesViewer(
|
||||||
|
fetch: (_) async =>
|
||||||
|
ArtifactFetchResult(status: 200, bytes: utf8.encode('bytes')),
|
||||||
|
bridge: ArtifactFileBridge(
|
||||||
|
download: (_) async => throw StateError('host failure'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.tap(find.byTooltip('File actions').last);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
await tester.tap(find.text('Download'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(
|
||||||
|
find.text('Could not download the file. Try again.'),
|
||||||
|
findsOneWidget,
|
||||||
|
);
|
||||||
|
expect(tester.takeException(), isNull);
|
||||||
|
});
|
||||||
|
test('file-specific HTML previews preserve artifact export exclusions', () {
|
||||||
|
expect(
|
||||||
|
filePreviewFormat('text/html', 'session.html'),
|
||||||
|
ArtifactPreviewFormat.html,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
artifactPreviewFormat('text/html', 'session.html'),
|
||||||
|
ArtifactPreviewFormat.none,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
filePreviewFormat('image/svg+xml', 'icon.svg'),
|
||||||
|
ArtifactPreviewFormat.html,
|
||||||
|
);
|
||||||
|
expect(fileContentType('code.dart'), 'text/plain');
|
||||||
|
expect(fileSizeLabel(1024), '1.0 KiB');
|
||||||
|
expect(fileSizeLabel(1024 * 1024), '1.0 MiB');
|
||||||
|
});
|
||||||
|
testWidgets('folder errors hide technical detail', (tester) async {
|
||||||
|
await pump(tester, gateway: Gateway()..fail = true);
|
||||||
|
expect(find.text("Couldn't load this folder."), findsOneWidget);
|
||||||
|
expect(find.textContaining('internal transport'), findsNothing);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pipelines_app/features/chat/files/files_urls.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
test('resolves view and attachment urls with encoded paths', () {
|
||||||
|
final urls = fileUrls(
|
||||||
|
'ws://example.test:8081/connect?old=1',
|
||||||
|
'~/My folder/naïve file.txt',
|
||||||
|
);
|
||||||
|
expect(urls, isNotNull);
|
||||||
|
expect(urls!.view.path, '/files');
|
||||||
|
expect(urls.view.queryParameters['path'], '~/My folder/naïve file.txt');
|
||||||
|
expect(urls.view.toString(), contains('My+folder'));
|
||||||
|
expect(urls.view.toString(), contains('na%C3%AFve+file.txt'));
|
||||||
|
expect(urls.download.queryParameters['download'], '1');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('preserves whitespace in actual filenames', () {
|
||||||
|
final urls = fileUrls('ws://example.test/connect', '/home/file.txt ');
|
||||||
|
expect(urls!.view.queryParameters['path'], '/home/file.txt ');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('rejects a missing or invalid endpoint', () {
|
||||||
|
expect(fileUrls('', '/tmp/a.txt'), isNull);
|
||||||
|
expect(fileUrls('http://example.test/connect', '/tmp/a.txt'), isNull);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -140,3 +140,20 @@ node tool/capture/capture.mjs --build build/probe-app --out /tmp/review/chat-whe
|
|||||||
For a prompt delivered to the running reply, use `--params chats=2&steered=1`,
|
For a prompt delivered to the running reply, use `--params chats=2&steered=1`,
|
||||||
open `/chat/perf-chat-0`, then type and send a prompt. Without `steered=1`
|
open `/chat/perf-chat-0`, then type and send a prompt. Without `steered=1`
|
||||||
the fixture retains the older-server Sent acknowledgement.
|
the fixture retains the older-server Sent acknowledgement.
|
||||||
|
|
||||||
|
## Chat file explorer
|
||||||
|
|
||||||
|
Use `--params 'chats=2&files=1' open=/chat/perf-chat-0 click=Files` to open a
|
||||||
|
populated explorer (the fixture always answers `list_directory`). `files=1`
|
||||||
|
redirects view/download URLs to same-origin static fixture files; production
|
||||||
|
continues to use `/files`. After building the probe, copy the fixtures:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
mkdir -p build/probe-app/capture-files
|
||||||
|
cp tool/capture/fixtures/files/* build/probe-app/capture-files/
|
||||||
|
```
|
||||||
|
|
||||||
|
The tree has an assets subfolder, a hidden folder, PNG/JPEG miniatures, text,
|
||||||
|
JSON, CSV, PDF, archive, log and video entries. Image/text/table/archive files
|
||||||
|
have bundled bytes; PDF and video entries demonstrate type labels and menus
|
||||||
|
only. Use the real server for their external handlers and playback acceptance.
|
||||||
|
|||||||
Binary file not shown.
@@ -0,0 +1 @@
|
|||||||
|
{"release":"1.0","ready":true}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 5.4 KiB |
@@ -0,0 +1,3 @@
|
|||||||
|
section,files
|
||||||
|
Images,2
|
||||||
|
Documents,4
|
||||||
|
@@ -0,0 +1,6 @@
|
|||||||
|
# Release notes
|
||||||
|
|
||||||
|
The explorer now previews files and saves downloads.
|
||||||
|
|
||||||
|
- Open a file to inspect it.
|
||||||
|
- Use the file menu to download it.
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import 'package:pipelines_app/core/api_gateway.dart';
|
||||||
|
import 'package:pipelines_app/features/chat/files/files_urls.dart';
|
||||||
|
|
||||||
|
/// A static, two-level explorer fixture. Its files live in capture/fixtures/files.
|
||||||
|
JsonMap probeFilesReply(JsonMap request) {
|
||||||
|
final fields = request['list_directory'] as Map?;
|
||||||
|
final path = '${fields?['path'] ?? '/srv/probe/release'}';
|
||||||
|
final nested = path.endsWith('/assets');
|
||||||
|
final entries = nested
|
||||||
|
? <(String, int)>[('design.png', 18432), ('icon.jpg', 23000)]
|
||||||
|
: <(String, int)>[
|
||||||
|
('design.png', 18432),
|
||||||
|
('icon.jpg', 23000),
|
||||||
|
('release.md', 640),
|
||||||
|
('config.json', 220),
|
||||||
|
('metrics.csv', 88),
|
||||||
|
('report.pdf', 45000),
|
||||||
|
('archive.zip', 85000),
|
||||||
|
('server.log', 12582912),
|
||||||
|
('demo.mp4', 8000000),
|
||||||
|
];
|
||||||
|
return {
|
||||||
|
'id': request['id'],
|
||||||
|
'type': 'directory_listing',
|
||||||
|
'directory_listing': {
|
||||||
|
'path': path,
|
||||||
|
'home': '/workspace',
|
||||||
|
'parent': nested
|
||||||
|
? path.substring(0, path.lastIndexOf('/'))
|
||||||
|
: '/workspace',
|
||||||
|
'entries': [
|
||||||
|
if (!nested) ...[
|
||||||
|
{'name': 'assets', 'path': '$path/assets', 'is_dir': true},
|
||||||
|
{
|
||||||
|
'name': '.config',
|
||||||
|
'path': '$path/.config',
|
||||||
|
'is_dir': true,
|
||||||
|
'hidden': true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
for (final (name, size) in entries)
|
||||||
|
{
|
||||||
|
'name': name,
|
||||||
|
'path': '$path/$name',
|
||||||
|
'is_dir': false,
|
||||||
|
'size': size,
|
||||||
|
'modified': '2026-11-07T00:00:00Z',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void installFilesFixture() {
|
||||||
|
resolveFileUrls = (_, path) {
|
||||||
|
final name = Uri.encodeComponent(path.split('/').last);
|
||||||
|
final view = Uri.base.resolve('/capture-files/$name');
|
||||||
|
return FileUrls(
|
||||||
|
view: view,
|
||||||
|
download: view.replace(queryParameters: {'download': '1'}),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -35,6 +35,7 @@ import 'perf/chat_question_fixture.dart';
|
|||||||
import 'perf/chat_scroll_fixture.dart';
|
import 'perf/chat_scroll_fixture.dart';
|
||||||
import 'perf/perf_fixture.dart';
|
import 'perf/perf_fixture.dart';
|
||||||
import 'probe_folder_fixture.dart';
|
import 'probe_folder_fixture.dart';
|
||||||
|
import 'probe_files_fixture.dart';
|
||||||
import 'probe_usage_fixture.dart';
|
import 'probe_usage_fixture.dart';
|
||||||
|
|
||||||
/// The run every run-scoped hit names. Its recorded sequences are deliberately
|
/// The run every run-scoped hit names. Its recorded sequences are deliberately
|
||||||
@@ -470,6 +471,8 @@ JsonMap? probeReply(JsonMap request) {
|
|||||||
final perf = perfChatReply(request);
|
final perf = perfChatReply(request);
|
||||||
if (perf != null) return perf;
|
if (perf != null) return perf;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
case 'list_directory':
|
||||||
|
return probeFilesReply(request);
|
||||||
case 'subscribe':
|
case 'subscribe':
|
||||||
case 'unsubscribe':
|
case 'unsubscribe':
|
||||||
return null;
|
return null;
|
||||||
@@ -733,6 +736,7 @@ void main() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
configurePerfFixture(params);
|
configurePerfFixture(params);
|
||||||
|
if (params['files'] == '1') installFilesFixture();
|
||||||
// `?font=inter` chooses a font as Settings would; otherwise the stored one.
|
// `?font=inter` chooses a font as Settings would; otherwise the stored one.
|
||||||
final font = params['font'];
|
final font = params['font'];
|
||||||
unawaited(
|
unawaited(
|
||||||
|
|||||||
@@ -13,3 +13,23 @@ Server side:
|
|||||||
absolute or `~`-prefixed and are resolved through the operator home directory; cleaned
|
absolute or `~`-prefixed and are resolved through the operator home directory; cleaned
|
||||||
paths and symlinks must stay inside that home subtree. Directories, special files and
|
paths and symlinks must stay inside that home subtree. Directories, special files and
|
||||||
escape paths are refused. Add `download=1` for attachment disposition.
|
escape paths are refused. Add `download=1` for attachment disposition.
|
||||||
|
|
||||||
|
## Viewing and downloads
|
||||||
|
|
||||||
|
Files now open in the shared artifact viewer (images, SVG icons in an inert
|
||||||
|
HTML frame, text/code, markdown, JSON, tables, HTML, audio and video). PDFs open
|
||||||
|
through the platform handler. Unknown files show metadata and host-native Open
|
||||||
|
externally/Download actions. Every file has separate Open and Download menu
|
||||||
|
items, including PDFs; folders have neither. Downloads reuse the artifact
|
||||||
|
save bridge on native platforms and attachment URLs on web. Viewer downloads
|
||||||
|
also use attachment URLs.
|
||||||
|
|
||||||
|
Image tiles decode at 56 logical pixels (maximum scale 4), show a loading
|
||||||
|
placeholder and error glyph, and evict decoded cache entries when scrolled out.
|
||||||
|
Sorting runs once per panel rebuild. Breadcrumbs navigate to ancestors; filters
|
||||||
|
stay synchronized with folder navigation, and filtered empty states differ from
|
||||||
|
empty folders. Sizes use binary units and mtimes use compact local timestamps.
|
||||||
|
|
||||||
|
The capture fixture uses `files=1`; see app/tool/capture/README.md for bundling
|
||||||
|
its static files. PDF/video fixture entries only show types/menus and do not
|
||||||
|
provide playable sample bytes.
|
||||||
|
|||||||
Reference in New Issue
Block a user