feat(library): removing a bad file keeps its track, waiting for a good copy
release / go (push) Successful in 2m6s
release / web (push) Successful in 1m15s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 4m46s
release / android (push) Successful in 4m47s
release / Build signed APK (push) Successful in 5m38s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 31s
release / Verify release artifacts (tag releases only) (push) Skipped
release / go (push) Successful in 2m6s
release / web (push) Successful in 1m15s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 4m46s
release / android (push) Successful in 4m47s
release / Build signed APK (push) Successful in 5m38s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 31s
release / Verify release artifacts (tag releases only) (push) Skipped
Reports, Duplicates and Suspect sources now end the same way: the file
goes and the track stays, marked missing with its likes, plays and
playlist places, until a good copy lands in the library and move
adoption or missing-pair folding brings it back.
- library.RemoveFile removes one track's file and marks the track
missing with the queue it was removed from and who removed it
(tracks.removed_reason / removed_by, migration 0104). The duplicate
resolver's wrong-slot removal shares the same marking.
- POST /api/admin/quarantine/{id}/remove-file removes a reported file,
clears the listeners' reports, marks open playback errors deleted and
records removed_file in the Reports history. A wrong-file or
wrong-tags report drops the file's recording MBID.
- POST /api/admin/library/suspect-sources/{id}/remove removes a video
rip's file and its MBID, and writes a suspect_file_remove audit row.
- The removal reason clears with the missing mark when a file returns.
Grimoire #7743 (milestone 635).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
// Package quarantine owns the per-user track quarantine workflow.
|
||||
// Users flag a track as broken (Flag/Unflag), the SPA hides the track
|
||||
// from their views, and admins resolve the resulting reports via the
|
||||
// Service's admin actions (Resolve / DeleteFile).
|
||||
// Service's admin actions (Resolve / RemoveFile / DeleteFile).
|
||||
package quarantine
|
||||
|
||||
import (
|
||||
@@ -265,3 +265,69 @@ func (s *Service) DeleteFile(ctx context.Context, trackID, adminID pgtype.UUID)
|
||||
AdminID: adminID, AffectedUsers: affected,
|
||||
})
|
||||
}
|
||||
|
||||
// RemoveFile removes a reported track's file and keeps the track: it waits,
|
||||
// missing, for a good copy, with its likes and plays (library.RemoveFile).
|
||||
// The reports are settled with it: every listener's report is cleared, so the
|
||||
// track is back in their views once a good copy lands, its open playback
|
||||
// errors are marked deleted, and the Reports history records the removal.
|
||||
//
|
||||
// A report saying the file is another song, or that its tags are wrong, means
|
||||
// the file's recording MBID is not to be trusted, so it goes with the file.
|
||||
//
|
||||
// If the file cannot be removed, nothing changes and the error wraps a
|
||||
// *library.FileRemoveError.
|
||||
func (s *Service) RemoveFile(ctx context.Context, trackID, adminID pgtype.UUID) (dbq.QuarantineAction, error) {
|
||||
q := dbq.New(s.pool)
|
||||
track, err := q.GetTrackByID(ctx, trackID)
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return dbq.QuarantineAction{}, ErrTrackNotFound
|
||||
}
|
||||
return dbq.QuarantineAction{}, fmt.Errorf("get track: %w", err)
|
||||
}
|
||||
snap, err := s.snapshot(ctx, q, track)
|
||||
if err != nil {
|
||||
return dbq.QuarantineAction{}, err
|
||||
}
|
||||
reports, err := q.ListQuarantineReportsForTrack(ctx, trackID)
|
||||
if err != nil {
|
||||
return dbq.QuarantineAction{}, fmt.Errorf("list reports: %w", err)
|
||||
}
|
||||
forget := false
|
||||
for _, r := range reports {
|
||||
if r.Reason == dbq.QuarantineReasonWrongFile || r.Reason == dbq.QuarantineReasonWrongTags {
|
||||
forget = true
|
||||
}
|
||||
}
|
||||
|
||||
var action dbq.QuarantineAction
|
||||
deleted := "deleted"
|
||||
_, err = library.RemoveFile(ctx, s.pool, nil, library.RemoveFileParams{
|
||||
TrackID: trackID, ActorID: adminID, Reason: library.RemovedForReport, ForgetMBID: forget,
|
||||
Within: func(ctx context.Context, tq *dbq.Queries) error {
|
||||
if err := tq.DeleteQuarantineForTrack(ctx, trackID); err != nil {
|
||||
return fmt.Errorf("delete rows: %w", err)
|
||||
}
|
||||
if _, err := tq.ResolveAllPlaybackErrorsForTrack(ctx, dbq.ResolveAllPlaybackErrorsForTrackParams{
|
||||
TrackID: trackID, ResolvedBy: adminID, Resolution: &deleted,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("resolve playback errors: %w", err)
|
||||
}
|
||||
var err error
|
||||
action, err = tq.WriteQuarantineAction(ctx, dbq.WriteQuarantineActionParams{
|
||||
TrackID: trackID, TrackTitle: snap.TrackTitle, ArtistName: snap.ArtistName,
|
||||
AlbumTitle: snap.AlbumTitle, Action: dbq.QuarantineActionKindRemovedFile,
|
||||
AdminID: adminID, AffectedUsers: int32(len(reports)),
|
||||
})
|
||||
return err
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
if errors.Is(err, library.ErrTrackNotFound) {
|
||||
return dbq.QuarantineAction{}, ErrTrackNotFound
|
||||
}
|
||||
return dbq.QuarantineAction{}, fmt.Errorf("remove file: %w", err)
|
||||
}
|
||||
return action, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user