Add asset-pack Image v2 API for Family Board stickers.

POST /api/assets/generate wraps Flux/Krea generate with sticker/panel/icon presets; GET /api/assets/{id} returns status and PNG URLs using the existing poll path.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Towsty
2026-10-06 19:06:14 -05:00
co-authored by Cursor
parent f6c5ef8af5
commit 26a3bfb797
6 changed files with 530 additions and 0 deletions
+94
View File
@@ -0,0 +1,94 @@
import { clampImageV2Size, parseImageV2Engine, type ImageV2Engine } from '~/utils/imageV2'
export const ASSET_PACK_STYLES = ['sticker', 'panel_bg', 'icon'] as const
export type AssetPackStyle = (typeof ASSET_PACK_STYLES)[number]
export const ASSET_PACK_DEFAULT_NEGATIVE = [
'photoreal',
'celebrity',
'watermark',
'logo',
'signature',
'readable text',
'trademarked names',
'Sonic',
'Mario',
'Minecraft',
'Nintendo',
'Sega',
'Mojang',
'NSFW',
'nude',
'gore',
'bloody',
'horror'
].join(', ')
const STYLE_PRESETS: Record<AssetPackStyle, {
prefix: string
suffix: string
defaultWidth: number
defaultHeight: number
}> = {
sticker: {
prefix: 'die-cut sticker illustration, clean bold outline, flat soft shading, centered subject, plain transparent-friendly background, cute original character mascot',
suffix: 'kid-friendly UI sticker, high clarity, no watermark, original character not based on copyrighted IP',
defaultWidth: 1024,
defaultHeight: 1024
},
panel_bg: {
prefix: 'subtle repeating decorative background, soft kid-friendly theme, even lighting, not busy',
suffix: 'gentle panel background, no text, no logo, original pattern',
defaultWidth: 1280,
defaultHeight: 1280
},
icon: {
prefix: 'simple high-contrast UI icon, centered, clean silhouette, minimal detail',
suffix: 'app icon style, plain background, readable at small size, original symbol',
defaultWidth: 768,
defaultHeight: 768
}
}
export function parseAssetPackStyle(raw: unknown, fallback: AssetPackStyle = 'sticker'): AssetPackStyle {
const value = String(raw || '').trim().toLowerCase()
return (ASSET_PACK_STYLES as readonly string[]).includes(value)
? (value as AssetPackStyle)
: fallback
}
export function parseAssetPackEngine(raw: unknown, fallback: ImageV2Engine = 'flux'): ImageV2Engine {
return parseImageV2Engine(raw, fallback)
}
export function assetPackSize(style: AssetPackStyle, width?: unknown, height?: unknown) {
const preset = STYLE_PRESETS[style]
return clampImageV2Size(
width == null || width === '' ? preset.defaultWidth : width,
height == null || height === '' ? preset.defaultHeight : height
)
}
export function buildAssetPackPrompt(opts: {
prompt: string
style?: AssetPackStyle
transparentFriendly?: boolean
}) {
const style = opts.style || 'sticker'
const preset = STYLE_PRESETS[style]
const body = String(opts.prompt || '').trim()
const transparent = opts.transparentFriendly
? 'solid plain background for easy keying or crop, no busy backdrop, chroma-friendly fill'
: ''
return [preset.prefix, transparent, body, preset.suffix]
.map(part => String(part || '').trim())
.filter(Boolean)
.join(', ')
}
export function buildAssetPackNegative(userNegative?: string) {
const extra = String(userNegative || '').trim()
return extra
? `${ASSET_PACK_DEFAULT_NEGATIVE}, ${extra}`
: ASSET_PACK_DEFAULT_NEGATIVE
}