Align podcast chart preview route and preview URL handling
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import React, { createContext, useContext, useState, useEffect, useCallback, ReactNode } from "react";
|
||||
import { Script, Knobs, Scene, PodcastMode } from "../types";
|
||||
import { podcastApi } from "../../../services/podcastApi";
|
||||
import { getApiUrl } from "../../../api/client";
|
||||
|
||||
interface ScriptEditorContextType {
|
||||
// State
|
||||
@@ -58,6 +59,13 @@ interface ScriptEditorContextType {
|
||||
|
||||
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 {
|
||||
children: ReactNode;
|
||||
projectId: string;
|
||||
@@ -413,7 +421,7 @@ export const ScriptEditorProvider: React.FC<ScriptEditorProviderProps> = ({
|
||||
|
||||
return {
|
||||
...scene,
|
||||
broll_preview_url: result.preview_url,
|
||||
broll_preview_url: toUsablePreviewUrl(result.preview_url),
|
||||
chart_id: result.chart_id,
|
||||
};
|
||||
} catch (err) {
|
||||
@@ -451,7 +459,7 @@ export const ScriptEditorProvider: React.FC<ScriptEditorProviderProps> = ({
|
||||
|
||||
const updatedScenes = activeScript.scenes.map((s) =>
|
||||
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
|
||||
);
|
||||
|
||||
@@ -547,4 +555,4 @@ export const useScriptEditor = (): ScriptEditorContextType => {
|
||||
throw new Error("useScriptEditor must be used within ScriptEditorProvider");
|
||||
}
|
||||
return context;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -967,8 +967,10 @@ export const podcastApi = {
|
||||
chart_data: Record<string, any>;
|
||||
chart_type: string;
|
||||
title: string;
|
||||
}): Promise<{ image_url: string; preview_url: string; chart_id: string }> {
|
||||
const response = await aiApiClient.post('/api/podcast/chart/preview', params);
|
||||
}): Promise<{ preview_url: string; chart_id: string }> {
|
||||
// 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;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user