1
0
mirror of https://github.com/immich-app/immich.git synced 2025-07-15 07:14:42 +02:00

refactor: asset media endpoints (#9831)

* refactor: asset media endpoints

* refactor: mobile upload livePhoto as separate request

* refactor: change mobile backup flow to use new asset upload endpoints

* chore: format and analyze dart code

* feat: mark motion as hidden when linked

* feat: upload video portion of live photo before image portion

* fix: incorrect assetApi calls in mobile code

* fix: download asset

---------

Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
Co-authored-by: Zack Pollard <zackpollard@ymail.com>
This commit is contained in:
Jason Rasmussen
2024-05-31 13:44:04 -04:00
committed by GitHub
parent 66fced40e7
commit 69d2fcb43e
91 changed files with 1932 additions and 2456 deletions

View File

@ -1,106 +0,0 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.18
// ignore_for_file: unused_element, unused_import
// ignore_for_file: always_put_required_named_parameters_first
// ignore_for_file: constant_identifier_names
// ignore_for_file: lines_longer_than_80_chars
part of openapi.api;
class AssetFileUploadResponseDto {
/// Returns a new [AssetFileUploadResponseDto] instance.
AssetFileUploadResponseDto({
required this.duplicate,
required this.id,
});
bool duplicate;
String id;
@override
bool operator ==(Object other) => identical(this, other) || other is AssetFileUploadResponseDto &&
other.duplicate == duplicate &&
other.id == id;
@override
int get hashCode =>
// ignore: unnecessary_parenthesis
(duplicate.hashCode) +
(id.hashCode);
@override
String toString() => 'AssetFileUploadResponseDto[duplicate=$duplicate, id=$id]';
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
json[r'duplicate'] = this.duplicate;
json[r'id'] = this.id;
return json;
}
/// Returns a new [AssetFileUploadResponseDto] instance and imports its values from
/// [value] if it's a [Map], null otherwise.
// ignore: prefer_constructors_over_static_methods
static AssetFileUploadResponseDto? fromJson(dynamic value) {
if (value is Map) {
final json = value.cast<String, dynamic>();
return AssetFileUploadResponseDto(
duplicate: mapValueOfType<bool>(json, r'duplicate')!,
id: mapValueOfType<String>(json, r'id')!,
);
}
return null;
}
static List<AssetFileUploadResponseDto> listFromJson(dynamic json, {bool growable = false,}) {
final result = <AssetFileUploadResponseDto>[];
if (json is List && json.isNotEmpty) {
for (final row in json) {
final value = AssetFileUploadResponseDto.fromJson(row);
if (value != null) {
result.add(value);
}
}
}
return result.toList(growable: growable);
}
static Map<String, AssetFileUploadResponseDto> mapFromJson(dynamic json) {
final map = <String, AssetFileUploadResponseDto>{};
if (json is Map && json.isNotEmpty) {
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
for (final entry in json.entries) {
final value = AssetFileUploadResponseDto.fromJson(entry.value);
if (value != null) {
map[entry.key] = value;
}
}
}
return map;
}
// maps a json object with a list of AssetFileUploadResponseDto-objects as value to a dart map
static Map<String, List<AssetFileUploadResponseDto>> mapListFromJson(dynamic json, {bool growable = false,}) {
final map = <String, List<AssetFileUploadResponseDto>>{};
if (json is Map && json.isNotEmpty) {
// ignore: parameter_assignments
json = json.cast<String, dynamic>();
for (final entry in json.entries) {
map[entry.key] = AssetFileUploadResponseDto.listFromJson(entry.value, growable: growable,);
}
}
return map;
}
/// The list of required keys that must be present in a JSON.
static const requiredKeys = <String>{
'duplicate',
'id',
};
}

View File

