AI generate only produces images, so Video Pin / Reel / TikTok Video are filtered out in previewOnly and rejected server-side with a clear error. Co-authored-by: Cursor <cursoragent@cursor.com>
32 lines
1,023 B
TypeScript
32 lines
1,023 B
TypeScript
import { getMediaRulesForContentType } from '@/composables/useMediaRules';
|
|
|
|
/**
|
|
* The automation Generate node (and AI wizard) only produce images. When
|
|
* `imageOnly` is true (previewOnly / generate context), drop video-only
|
|
* content types so they can't be selected.
|
|
*/
|
|
export const filterImageCapableVariants = <T extends { value: string }>(
|
|
variants: readonly T[],
|
|
imageOnly: boolean,
|
|
): T[] => {
|
|
if (! imageOnly) {
|
|
return [...variants];
|
|
}
|
|
|
|
return variants.filter((variant) => getMediaRulesForContentType(variant.value).acceptImages);
|
|
};
|
|
|
|
/**
|
|
* When the current content type was filtered out (e.g. Video Pin in Generate),
|
|
* return the first remaining variant to switch to — or null when already valid.
|
|
*/
|
|
export const fallbackImageCapableVariant = (
|
|
contentType: string,
|
|
available: readonly { value: string }[],
|
|
): string | null => {
|
|
if (available.some((variant) => variant.value === contentType)) {
|
|
return null;
|
|
}
|
|
|
|
return available[0]?.value ?? null;
|
|
};
|