Open the run's artifact from notifications

Phone and browser notifications that carry an artifact open it full
screen in the artifact viewer, with an Open run action and the preview as
expanded text; pipelines://artifact deep links route to the viewer.
This commit is contained in:
2026-11-12 18:56:26 +00:00
parent d42d7a3534
commit 767643d991
17 changed files with 487 additions and 35 deletions
+47 -1
View File
@@ -5,6 +5,16 @@ part of 'app_route.dart';
const _maxSafe = 9007199254740991;
final _digits = RegExp(r'^[0-9]+$');
String _rawNativePath(Uri uri) {
final text = uri.toString();
final marker = '${uri.scheme}://${uri.host}';
final start = text.indexOf(marker);
if (start == -1) return uri.path;
final suffix = text.substring(start + marker.length);
final end = suffix.indexOf(RegExp(r'[?#]'));
return end == -1 ? suffix : suffix.substring(0, end);
}
String _routePath(AppRoute route) => switch (route.kind) {
AppRouteKind.pipelines => _pipelinePath(route),
AppRouteKind.runs => _runsPath(route),
@@ -13,8 +23,15 @@ String _routePath(AppRoute route) => switch (route.kind) {
AppRouteKind.settings => '/settings',
AppRouteKind.templates => _templatesPath(route),
AppRouteKind.schedules => '/schedules',
AppRouteKind.artifact => _artifactPath(route),
};
String _artifactPath(AppRoute route) =>
'/artifact/${route.runId}/${route.artifactSequence}/${route.artifactPathEncoded ?? _encodeArtifactPath(route.artifactPath ?? '')}';
String _encodeArtifactPath(String path) =>
path.split('/').map(Uri.encodeComponent).join('/');
String _pipelinePath(AppRoute route) {
final id = _validId(route.pipelineId);
if (id == null) return '/pipelines';
@@ -69,7 +86,9 @@ AppRoute _parseRoute(String location) {
if (raw.contains('://')) {
final uri = Uri.tryParse(raw);
if (uri == null) return AppRoute.pipelines;
raw = uri.path;
raw = uri.scheme == 'pipelines' && uri.host == 'artifact'
? '/artifact${_rawNativePath(uri)}'
: uri.path;
query = uri.query;
}
final hash = raw.indexOf('#');
@@ -93,10 +112,37 @@ AppRoute _parseRoute(String location) {
'settings' => _settingsRoute(segments),
'templates' => _templatesRoute(segments),
'schedules' when segments.length == 1 => AppRoute.schedules,
'artifact' => _artifactRoute(raw),
_ => AppRoute.pipelines,
};
}
AppRoute _artifactRoute(String raw) {
final rawSegments = raw.split('/');
final first = rawSegments.isNotEmpty && rawSegments.first.isEmpty ? 1 : 0;
if (rawSegments.length - first < 4) return AppRoute.pipelines;
final encodedPath = rawSegments.sublist(first + 3).join('/');
try {
final run = _positiveId(Uri.decodeComponent(rawSegments[first + 1]));
final sequence = _number(Uri.decodeComponent(rawSegments[first + 2]));
final path = rawSegments
.sublist(first + 3)
.map(Uri.decodeComponent)
.join('/');
return run == null || sequence == null || path.isEmpty
? AppRoute.pipelines
: AppRoute(
AppRouteKind.artifact,
runId: run,
artifactSequence: sequence,
artifactPath: path,
artifactPathEncoded: encodedPath,
);
} on ArgumentError {
return AppRoute.pipelines;
}
}
List<String>? _decodeSegments(String path) {
final parts = path.split('/');
final first = parts.isNotEmpty && parts.first.isEmpty ? 1 : 0;