add svg metadata loading (#3719)

Co-authored-by: filtered <176114999+webfiltered@users.noreply.github.com>
This commit is contained in:
thot experiment
2025-05-01 16:26:24 -07:00
committed by GitHub
parent f7e4ed23d7
commit 878aedb4f7
5 changed files with 627 additions and 1 deletions

View File

@@ -0,0 +1,18 @@
import { ComfyMetadata } from '@/types/metadataTypes'
export async function getSvgMetadata(file: File): Promise<ComfyMetadata> {
const text = await file.text()
const metadataMatch =
/<metadata>\s*<!\[CDATA\[([\s\S]*?)\]\]>\s*<\/metadata>/i.exec(text)
if (metadataMatch && metadataMatch[1]) {
try {
return JSON.parse(metadataMatch[1].trim())
} catch (error) {
console.error('Error parsing SVG metadata:', error)
return {}
}
}
return {}
}