Files
photochk/Sources/Photochk/Services/TrashService.swift
T
yfoxjpandClaude Opus 5 c7f68b6cca Photochk 1.0.0 — 類似写真を探して整理する macOS アプリ
フォルダ内の写真から、中身が同じものと見た目が似ているものを検出して
グループにまとめ、残す1枚を選んでほかをゴミ箱へ送れるようにする。

検出は安い判定から順に4段:
- ファイルサイズが同じものだけ SHA-256 でバイト一致を確定
- dHash(知覚ハッシュ)のハミング距離で候補ペアを抽出
- 候補に出てくる画像だけ Vision の feature print で精査
- Union-Find で連結成分をグループ化

判定のしきい値は実写画像で距離を実測して決めた(docs/calibration.md)。
tools/release-update.sh で Gitea のリリースを更新する。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-28 08:02:14 +09:00

31 lines
974 B
Swift

import AppKit
import Foundation
/// 選択されたファイルをゴミ箱へ送る。削除ではないので Finder から戻せる。
enum TrashService {
struct Outcome: Sendable {
var trashed: [URL] = []
var failed: [URL] = []
var errorDescription: String?
}
@MainActor
static func moveToTrash(_ urls: [URL]) async -> Outcome {
guard !urls.isEmpty else { return Outcome() }
let (moved, error): ([URL: URL], Error?) = await withCheckedContinuation { continuation in
NSWorkspace.shared.recycle(urls) { newURLs, error in
continuation.resume(returning: (newURLs, error))
}
}
let trashed = urls.filter { moved[$0] != nil }
let failed = urls.filter { moved[$0] == nil }
return Outcome(
trashed: trashed,
failed: failed,
errorDescription: failed.isEmpty ? nil : error?.localizedDescription
)
}
}