Gitea CI / Check code and tests (pull_request) Failing after 8s
Gitea CI / Build Android APK (pull_request) Skipped
Gitea CI / Build Windows x64 app (pull_request) Skipped
Gitea CI / Audit and package Windows x64 (pull_request) Skipped
Gitea CI / Assemble and validate CI artifacts (pull_request) Skipped
Gitea CI / Gitea CI passed (pull_request) Failing after 1s
60 lines
1.7 KiB
Dart
60 lines
1.7 KiB
Dart
import 'package:cutdex_core/project.dart';
|
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
import 'package:path/path.dart' as p;
|
|
|
|
import '../errors/app_failure.dart';
|
|
|
|
part 'media_import.freezed.dart';
|
|
|
|
/// A selected local file or document supplied by a platform provider.
|
|
@freezed
|
|
sealed class ExternalMediaFile with _$ExternalMediaFile {
|
|
const ExternalMediaFile._();
|
|
const factory ExternalMediaFile({required String path}) = LocalMediaFile;
|
|
const factory ExternalMediaFile.content({
|
|
required Uri uri,
|
|
required String name,
|
|
int? byteLength,
|
|
}) = ContentMediaFile;
|
|
|
|
String? get localPath => switch (this) {
|
|
LocalMediaFile(:final path) => path,
|
|
ContentMediaFile() => null,
|
|
};
|
|
|
|
Uri get sourceUri => switch (this) {
|
|
LocalMediaFile(:final path) => p.toUri(path),
|
|
ContentMediaFile(:final uri) => uri,
|
|
};
|
|
|
|
String get displayName => switch (this) {
|
|
LocalMediaFile(:final path) => p.basename(path),
|
|
ContentMediaFile(:final name) => name,
|
|
};
|
|
}
|
|
|
|
const mediaSourceUriKey = 'cutdex.sourceUri';
|
|
|
|
String? mediaSourceLocation(AssetDocument asset) => switch (asset.storage) {
|
|
AssetStorage.external => asset.location,
|
|
AssetStorage.managed => asset.metadata[mediaSourceUriKey] as String?,
|
|
};
|
|
|
|
@freezed
|
|
abstract class MediaImportFailure with _$MediaImportFailure {
|
|
const factory MediaImportFailure({
|
|
required String name,
|
|
required AppFailure failure,
|
|
}) = _MediaImportFailure;
|
|
}
|
|
|
|
@freezed
|
|
abstract class MediaImportResult with _$MediaImportResult {
|
|
const factory MediaImportResult({
|
|
required List<AssetDocument> assets,
|
|
required int added,
|
|
required int duplicates,
|
|
required List<MediaImportFailure> failures,
|
|
}) = _MediaImportResult;
|
|
}
|