9216a8687f
Adds the duplicate-detection backend on top of perceptual hashing:
- Two tables (edited into the original migrations): data.duplicate_pairs holds
precomputed near-duplicate candidates (rebuilt wholesale by the rescan), and
data.duplicate_dismissals is a global "not a duplicate" overlay that survives
rescans. New audit actions file_merge / duplicate_dismiss.
- DuplicateService:
- Rescan builds every pair within DUPLICATE_HASH_THRESHOLD via a BK-tree over
the perceptual hashes and replaces the pairs table. This is the only thing
that populates pairs, so GET never compares all-vs-all (scales to 110k+).
- Clusters reads the precomputed pairs (ACL-filtered, non-trashed, non-
dismissed), groups them into connected components via union-find, and
paginates whole clusters.
- Resolve merges a pair field-by-field: each scalar from keep or discard,
metadata keep/discard/shallow-merge, tags/pools keep or union; then trashes
the discarded file. Enforces edit ACL on both.
- Dismiss records a canonical pair (view ACL on both).
- Endpoints under /files: GET /files/duplicates, POST /files/duplicates/dismiss,
POST /files/duplicates/resolve (registered before /:id to avoid collision).
Plain delete reuses /files/bulk/delete.
- Repo support: ListMissingPHash, ListAllPHashes, CopyPoolMemberships, plus the
DuplicatePairRepo (ReplaceAll via COPY, ListVisible) and DismissalRepo.
Unit tests cover the BK-tree pairing, union-find clustering, metadata merge and
field validation; an integration test covers rescan -> list -> merge -> dismiss
(including that a dismissal survives a re-rescan).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
24 lines
856 B
Go
24 lines
856 B
Go
package handler
|
|
|
|
import "testing"
|
|
|
|
// TestNewRouterRegisters builds the router with typed-nil dependencies to assert
|
|
// route registration itself succeeds. Gin panics on a route conflict (e.g. a
|
|
// duplicated method+path or an inconsistent wildcard name) during registration,
|
|
// before any handler runs — so this catches such mistakes without a database.
|
|
// Handlers are never invoked here; method values on nil pointers are fine.
|
|
func TestNewRouterRegisters(t *testing.T) {
|
|
r, err := NewRouter(
|
|
(*AuthMiddleware)(nil), (*AuthHandler)(nil),
|
|
(*FileHandler)(nil), (*DuplicateHandler)(nil), (*TagHandler)(nil), (*CategoryHandler)(nil), (*PoolHandler)(nil),
|
|
(*UserHandler)(nil), (*ACLHandler)(nil), (*AuditHandler)(nil),
|
|
"", nil,
|
|
)
|
|
if err != nil {
|
|
t.Fatalf("NewRouter: %v", err)
|
|
}
|
|
if r == nil {
|
|
t.Fatal("NewRouter returned nil engine")
|
|
}
|
|
}
|