Add PhotoAsset model

This commit is contained in:
2026-07-27 15:40:30 +00:00
parent a6cc8121ce
commit af5287a2ad
+40
View File
@@ -0,0 +1,40 @@
import Foundation
/// スキャン対象の写真1枚。ファイル URL を同一性とする。
struct PhotoAsset: Identifiable, Hashable, Sendable {
var id: URL { url }
let url: URL
let fileSize: Int64
let modificationDate: Date
/// EXIF の撮影日時。無ければファイルの作成日。
var captureDate: Date?
var pixelWidth: Int
var pixelHeight: Int
var fileName: String { url.lastPathComponent }
/// 画素数。代表選出の第一基準。
var pixelCount: Int { pixelWidth * pixelHeight }
var dimensionText: String {
pixelWidth > 0 && pixelHeight > 0 ? "\(pixelWidth) × \(pixelHeight)" : "—"
}
var fileSizeText: String {
ByteCountFormatter.string(fromByteCount: fileSize, countStyle: .file)
}
var captureDateText: String {
guard let captureDate else { return "—" }
return PhotoAsset.displayDateFormatter.string(from: captureDate)
}
private static let displayDateFormatter: DateFormatter = {
let f = DateFormatter()
f.dateStyle = .medium
f.timeStyle = .short
return f
}()
}