gongxiangp2/lib/detail-generator/brand-availability.ts

15 lines
809 B
TypeScript

import type { DetailBrandProfile, DetailBrandProfileRecord } from './types'
/** A catalogue name or a color-only draft is not a migrated brand knowledge profile. */
export function hasDetailBrandKnowledge(profile?: DetailBrandProfile): boolean {
const source = profile?.source
return !!profile?.tone.trim() && !!source?.label.trim() && !!source.version.trim()
&& source.files.some(file => !!file.name.trim() && /^[a-f0-9]{64}$/i.test(file.sha256))
&& (['palette', 'materials', 'props', 'lighting', 'composition', 'quality'] as const)
.every(key => !!profile.visualRules?.[key]?.trim())
}
export function isDetailBrandAvailable(profiles: DetailBrandProfileRecord[], name: string): boolean {
return profiles.some(row => row.profile.name === name && hasDetailBrandKnowledge(row.profile))
}