From af5287a2ad1d66cd703affc52a1262ed9e0c913f Mon Sep 17 00:00:00 2001 From: yoshikazu Date: Mon, 27 Jul 2026 15:40:30 +0000 Subject: [PATCH] Add PhotoAsset model --- Sources/Photochk/Models/PhotoAsset.swift | 40 ++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Sources/Photochk/Models/PhotoAsset.swift diff --git a/Sources/Photochk/Models/PhotoAsset.swift b/Sources/Photochk/Models/PhotoAsset.swift new file mode 100644 index 0000000..6780d98 --- /dev/null +++ b/Sources/Photochk/Models/PhotoAsset.swift @@ -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 + }() +}