Phase 2 complete
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
/// 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)';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/// Response from Immich upload API.
|
||||
class UploadResponse {
|
||||
/// The unique identifier of the uploaded asset.
|
||||
final String id;
|
||||
|
||||
/// Whether the upload was a duplicate (already existed).
|
||||
final bool duplicate;
|
||||
|
||||
/// Creates an [UploadResponse] instance.
|
||||
UploadResponse({
|
||||
required this.id,
|
||||
required this.duplicate,
|
||||
});
|
||||
|
||||
/// Creates an [UploadResponse] from Immich API JSON response.
|
||||
factory UploadResponse.fromJson(Map<String, dynamic> json) {
|
||||
return UploadResponse(
|
||||
id: json['id'] as String,
|
||||
duplicate: json['duplicate'] as bool? ?? false,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'UploadResponse(id: $id, duplicate: $duplicate)';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user