You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.1 KiB
80 lines
2.1 KiB
/// Represents an asset (image) from Immich API.
|
|
class ImmichAsset {
|
|
/// Unique identifier for the asset.
|
|
final String id;
|
|
|
|
/// File name of the asset.
|
|
final String fileName;
|
|
|
|
/// Creation date/time of the asset.
|
|
final DateTime createdAt;
|
|
|
|
/// File size in bytes.
|
|
final int fileSize;
|
|
|
|
/// MIME type of the asset.
|
|
final String mimeType;
|
|
|
|
/// Width of the image in pixels.
|
|
final int? width;
|
|
|
|
/// Height of the image in pixels.
|
|
final int? height;
|
|
|
|
/// Creates an [ImmichAsset] instance.
|
|
ImmichAsset({
|
|
required this.id,
|
|
required this.fileName,
|
|
required this.createdAt,
|
|
required this.fileSize,
|
|
required this.mimeType,
|
|
this.width,
|
|
this.height,
|
|
});
|
|
|
|
/// Creates an [ImmichAsset] from Immich API JSON response.
|
|
factory ImmichAsset.fromJson(Map<String, dynamic> json) {
|
|
return ImmichAsset(
|
|
id: json['id'] as String,
|
|
fileName: json['originalFileName'] as String? ?? json['fileName'] as String? ?? 'unknown',
|
|
createdAt: DateTime.parse(json['createdAt'] as String),
|
|
fileSize: json['fileSizeByte'] as int? ?? json['fileSize'] as int? ?? 0,
|
|
mimeType: json['mimeType'] as String? ?? 'image/jpeg',
|
|
width: json['exifInfo']?['imageWidth'] as int?,
|
|
height: json['exifInfo']?['imageHeight'] as int?,
|
|
);
|
|
}
|
|
|
|
/// Converts [ImmichAsset] to JSON for local storage.
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'fileName': fileName,
|
|
'createdAt': createdAt.toIso8601String(),
|
|
'fileSize': fileSize,
|
|
'mimeType': mimeType,
|
|
'width': width,
|
|
'height': height,
|
|
};
|
|
}
|
|
|
|
/// Creates an [ImmichAsset] from local storage JSON.
|
|
factory ImmichAsset.fromLocalJson(Map<String, dynamic> json) {
|
|
return ImmichAsset(
|
|
id: json['id'] as String,
|
|
fileName: json['fileName'] as String,
|
|
createdAt: DateTime.parse(json['createdAt'] as String),
|
|
fileSize: json['fileSize'] as int,
|
|
mimeType: json['mimeType'] as String,
|
|
width: json['width'] as int?,
|
|
height: json['height'] as int?,
|
|
);
|
|
}
|
|
|
|
@override
|
|
String toString() {
|
|
return 'ImmichAsset(id: $id, fileName: $fileName, createdAt: $createdAt)';
|
|
}
|
|
}
|
|
|