update ai buttons

This commit is contained in:
Garret Patti
2026-04-14 19:55:44 -04:00
parent dae33a36bc
commit afcf740f63
6 changed files with 255 additions and 166 deletions

View File

@@ -269,7 +269,7 @@ async function processNextJob(): Promise<boolean> {
await generateItemDescription(row.item_key)
break
case 'extract':
await extractItemText(row.item_key, jobPayload?.ocrLanguages)
await extractItemText(row.item_key, jobPayload?.ocrLanguages, jobPayload?.ocrMode)
break
case 'translate':
await translateItemText(row.item_key, sourceLanguage || undefined)

View File

@@ -538,7 +538,7 @@ async function extractWithTesseract(
* Translation is not performed automatically — call translateItemText() separately.
* Returns { extractedText, translatedText } where translatedText is always null.
*/
export async function extractItemText(itemKey: string, ocrLanguagesOverride?: string): Promise<{ extractedText: string; translatedText: string | null }> {
export async function extractItemText(itemKey: string, ocrLanguagesOverride?: string, ocrModeOverride?: string): Promise<{ extractedText: string; translatedText: string | null }> {
const libraryId = itemKey.split(':')[0]
const config = getEffectiveAiConfig(libraryId)
@@ -567,7 +567,8 @@ export async function extractItemText(itemKey: string, ocrLanguagesOverride?: st
throw Object.assign(new Error('Text extraction is only available for images'), { code: 'NO_IMAGE' })
}
const { ocrMode, ocrLanguages: configOcrLanguages, ocrConfidenceThreshold } = config
const { ocrMode: configOcrMode, ocrLanguages: configOcrLanguages, ocrConfidenceThreshold } = config
const ocrMode = ocrModeOverride ?? configOcrMode
const ocrLanguages = ocrLanguagesOverride?.trim() || configOcrLanguages
// ── Tesseract path ────────────────────────────────────────────────────────
@@ -655,6 +656,14 @@ export function updateExtractedText(itemKey: string, text: string): void {
db.prepare('UPDATE media_items SET extracted_text = ? WHERE item_key = ?').run(text, itemKey)
}
/**
* Update the ai_description of an item.
*/
export function updateAiDescription(itemKey: string, description: string): void {
const db = getDb()
db.prepare('UPDATE media_items SET ai_description = ? WHERE item_key = ?').run(description, itemKey)
}
/**
* Translate text to a target language using the chat API.
* Returns null if the text is already in the target language.