test-go / test (push) Failing after 44s
test-web / test (push) Successful in 49s
test-go / integration (push) Failing after 2m42s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / Build signed APK (releases and dev) (push) Canceled after 4m8s
Rule 25: the fingerprinting knobs move out of source into a DB-backed singleton (migration 0061), edited from a card on the Duplicates page and shared live with the scanner, the backfill and the duplicate sweep through one service instance, so a save needs no restart. The length is the knob that can silently break the library: prints taken at two lengths never match. Each track_fingerprints row now records the length it was taken at, and every reader filters on the current one — the backfill treats another length as stale, the gauge counts it pending, the sweep never streams it. Equivalent to a version bump, except that setting the length back makes rows not yet redone current again. The card warns before a length change re-fingerprints the library. Off stops every decode: the scan takes only the stream hash (a demux, and what recognises a moved file) and stores nothing, dropping a changed file's stale row; the backfill idles. A save also makes a sweep due, since a new threshold or length changes what the same prints group into, and the sweep interval gains slack so an hourly interval on an hourly tick doesn't skip every other tick. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SQ31KQpYbStyK5y58UmPLH
68 lines
2.7 KiB
Go
68 lines
2.7 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"net/http"
|
|
|
|
"git.fabledsword.com/bvandeusen/minstrel/internal/apierror"
|
|
"git.fabledsword.com/bvandeusen/minstrel/internal/library"
|
|
)
|
|
|
|
// fingerprintSettingsBody is the wire shape for GET and PUT
|
|
// /api/admin/library/fingerprint-settings (M400 #3913). The threshold travels as
|
|
// the bit-error rate the matcher uses; the card presents it as a match percentage.
|
|
type fingerprintSettingsBody struct {
|
|
Enabled bool `json:"enabled"`
|
|
ChromaprintLengthSec int32 `json:"chromaprint_length_sec"`
|
|
AcousticMaxBitErrorRate float64 `json:"acoustic_max_bit_error_rate"`
|
|
BackfillConcurrency int32 `json:"backfill_concurrency"`
|
|
SweepIntervalHours int32 `json:"sweep_interval_hours"`
|
|
}
|
|
|
|
func fingerprintSettingsBodyOf(s library.FingerprintSettings) fingerprintSettingsBody {
|
|
return fingerprintSettingsBody{
|
|
Enabled: s.Enabled,
|
|
ChromaprintLengthSec: s.ChromaprintLengthSec,
|
|
AcousticMaxBitErrorRate: s.AcousticMaxBitErrorRate,
|
|
BackfillConcurrency: s.BackfillConcurrency,
|
|
SweepIntervalHours: s.SweepIntervalHours,
|
|
}
|
|
}
|
|
|
|
// handleGetFingerprintSettings implements GET /api/admin/library/fingerprint-settings.
|
|
func (h *handlers) handleGetFingerprintSettings(w http.ResponseWriter, _ *http.Request) {
|
|
writeJSON(w, http.StatusOK, fingerprintSettingsBodyOf(h.fingerprintSettings.Get()))
|
|
}
|
|
|
|
// handleUpdateFingerprintSettings implements PUT /api/admin/library/fingerprint-settings.
|
|
//
|
|
// A whole-row write. A body that leaves a field out decodes it as zero, which no
|
|
// field accepts, so a partial save is refused rather than zeroing what it omitted.
|
|
// The saved settings reach the scanner and both workers at once: they share the
|
|
// service instance.
|
|
func (h *handlers) handleUpdateFingerprintSettings(w http.ResponseWriter, r *http.Request) {
|
|
var req fingerprintSettingsBody
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
writeErr(w, apierror.BadRequest("invalid_body", "malformed JSON"))
|
|
return
|
|
}
|
|
saved, err := h.fingerprintSettings.Set(r.Context(), library.FingerprintSettings{
|
|
Enabled: req.Enabled,
|
|
ChromaprintLengthSec: req.ChromaprintLengthSec,
|
|
AcousticMaxBitErrorRate: req.AcousticMaxBitErrorRate,
|
|
BackfillConcurrency: req.BackfillConcurrency,
|
|
SweepIntervalHours: req.SweepIntervalHours,
|
|
})
|
|
if err != nil {
|
|
// Validation mirrors migration 0061's CHECKs and names the field.
|
|
if errors.Is(err, library.ErrFingerprintSettingOutOfRange) {
|
|
writeErr(w, apierror.BadRequest("invalid_setting", err.Error()))
|
|
return
|
|
}
|
|
writeErrWithLog(w, h.logger, "admin fingerprint settings: update failed", apierror.Internal(err))
|
|
return
|
|
}
|
|
writeJSON(w, http.StatusOK, fingerprintSettingsBodyOf(saved))
|
|
}
|