feat: connect subject template library

This commit is contained in:
2026-05-18 15:59:56 +08:00
parent d9b51348fe
commit 48d4002cbd
4 changed files with 503 additions and 38 deletions

View File

@@ -359,6 +359,49 @@ export function characterLibraryImageUrl(filename: string): string {
return `${API_BASE}/character-library/skg/images/${filename}`
}
export async function listSubjectTemplates(): Promise<SubjectTemplateItem[]> {
const res = await fetch(`${API_BASE}/subject-templates`)
if (!res.ok) {
const txt = await res.text().catch(() => "")
throw new Error(`listSubjectTemplates ${res.status} ${txt.slice(0, 300)}`)
}
return res.json()
}
export function subjectTemplateImageUrl(filename: string): string {
return `${API_BASE}/subject-templates/images/${filename}`
}
export async function saveSubjectTemplate(
jobId: string,
body: {
name: string
note?: string
frame_idx: number
element_id: string
asset_ids: string[]
subject_style?: "transparent_human" | "source_actor"
},
): Promise<SubjectTemplateItem> {
const res = await fetch(`${API_BASE}/jobs/${jobId}/subject-templates`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
name: body.name,
note: body.note ?? "",
frame_idx: body.frame_idx,
element_id: body.element_id,
asset_ids: body.asset_ids,
subject_style: body.subject_style ?? "transparent_human",
}),
})
if (!res.ok) {
const txt = await res.text().catch(() => "")
throw new Error(`saveSubjectTemplate ${res.status} ${txt.slice(0, 300)}`)
}
return res.json()
}
export async function copyCharacterLibraryAssets(jobId: string, characterId: string): Promise<{ character_id: string; character_name: string; images: ImageRef[] }> {
const res = await fetch(`${API_BASE}/jobs/${jobId}/assets/character-library`, {
method: "POST",
@@ -520,6 +563,38 @@ export interface CharacterLibraryItem {
images: CharacterLibraryImage[]
}
export interface SubjectTemplateImage {
id: string
view: string
label: string
filename: string
url: string
width: number
height: number
background: "white" | "black"
quality: "hd"
size: "source" | "1024" | "1536" | "2048"
source_asset_id: string
source_frame_indices: number[]
created_at: number
}
export interface SubjectTemplateItem {
id: string
name: string
description: string
note: string
source: "database"
source_job_id: string
source_frame_idx: number
source_element_id: string
subject_style: "transparent_human" | "source_actor"
primary_image: string
images: SubjectTemplateImage[]
created_at: number
updated_at: number
}
export interface TranscriptSegment {
index: number
start: number
@@ -1087,6 +1162,7 @@ export async function generateSubjectAssets(
source_frame_indices?: number[]
views?: string[]
character_id?: string
subject_template_id?: string
subject_style?: "transparent_human" | "source_actor"
reconstruction_mode?: "same" | "similar"
prompt?: string
@@ -1104,6 +1180,7 @@ export async function generateSubjectAssets(
source_frame_indices: body.source_frame_indices ?? null,
views: body.views ?? null,
character_id: body.character_id ?? "",
subject_template_id: body.subject_template_id ?? "",
subject_style: body.subject_style ?? "transparent_human",
reconstruction_mode: body.reconstruction_mode ?? "same",
prompt: body.prompt ?? "",