@ -11,9 +11,9 @@
part of openapi.api;
class ThumbnailFormat {
class AssetMediaSize {
/// Instantiate a new enum with the provided [value].
const ThumbnailFormat._(this.value);
const AssetMediaSize._(this.value);
/// The underlying value of this enum member.
final String value;
@ -23,22 +23,22 @@ class ThumbnailFormat {
String toJson() => value;
static const JPEG = ThumbnailFormat._(r'JPEG');
static const WEBP = ThumbnailFormat._(r'WEBP');
static const preview = AssetMediaSize._(r'preview');
static const thumbnail = AssetMediaSize._(r'thumbnail');
/// List of all possible values in this [enum][ThumbnailFormat].
static const values = <ThumbnailFormat>[
JPEG,
WEBP,
/// List of all possible values in this [enum][AssetMediaSize].
static const values = <AssetMediaSize>[
preview,
thumbnail,
];
static ThumbnailFormat? fromJson(dynamic value) => ThumbnailFormatTypeTransformer().decode(value);
static AssetMediaSize? fromJson(dynamic value) => AssetMediaSizeTypeTransformer().decode(value);
static List<ThumbnailFormat> listFromJson(dynamic json, {bool growable = false,}) {
final result = <ThumbnailFormat>[];
static List<AssetMediaSize> listFromJson(dynamic json, {bool growable = false,}) {
final result = <AssetMediaSize>[];
if (json is List && json.isNotEmpty) {
for (final row in json) {
final value = ThumbnailFormat.fromJson(row);
final value = AssetMediaSize.fromJson(row);
if (value != null) {
result.add(value);
}
@ -48,16 +48,16 @@ class ThumbnailFormat {
}
}
/// Transformation class that can [encode] an instance of [ThumbnailFormat] to String,
/// and [decode] dynamic data back to [ThumbnailFormat].
class ThumbnailFormatTypeTransformer {
factory ThumbnailFormatTypeTransformer() => _instance ??= const ThumbnailFormatTypeTransformer._();
/// Transformation class that can [encode] an instance of [AssetMediaSize] to String,
/// and [decode] dynamic data back to [AssetMediaSize].
class AssetMediaSizeTypeTransformer {
factory AssetMediaSizeTypeTransformer() => _instance ??= const AssetMediaSizeTypeTransformer._();
const ThumbnailFormatTypeTransformer._();
const AssetMediaSizeTypeTransformer._();
String encode(ThumbnailFormat data) => data.value;
String encode(AssetMediaSize data) => data.value;
/// Decodes a [dynamic value][data] to a ThumbnailFormat.
/// Decodes a [dynamic value][data] to a AssetMediaSize.
///
/// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully,
/// then null is returned. However, if [allowNull] is false and the [dynamic value][data]
@ -65,11 +65,11 @@ class ThumbnailFormatTypeTransformer {
///
/// The [allowNull] is very handy when an API changes and a new enum value is added or removed,
/// and users are still using an old app with the old code.
ThumbnailFormat? decode(dynamic data, {bool allowNull = true}) {
AssetMediaSize? decode(dynamic data, {bool allowNull = true}) {
if (data != null) {
switch (data) {
case r'JPEG': return ThumbnailFormat.JPEG;
case r'WEBP': return ThumbnailFormat.WEBP;
case r'preview': return AssetMediaSize.preview;
case r'thumbnail': return AssetMediaSize.thumbnail;
default:
if (!allowNull) {
throw ArgumentError('Unknown enum value to decode: $data');
@ -79,7 +79,7 @@ class ThumbnailFormatTypeTransformer {
return null;
}
/// Singleton [ThumbnailFormatTypeTransformer] instance.
static ThumbnailFormatTypeTransformer? _instance;
/// Singleton [AssetMediaSizeTypeTransformer] instance.
static AssetMediaSizeTypeTransformer? _instance;
}

View File

@ -23,11 +23,13 @@ class AssetMediaStatus {
String toJson() => value;
static const created = AssetMediaStatus._(r'created');
static const replaced = AssetMediaStatus._(r'replaced');
static const duplicate = AssetMediaStatus._(r'duplicate');
/// List of all possible values in this [enum][AssetMediaStatus].
static const values = <AssetMediaStatus>[
created,
replaced,
duplicate,
];
@ -68,6 +70,7 @@ class AssetMediaStatusTypeTransformer {
AssetMediaStatus? decode(dynamic data, {bool allowNull = true}) {
if (data != null) {
switch (data) {
case r'created': return AssetMediaStatus.created;
case r'replaced': return AssetMediaStatus.replaced;
case r'duplicate': return AssetMediaStatus.duplicate;
default: