Files
pipelines/app/lib/features/artifacts/actions/artifact_transfer.dart
T

63 lines
1.9 KiB
Dart

import 'artifact_file.dart';
import 'artifact_transfer_stub.dart'
if (dart.library.js_interop) 'artifact_transfer_web.dart'
if (dart.library.io) 'artifact_transfer_io.dart'
as impl;
/// The outcome of a host file transfer.
enum ArtifactTransferState {
/// The host accepted a browser download.
saved,
/// The host share sheet accepted the file.
shared,
/// The bytes are ready but the browser needed a fresh user activation.
ready,
/// The operator or the host canceled the transfer.
canceled,
/// The host cannot save/share this file.
unsupported,
/// The host refused the share for a policy or activation reason.
blocked,
/// The transfer failed for any other reason.
failed,
}
/// A transfer result plus the exact words the action row reports.
class ArtifactTransferResult {
const ArtifactTransferResult(this.state, this.message);
final ArtifactTransferState state;
final String message;
}
typedef ArtifactSaveFile =
Future<ArtifactTransferResult> Function(ArtifactFile file);
typedef ArtifactShareFile =
Future<ArtifactTransferResult> Function(ArtifactFile file);
/// Whether the host can save an artifact's bytes as a named file.
bool get artifactDownloadSupported => impl.artifactDownloadSupported;
/// Whether the host can share a file (not merely a link).
bool get artifactShareSupported => impl.artifactShareSupported;
String get artifactDownloadUnsupportedMessage =>
impl.artifactDownloadUnsupportedMessage;
String get artifactShareUnsupportedMessage =>
impl.artifactShareUnsupportedMessage;
/// Saves [file] through the host's download capability.
Future<ArtifactTransferResult> saveArtifactFile(ArtifactFile file) =>
impl.saveArtifactFile(file);
/// Shares [file] through the host's file-sharing capability.
Future<ArtifactTransferResult> shareArtifactFile(ArtifactFile file) =>
impl.shareArtifactFile(file);