Keep wrappers off the library mid-prompt so Use as input and Extend restore the same split, send stills to xAIGen as hidden inputs, and stop the two-column library from growing with the list. Co-authored-by: Cursor <cursoragent@cursor.com>
49 lines
1.9 KiB
TypeScript
49 lines
1.9 KiB
TypeScript
import { passwordAuthEnabled, privateInstanceId } from '~/server/utils/localAuth'
|
|
import { saveStill } from '~/server/utils/library'
|
|
|
|
function ingestOwner() {
|
|
if (passwordAuthEnabled()) return privateInstanceId()
|
|
return 'local'
|
|
}
|
|
|
|
function assertIngestToken(event: Parameters<typeof getHeader>[0]) {
|
|
const expected = String(useRuntimeConfig().backupIngestToken || process.env.BACKUP_INGEST_TOKEN || '').trim()
|
|
if (!expected) {
|
|
throw createError({ statusCode: 503, statusMessage: 'Backup ingest is not configured' })
|
|
}
|
|
const header = String(getHeader(event, 'authorization') || '')
|
|
if (header !== `Bearer ${expected}`) {
|
|
throw createError({ statusCode: 401, statusMessage: 'Unauthorized' })
|
|
}
|
|
}
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
assertIngestToken(event)
|
|
const form = await readMultipartFormData(event)
|
|
if (!form?.length) throw createError({ statusCode: 400, statusMessage: 'Expected an image upload' })
|
|
const fields: Record<string, string> = {}
|
|
let image: { filename: string; data: Buffer } | null = null
|
|
for (const part of form) {
|
|
if (part.name === 'image' && part.filename && part.data?.length) {
|
|
image = { filename: part.filename, data: part.data }
|
|
} else if (part.name && part.data) {
|
|
fields[part.name] = part.data.toString('utf8')
|
|
}
|
|
}
|
|
if (!image) throw createError({ statusCode: 400, statusMessage: 'An image is required' })
|
|
const owner = ingestOwner()
|
|
const still = await saveStill({
|
|
ownerKey: owner,
|
|
folderId: 'inbox',
|
|
filename: image.filename,
|
|
data: image.data,
|
|
width: Number(fields.width || 0),
|
|
height: Number(fields.height || 0),
|
|
hideInput: true,
|
|
role: 'input',
|
|
name: (fields.name || '').trim().slice(0, 80) || undefined
|
|
})
|
|
if (!still) throw createError({ statusCode: 400, statusMessage: 'Backup studio already has that still' })
|
|
return { ok: true, id: still.id }
|
|
})
|