1
0

feat: rip status resolution with override and match links

This commit is contained in:
2026-08-29 16:57:34 +02:00
parent c49321ccf1
commit e8a83eeefb
2 changed files with 89 additions and 0 deletions

31
server/src/ripstatus.ts Normal file
View File

@@ -0,0 +1,31 @@
import type { DB } from './db.js'
import { isConfidentMatch } from './matcher.js'
export type RipStatus = 'ripped' | 'not_ripped'
/**
* Resolution order per spec:
* 1. manual rip_override (non-null) wins
* 2. else a stored match_link means ripped
* 3. else confident fuzzy match against the user's digital_albums
*/
export function resolveRipStatus(db: DB, userId: number, itemId: number): RipStatus {
const item = db
.prepare('SELECT id, title, artist, rip_override FROM collection_items WHERE id = ? AND user_id = ?')
.get(itemId, userId) as
| { id: number; title: string; artist: string; rip_override: number | null }
| undefined
if (!item) return 'not_ripped'
if (item.rip_override !== null && item.rip_override !== undefined) {
return item.rip_override === 1 ? 'ripped' : 'not_ripped'
}
const link = db.prepare('SELECT album_id FROM match_links WHERE item_id = ?').get(itemId)
if (link) return 'ripped'
const albums = db
.prepare('SELECT title, artist FROM digital_albums WHERE user_id = ?')
.all(userId) as { title: string; artist: string }[]
return albums.some((a) => isConfidentMatch(item, a)) ? 'ripped' : 'not_ripped'
}