add full sync

This commit is contained in:
shenlong-tanwen
2024-09-02 02:16:47 +05:30
parent 877c3b028b
commit e81b61c98b
30 changed files with 333 additions and 179 deletions
@@ -7,32 +7,27 @@ enum AssetType {
}
class Asset {
final int id;
final String name;
final String checksum;
final int height;
final int width;
final int? height;
final int? width;
final AssetType type;
final DateTime createdTime;
final DateTime modifiedTime;
final int duration;
final bool isLivePhoto;
const Asset({
required this.id,
required this.name,
required this.checksum,
required this.height,
required this.width,
this.height,
this.width,
required this.type,
required this.createdTime,
required this.modifiedTime,
required this.duration,
required this.isLivePhoto,
});
Asset copyWith({
int? id,
String? name,
String? checksum,
int? height,
@@ -41,10 +36,8 @@ class Asset {
DateTime? createdTime,
DateTime? modifiedTime,
int? duration,
bool? isLivePhoto,
}) {
return Asset(
id: id ?? this.id,
name: name ?? this.name,
checksum: checksum ?? this.checksum,
height: height ?? this.height,
@@ -53,52 +46,45 @@ class Asset {
createdTime: createdTime ?? this.createdTime,
modifiedTime: modifiedTime ?? this.modifiedTime,
duration: duration ?? this.duration,
isLivePhoto: isLivePhoto ?? this.isLivePhoto,
);
}
@override
String toString() => """
{
"id": $id,
"name": "$name",
"checksum": "$checksum",
"height": $height,
"width": $width,
"height": ${height ?? "-"},
"width": ${width ?? "-"},
"type": "$type",
"createdTime": "$createdTime",
"modifiedTime": "$modifiedTime",
"duration": "$duration",
"isLivePhoto": "$isLivePhoto",
}""";
@override
bool operator ==(covariant Asset other) {
if (identical(this, other)) return true;
return other.id == id &&
other.name == name &&
return other.name == name &&
other.checksum == checksum &&
other.height == height &&
other.width == width &&
other.type == type &&
other.createdTime == createdTime &&
other.modifiedTime == modifiedTime &&
other.duration == duration &&
other.isLivePhoto == isLivePhoto;
other.duration == duration;
}
@override
int get hashCode {
return id.hashCode ^
name.hashCode ^
return name.hashCode ^
checksum.hashCode ^
height.hashCode ^
width.hashCode ^
type.hashCode ^
createdTime.hashCode ^
modifiedTime.hashCode ^
duration.hashCode ^
isLivePhoto.hashCode;
duration.hashCode;
}
}
@@ -1,5 +1,5 @@
import 'package:flutter/foundation.dart';
import 'package:immich_mobile/domain/models/asset.model.dart';
import 'package:immich_mobile/domain/models/asset/asset.model.dart';
@immutable
class LocalAsset extends Asset {
@@ -7,7 +7,6 @@ class LocalAsset extends Asset {
const LocalAsset({
required this.localId,
required super.id,
required super.name,
required super.checksum,
required super.height,
@@ -16,23 +15,20 @@ class LocalAsset extends Asset {
required super.createdTime,
required super.modifiedTime,
required super.duration,
required super.isLivePhoto,
});
@override
String toString() => """
{
"id": $id,
"localId": "$localId",
"name": "$name",
"checksum": "$checksum",
"height": $height,
"width": $width,
"height": ${height ?? "-"},
"width": ${width ?? "-"},
"type": "$type",
"createdTime": "$createdTime",
"modifiedTime": "$modifiedTime",
"duration": "$duration",
"isLivePhoto": "$isLivePhoto",
}""";
@override
@@ -47,7 +43,6 @@ class LocalAsset extends Asset {
@override
LocalAsset copyWith({
int? id,
String? localId,
String? name,
String? checksum,
@@ -57,10 +52,8 @@ class LocalAsset extends Asset {
DateTime? createdTime,
DateTime? modifiedTime,
int? duration,
bool? isLivePhoto,
}) {
return LocalAsset(
id: id ?? this.id,
localId: localId ?? this.localId,
name: name ?? this.name,
checksum: checksum ?? this.checksum,
@@ -70,7 +63,6 @@ class LocalAsset extends Asset {
createdTime: createdTime ?? this.createdTime,
modifiedTime: modifiedTime ?? this.modifiedTime,
duration: duration ?? this.duration,
isLivePhoto: isLivePhoto ?? this.isLivePhoto,
);
}
}
@@ -1,13 +1,15 @@
import 'package:flutter/foundation.dart';
import 'package:immich_mobile/domain/models/asset.model.dart';
import 'package:immich_mobile/domain/models/asset/asset.model.dart';
import 'package:immich_mobile/utils/extensions/string.extension.dart';
import 'package:openapi/api.dart';
@immutable
class RemoteAsset extends Asset {
final String remoteId;
final String? livePhotoVideoId;
const RemoteAsset({
required this.remoteId,
required super.id,
required super.name,
required super.checksum,
required super.height,
@@ -16,23 +18,22 @@ class RemoteAsset extends Asset {
required super.createdTime,
required super.modifiedTime,
required super.duration,
required super.isLivePhoto,
this.livePhotoVideoId,
});
@override
String toString() => """
{
"id": $id,
"remoteId": "$remoteId",
"name": "$name",
"checksum": "$checksum",
"height": $height,
"width": $width,
"height": ${height ?? "-"},
"width": ${width ?? "-"},
"type": "$type",
"createdTime": "$createdTime",
"modifiedTime": "$modifiedTime",
"duration": "$duration",
"isLivePhoto": "$isLivePhoto",
"livePhotoVideoId": "${livePhotoVideoId ?? "-"}",
}""";
@override
@@ -47,7 +48,6 @@ class RemoteAsset extends Asset {
@override
RemoteAsset copyWith({
int? id,
String? remoteId,
String? name,
String? checksum,
@@ -57,10 +57,9 @@ class RemoteAsset extends Asset {
DateTime? createdTime,
DateTime? modifiedTime,
int? duration,
bool? isLivePhoto,
String? livePhotoVideoId,
}) {
return RemoteAsset(
id: id ?? this.id,
remoteId: remoteId ?? this.remoteId,
name: name ?? this.name,
checksum: checksum ?? this.checksum,
@@ -70,7 +69,27 @@ class RemoteAsset extends Asset {
createdTime: createdTime ?? this.createdTime,
modifiedTime: modifiedTime ?? this.modifiedTime,
duration: duration ?? this.duration,
isLivePhoto: isLivePhoto ?? this.isLivePhoto,
livePhotoVideoId: livePhotoVideoId ?? this.livePhotoVideoId,
);
}
factory RemoteAsset.fromDto(AssetResponseDto dto) => RemoteAsset(
remoteId: dto.id,
createdTime: dto.fileCreatedAt,
duration: dto.duration.tryParseInt() ?? 0,
height: dto.exifInfo?.exifImageHeight?.toInt(),
width: dto.exifInfo?.exifImageWidth?.toInt(),
checksum: dto.checksum,
name: dto.originalFileName,
livePhotoVideoId: dto.livePhotoVideoId,
modifiedTime: dto.fileModifiedAt,
type: _toAssetType(dto.type),
);
}
AssetType _toAssetType(AssetTypeEnum type) => switch (type) {
AssetTypeEnum.AUDIO => AssetType.audio,
AssetTypeEnum.IMAGE => AssetType.image,
AssetTypeEnum.VIDEO => AssetType.video,
_ => AssetType.other,
};