gongxiangp2/lib/material-access-scope.ts

44 lines
1.5 KiB
TypeScript

export const MATERIAL_ACCESS_SCOPES = ['general', 'operations_g'] as const
export type MaterialAccessScope = (typeof MATERIAL_ACCESS_SCOPES)[number]
export const EXTERNAL_MATERIAL_SCOPE_WHERE = {
accessScope: 'general',
taskDetailPrivate: false,
} as const
export const MATERIAL_ACCESS_SCOPE_LABELS: Record<MaterialAccessScope, string> = {
general: '通用素材',
operations_g: '运营中心 G 专属',
}
export function isMaterialAccessScope(value: unknown): value is MaterialAccessScope {
return value === 'general' || value === 'operations_g'
}
export function normalizeMaterialAccessScope(value: unknown): MaterialAccessScope {
if (value == null || value === '') return 'general'
if (isMaterialAccessScope(value)) 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:')
)
}