Merge remote-tracking branch 'origin/codex/standardize-chart-preview-route-usage'
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import React, { createContext, useContext, useState, useEffect, useCallback, ReactNode } from "react";
|
import React, { createContext, useContext, useState, useEffect, useCallback, ReactNode } from "react";
|
||||||
import { Script, Knobs, Scene, PodcastMode } from "../types";
|
import { Script, Knobs, Scene, PodcastMode } from "../types";
|
||||||
import { podcastApi } from "../../../services/podcastApi";
|
import { podcastApi } from "../../../services/podcastApi";
|
||||||
|
import { getApiUrl } from "../../../api/client";
|
||||||
|
|
||||||
interface ScriptEditorContextType {
|
interface ScriptEditorContextType {
|
||||||
// State
|
// State
|
||||||
@@ -58,6 +59,13 @@ interface ScriptEditorContextType {
|
|||||||
|
|
||||||
const ScriptEditorContext = createContext<ScriptEditorContextType | undefined>(undefined);
|
const ScriptEditorContext = createContext<ScriptEditorContextType | undefined>(undefined);
|
||||||
|
|
||||||
|
const toUsablePreviewUrl = (previewUrl?: string): string | undefined => {
|
||||||
|
if (!previewUrl) return undefined;
|
||||||
|
if (/^https?:\/\//i.test(previewUrl)) return previewUrl;
|
||||||
|
const cleanPath = previewUrl.startsWith("/") ? previewUrl : `/${previewUrl}`;
|
||||||
|
return `${getApiUrl()}${cleanPath}`;
|
||||||
|
};
|
||||||
|
|
||||||
interface ScriptEditorProviderProps {
|
interface ScriptEditorProviderProps {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
@@ -413,7 +421,7 @@ export const ScriptEditorProvider: React.FC<ScriptEditorProviderProps> = ({
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
...scene,
|
...scene,
|
||||||
broll_preview_url: result.preview_url,
|
broll_preview_url: toUsablePreviewUrl(result.preview_url),
|
||||||
chart_id: result.chart_id,
|
chart_id: result.chart_id,
|
||||||
};
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -451,7 +459,7 @@ export const ScriptEditorProvider: React.FC<ScriptEditorProviderProps> = ({
|
|||||||
|
|
||||||
const updatedScenes = activeScript.scenes.map((s) =>
|
const updatedScenes = activeScript.scenes.map((s) =>
|
||||||
s.id === sceneId
|
s.id === sceneId
|
||||||
? { ...s, broll_preview_url: result.preview_url, chart_id: result.chart_id }
|
? { ...s, broll_preview_url: toUsablePreviewUrl(result.preview_url), chart_id: result.chart_id }
|
||||||
: s
|
: s
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -547,4 +555,4 @@ export const useScriptEditor = (): ScriptEditorContextType => {
|
|||||||
throw new Error("useScriptEditor must be used within ScriptEditorProvider");
|
throw new Error("useScriptEditor must be used within ScriptEditorProvider");
|
||||||
}
|
}
|
||||||
return context;
|
return context;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -967,8 +967,10 @@ export const podcastApi = {
|
|||||||
chart_data: Record<string, any>;
|
chart_data: Record<string, any>;
|
||||||
chart_type: string;
|
chart_type: string;
|
||||||
title: string;
|
title: string;
|
||||||
}): Promise<{ image_url: string; preview_url: string; chart_id: string }> {
|
}): Promise<{ preview_url: string; chart_id: string }> {
|
||||||
const response = await aiApiClient.post('/api/podcast/chart/preview', params);
|
// Canonical backend endpoint from api/podcast/handlers/broll.py after router prefix composition:
|
||||||
|
// /api/podcast (main router) + /broll (handler prefix) + /preview/chart (endpoint)
|
||||||
|
const response = await aiApiClient.post('/api/podcast/broll/preview/chart', params);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user