gongxiangp2/lib/material-access-scope.ts

35 lines
1.3 KiB
TypeScript

export const MATERIAL_ACCESS_SCOPES = ['general', 'operations_g'] as const
export type MaterialAccessScope = (typeof MATERIAL_ACCESS_SCOPES)[number]
export const MATERIAL_ACCESS_SCOPE_LABELS: Record<MaterialAccessScope, string> = {
general: '通用素材',
operations_g: '运营中心 G 专属',
}
export function normalizeMaterialAccessScope(value: unknown): MaterialAccessScope {
if (value == null || value === '') return 'general'
if (value === 'general' || value === 'operations_g') return value
throw new Error('使用范围只能是通用素材或运营中心 G 专属')
}
export function isOperationsGMaterial(material: { accessScope?: string | null }): boolean {
return material.accessScope === 'operations_g'
}
export function isRestrictedMaterial(material: {
accessScope?: string | null
taskDetailPrivate?: boolean | null
}): boolean {
return isOperationsGMaterial(material) || material.taskDetailPrivate === true
}
export function isPreviewAssetType(assetType: unknown): boolean {
const normalized = String(assetType || '').trim()
return (
['preview', 'main-preview', 'sku-preview', 'detail-preview', 'report-image'].includes(normalized) ||
normalized.startsWith('standard-model-white-bg-view:') ||
normalized.startsWith('standard-model-white-bg-other:')
)
}