forked from 77media/video-flow
解决视频编辑编译报错问题
This commit is contained in:
parent
0824ea0af9
commit
5edc2abafa
@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { EditPoint } from '@/components/pages/work-flow/video-edit/types';
|
||||
import { EditPoint, EditPointStatus } from '@/components/pages/work-flow/video-edit/types';
|
||||
|
||||
// 引用主路由的存储(实际应用中应使用共享数据库)
|
||||
// 这里我们需要一个简单的方式来共享数据
|
||||
@ -72,7 +72,7 @@ export async function PUT(
|
||||
editPoint.position = { x: position_x, y: position_y };
|
||||
}
|
||||
|
||||
editPoint.updatedAt = new Date().toISOString();
|
||||
editPoint.updatedAt = Date.now();
|
||||
|
||||
// 保存更新
|
||||
setEditPointsStorage(storage);
|
||||
@ -207,8 +207,8 @@ export async function POST(
|
||||
|
||||
// 更新状态为处理中
|
||||
const editPoint = storage[editPointIndex];
|
||||
editPoint.status = 'processing';
|
||||
editPoint.updatedAt = new Date().toISOString();
|
||||
editPoint.status = EditPointStatus.PROCESSING;
|
||||
editPoint.updatedAt = Date.now();
|
||||
|
||||
setEditPointsStorage(storage);
|
||||
|
||||
|
||||
@ -114,8 +114,8 @@ export async function POST(request: NextRequest) {
|
||||
timestamp,
|
||||
description: description || '',
|
||||
status: status || EditPointStatus.PENDING,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
createdAt: Date.now(),
|
||||
updatedAt: Date.now(),
|
||||
showInput: false,
|
||||
connectionDirection: 'auto'
|
||||
};
|
||||
|
||||
@ -66,8 +66,8 @@ function createMockEditPoint(request: CreateEditPointRequest): EditPoint {
|
||||
timestamp: request.timestamp,
|
||||
description: request.description || '',
|
||||
status: EditPointStatus.PENDING,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
createdAt: Date.now(),
|
||||
updatedAt: Date.now(),
|
||||
showInput: true, // 新创建的编辑点应该显示输入框
|
||||
connectionDirection: 'auto'
|
||||
};
|
||||
@ -137,7 +137,8 @@ export async function createEditPoint(request: CreateEditPointRequest): Promise<
|
||||
} catch (error) {
|
||||
console.error('创建编辑点API调用失败:', error);
|
||||
// 如果真实API失败,回退到Mock
|
||||
if (!USE_MOCK_API) {
|
||||
const config = getVideoEditApiConfig();
|
||||
if (!config.useMockApi) {
|
||||
console.log('🔄 API失败,回退到Mock模式');
|
||||
const editPoint = createMockEditPoint(request);
|
||||
return editPoint;
|
||||
@ -176,7 +177,7 @@ export async function updateEditPoint(request: UpdateEditPointRequest): Promise<
|
||||
editPoint.position = request.position;
|
||||
}
|
||||
|
||||
editPoint.updatedAt = new Date().toISOString();
|
||||
editPoint.updatedAt = Date.now();
|
||||
saveMockData(); // 持久化保存
|
||||
debugLog('Mock编辑点更新成功', editPoint);
|
||||
return true;
|
||||
@ -202,7 +203,7 @@ export async function updateEditPoint(request: UpdateEditPointRequest): Promise<
|
||||
}
|
||||
|
||||
// 选择API端点
|
||||
const apiUrl = USE_LOCAL_API ? `/api/video-edit/edit-points/${request.id}` : `/video-edit/edit-points/${request.id}`;
|
||||
const apiUrl = config.useLocalApi ? `/api/video-edit/edit-points/${request.id}` : `/video-edit/edit-points/${request.id}`;
|
||||
|
||||
const response = await put<ApiResponse<EditPoint>>(apiUrl, updateData);
|
||||
|
||||
@ -216,7 +217,8 @@ export async function updateEditPoint(request: UpdateEditPointRequest): Promise<
|
||||
} catch (error) {
|
||||
console.error('更新编辑点API调用失败:', error);
|
||||
// 如果真实API失败,回退到Mock
|
||||
if (!USE_MOCK_API) {
|
||||
const config = getVideoEditApiConfig();
|
||||
if (!config.useMockApi) {
|
||||
console.log('🔄 API失败,回退到Mock模式');
|
||||
const editPointIndex = mockEditPoints.findIndex(point => point.id === request.id);
|
||||
if (editPointIndex !== -1) {
|
||||
@ -224,7 +226,7 @@ export async function updateEditPoint(request: UpdateEditPointRequest): Promise<
|
||||
if (request.description !== undefined) editPoint.description = request.description;
|
||||
if (request.status !== undefined) editPoint.status = request.status;
|
||||
if (request.position !== undefined) editPoint.position = request.position;
|
||||
editPoint.updatedAt = new Date().toISOString();
|
||||
editPoint.updatedAt = Date.now();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -239,8 +241,11 @@ export async function deleteEditPoint(request: DeleteEditPointRequest): Promise<
|
||||
try {
|
||||
console.log('删除编辑点请求:', request);
|
||||
|
||||
// 获取配置
|
||||
const config = getVideoEditApiConfig();
|
||||
|
||||
// 使用Mock API
|
||||
if (USE_MOCK_API) {
|
||||
if (config.useMockApi) {
|
||||
console.log('🔧 使用Mock API删除编辑点');
|
||||
await new Promise(resolve => setTimeout(resolve, 200)); // 模拟网络延迟
|
||||
|
||||
@ -256,7 +261,7 @@ export async function deleteEditPoint(request: DeleteEditPointRequest): Promise<
|
||||
}
|
||||
|
||||
// 选择API端点
|
||||
const apiUrl = USE_LOCAL_API ? `/api/video-edit/edit-points/${request.id}` : `/video-edit/edit-points/${request.id}`;
|
||||
const apiUrl = config.useLocalApi ? `/api/video-edit/edit-points/${request.id}` : `/video-edit/edit-points/${request.id}`;
|
||||
|
||||
const response = await del<ApiResponse<void>>(apiUrl);
|
||||
|
||||
@ -270,7 +275,8 @@ export async function deleteEditPoint(request: DeleteEditPointRequest): Promise<
|
||||
} catch (error) {
|
||||
console.error('删除编辑点API调用失败:', error);
|
||||
// 如果真实API失败,回退到Mock
|
||||
if (!USE_MOCK_API) {
|
||||
const config = getVideoEditApiConfig();
|
||||
if (!config.useMockApi) {
|
||||
console.log('🔄 API失败,回退到Mock模式');
|
||||
const editPointIndex = mockEditPoints.findIndex(point => point.id === request.id);
|
||||
if (editPointIndex !== -1) {
|
||||
@ -294,8 +300,11 @@ export async function getEditPoints(params: {
|
||||
try {
|
||||
console.log('获取编辑点列表请求:', params);
|
||||
|
||||
// 获取配置
|
||||
const config = getVideoEditApiConfig();
|
||||
|
||||
// 使用Mock API
|
||||
if (USE_MOCK_API) {
|
||||
if (config.useMockApi) {
|
||||
console.log('🔧 使用Mock API获取编辑点列表');
|
||||
await new Promise(resolve => setTimeout(resolve, 300)); // 模拟网络延迟
|
||||
|
||||
@ -326,7 +335,7 @@ export async function getEditPoints(params: {
|
||||
});
|
||||
|
||||
// 选择API端点
|
||||
const apiUrl = USE_LOCAL_API ? `/api/video-edit/edit-points?${queryParams}` : `/video-edit/edit-points?${queryParams}`;
|
||||
const apiUrl = config.useLocalApi ? `/api/video-edit/edit-points?${queryParams}` : `/video-edit/edit-points?${queryParams}`;
|
||||
|
||||
const response = await get<ApiResponse<{
|
||||
edit_points: any[];
|
||||
|
||||
@ -279,7 +279,7 @@ export async function attemptRecovery(
|
||||
/**
|
||||
* 完整的错误处理流程
|
||||
*/
|
||||
export async function handleApiError(error: any, endpoint?: string): Promise<never> {
|
||||
export async function handleApiError(error: any, endpoint?: string): Promise<any> {
|
||||
// 标准化错误格式
|
||||
const apiError: ApiError = error instanceof Error
|
||||
? createApiError(0, error.message, error, endpoint)
|
||||
|
||||
@ -125,7 +125,7 @@ export function useVideoEdit({
|
||||
|
||||
// 创建编辑上下文
|
||||
const context: VideoEditContext = useMemo(() => ({
|
||||
currentVideo,
|
||||
currentVideo: currentVideo || null,
|
||||
editPoints,
|
||||
config: mergedConfig,
|
||||
isEditMode,
|
||||
@ -174,10 +174,10 @@ export function useVideoEdit({
|
||||
|
||||
if (createdEditPoint) {
|
||||
// 更新为服务器返回的数据,但保持输入框显示状态
|
||||
const updatedEditPoint = {
|
||||
const updatedEditPoint: EditPoint = {
|
||||
...createdEditPoint,
|
||||
showInput: true, // 确保新创建的编辑点显示输入框
|
||||
connectionDirection: 'auto'
|
||||
connectionDirection: 'auto' as const
|
||||
};
|
||||
|
||||
setEditPoints(prev =>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user