fix(design): normalize video quote options
This commit is contained in:
@@ -45,6 +45,17 @@ type ServerBrief = {
|
||||
missing_decision: string | null;
|
||||
};
|
||||
|
||||
type ServerGenerationOption = {
|
||||
value?: string | number;
|
||||
id?: string | number;
|
||||
seconds?: number;
|
||||
label?: string;
|
||||
default?: boolean;
|
||||
disabled?: boolean;
|
||||
enabled?: boolean;
|
||||
multiplier?: number;
|
||||
};
|
||||
|
||||
type ServerQuote = {
|
||||
quote_id: string;
|
||||
status: DesignGenerationQuote['status'];
|
||||
@@ -60,10 +71,10 @@ type ServerQuote = {
|
||||
duration_seconds: number | null;
|
||||
};
|
||||
generation_options: {
|
||||
models: Array<DesignGenerationOption<string>>;
|
||||
resolutions: Array<DesignGenerationOption<string>>;
|
||||
durations: Array<DesignGenerationOption<number>>;
|
||||
aspect_ratios: Array<DesignGenerationOption<string>>;
|
||||
models: ServerGenerationOption[];
|
||||
resolutions: ServerGenerationOption[];
|
||||
durations: ServerGenerationOption[];
|
||||
aspect_ratios: ServerGenerationOption[];
|
||||
};
|
||||
pricing: {
|
||||
schema: string;
|
||||
@@ -281,6 +292,22 @@ function mapBrief(brief: ServerBrief): DesignBrief {
|
||||
};
|
||||
}
|
||||
|
||||
function mapGenerationOptions<TValue extends string | number>(
|
||||
options: ServerGenerationOption[] | undefined,
|
||||
): DesignGenerationOption<TValue>[] {
|
||||
return (options ?? []).flatMap((option) => {
|
||||
const value = option.value ?? option.id ?? option.seconds;
|
||||
if (typeof value !== 'string' && typeof value !== 'number') return [];
|
||||
return [{
|
||||
value: value as TValue,
|
||||
label: option.label ?? String(value),
|
||||
default: option.default ?? false,
|
||||
disabled: option.disabled ?? option.enabled === false,
|
||||
multiplier: option.multiplier ?? 1,
|
||||
}];
|
||||
});
|
||||
}
|
||||
|
||||
function mapQuote(quote: ServerQuote | null): DesignGenerationQuote | null {
|
||||
if (!quote) return null;
|
||||
return {
|
||||
@@ -298,10 +325,10 @@ function mapQuote(quote: ServerQuote | null): DesignGenerationQuote | null {
|
||||
durationSeconds: quote.generation_parameters.duration_seconds,
|
||||
},
|
||||
generationOptions: {
|
||||
models: quote.generation_options.models,
|
||||
resolutions: quote.generation_options.resolutions,
|
||||
durations: quote.generation_options.durations,
|
||||
aspectRatios: quote.generation_options.aspect_ratios,
|
||||
models: mapGenerationOptions<string>(quote.generation_options.models),
|
||||
resolutions: mapGenerationOptions<string>(quote.generation_options.resolutions),
|
||||
durations: mapGenerationOptions<number>(quote.generation_options.durations),
|
||||
aspectRatios: mapGenerationOptions<string>(quote.generation_options.aspect_ratios),
|
||||
},
|
||||
pricing: {
|
||||
schema: quote.pricing.schema,
|
||||
|
||||
Reference in New Issue
Block a user