Skip to content
← Public packages

@kentcdodds/audible

Personal Audible library app — browser re-auth, library, wishlist, NAS archive stub.

src/nas-status-write-through.ts

43 lines · 1.2 KB · TypeScript
/**
 * Write-through NAS status cache entries (audit repair / agent corrections).
 * Marks titles On NAS without calling home — use only when disk presence is verified.
 */
import { writeThroughNasStatus } from './nas-status-cache.ts'

export type NasStatusWriteThroughInput = {
	updates: Array<{
		title: string
		asin?: string
		filename: string
		onNas?: boolean
	}>
}

/**
 * Batch write-through for verified On-NAS filenames.
 *
 * @example
 * import writeThrough from 'kody:@kentcdodds/audible/nas-status-write-through'
 * await writeThrough({ updates: [{ title: 'Edgedancer', asin: 'B07626B9D2', filename: 'Edgedancer - From the Stormlight Archive.m4b' }] })
 */
export default async function nasStatusWriteThrough(
	input: NasStatusWriteThroughInput,
): Promise<{ ok: true; updated: number }> {
	const updates = Array.isArray(input?.updates) ? input.updates : []
	let updated = 0
	for (const row of updates) {
		const title = row?.title?.trim()
		const filename = row?.filename?.trim()
		if (!title || !filename) continue
		await writeThroughNasStatus({
			title,
			asin: row.asin,
			filename,
			onNas: row.onNas !== false,
		})
		updated += 1
	}
	return { ok: true, updated }
}

export { writeThroughNasStatus }