feat(api): list the duplicate songs, check their files and delete the extra copies

Admin only. GET /library/duplicates lists the groups with what is needed to choose and never a path; POST|GET|DELETE /library/duplicates/check is the job that fingerprints the files; POST /library/duplicates/clean deletes the chosen copies of one song, each refusal with its own status and code (deletion_disabled, scan_running, invalid_input, track_not_found, duplicate_changed, library_read_only). In the spec with the contract test, and wired in main, where an info line says when library.allow_delete is on.
This commit is contained in:
tgiachi 2026-11-12 16:46:50 +01:00
commit 30f45bb383

View file

@ -21,6 +21,7 @@ import (
"codeberg.org/squidd/sonda/internal/config"
"codeberg.org/squidd/sonda/internal/discover"
"codeberg.org/squidd/sonda/internal/discovery"
"codeberg.org/squidd/sonda/internal/duplicates"
"codeberg.org/squidd/sonda/internal/feedback"
"codeberg.org/squidd/sonda/internal/images"
"codeberg.org/squidd/sonda/internal/jobs"
@ -261,6 +262,17 @@ func run() error {
Preference: cfg.Scoring.WeightPreference, Discovery: cfg.Scoring.WeightDiscovery,
}
// Deleting the extra copy of a song is the one thing that makes Sonda write in the music folders:
// off unless the operator turned it on, and said in the log when it is on.
duplicateSvc := duplicates.NewService(storage.NewDuplicatesRepo(db), duplicates.Options{
AllowDelete: cfg.Library.AllowDelete,
ScanRunning: func() bool { return scans.Status().Running },
Logger: logger,
})
if cfg.Library.AllowDelete {
logger.Warn("library.allow_delete is on: an admin can delete duplicate files from the music folders")
}
router := httpapi.NewRouter(httpapi.Deps{
Logger: logger,
Auth: auth.NewService(storage.NewUserRepo(db), storage.NewRefreshRepo(db), tokens, cfg.Auth.RefreshTTL()),
@ -281,6 +293,8 @@ func run() error {
CoversJob: jobs.Runner{Ctx: ctx, Job: images.NewCoversJob(pictures, imageRepo)},
ArtistImagesJob: jobs.Runner{Ctx: ctx, Job: images.NewArtistImagesJob(pictures, imageRepo)},
DescriptionsJob: jobs.Runner{Ctx: ctx, Job: about.NewJob(descriptions, discoveryRepo)},
Duplicates: duplicateSvc,
DuplicatesJob: jobs.Runner{Ctx: ctx, Job: duplicates.NewHashJob(duplicateSvc)},
ArtistImages: pictures,
About: descriptions,
Settings: userSettings,