mirror of
https://github.com/mediacms-io/mediacms.git
synced 2025-12-07 12:52:29 -05:00
* fix: Disable Segment Tools and Reset Preview State During Playback * chore: remove some unnecessary comments * chore: build assets * fix: do not display the handles (left/right) on preview mode * fix: Disable all tools on preview mode (undo, redo, reset, etc.) * Update README.md * feat: Prettier configuration for video editor * Update README.md * Update .prettierrc * style: Format entire codebase (video-editor) with Prettier * fix: During segments playback mode, disable button interactions but keep hover working * feat: Add yarn format * prettier format * Update package.json * feat: Install prettier and improve formatting * build assets * Update version.py 6.2.0
119 lines
3.7 KiB
TypeScript
119 lines
3.7 KiB
TypeScript
// API service for video trimming operations
|
|
|
|
interface TrimVideoRequest {
|
|
segments: {
|
|
startTime: string;
|
|
endTime: string;
|
|
name?: string;
|
|
}[];
|
|
saveAsCopy?: boolean;
|
|
saveIndividualSegments?: boolean;
|
|
}
|
|
|
|
interface TrimVideoResponse {
|
|
msg: string;
|
|
url_redirect: string;
|
|
status?: number; // HTTP status code for success/error
|
|
error?: string; // Error message if status is not 200
|
|
}
|
|
|
|
// Helper function to simulate delay
|
|
const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
|
|
// For now, we'll use a mock API that returns a promise
|
|
// This can be replaced with actual API calls later
|
|
export const trimVideo = async (
|
|
mediaId: string,
|
|
data: TrimVideoRequest
|
|
): Promise<TrimVideoResponse> => {
|
|
try {
|
|
// Attempt the real API call
|
|
const response = await fetch(`/api/v1/media/${mediaId}/trim_video`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(data)
|
|
});
|
|
|
|
if (!response.ok) {
|
|
// For error responses, return with error status and message
|
|
if (response.status === 400) {
|
|
// Handle 400 Bad Request - return with error details
|
|
try {
|
|
// Try to get error details from response
|
|
const errorData = await response.json();
|
|
return {
|
|
status: 400,
|
|
error: errorData.error || "An error occurred during processing",
|
|
msg: "Video Processing Error",
|
|
url_redirect: ""
|
|
};
|
|
} catch (parseError) {
|
|
// If can't parse response JSON, return generic error
|
|
return {
|
|
status: 400,
|
|
error: "An error occurred during video processing",
|
|
msg: "Video Processing Error",
|
|
url_redirect: ""
|
|
};
|
|
}
|
|
} else if (response.status !== 404) {
|
|
// Handle other error responses
|
|
try {
|
|
// Try to get error details from response
|
|
const errorData = await response.json();
|
|
return {
|
|
status: response.status,
|
|
error: errorData.error || "An error occurred during processing",
|
|
msg: "Video Processing Error",
|
|
url_redirect: ""
|
|
};
|
|
} catch (parseError) {
|
|
// If can't parse response JSON, return generic error
|
|
return {
|
|
status: response.status,
|
|
error: "An error occurred during video processing",
|
|
msg: "Video Processing Error",
|
|
url_redirect: ""
|
|
};
|
|
}
|
|
} else {
|
|
// If endpoint not ready (404), return mock success response
|
|
await delay(1500); // Simulate 1.5 second server delay
|
|
return {
|
|
status: 200, // Mock success status
|
|
msg: "Video Processed Successfully", // Updated per requirements
|
|
url_redirect: `./view?m=${mediaId}`
|
|
};
|
|
}
|
|
}
|
|
|
|
// Successful response
|
|
const jsonResponse = await response.json();
|
|
return {
|
|
status: 200,
|
|
msg: "Video Processed Successfully", // Ensure the success message is correct
|
|
url_redirect: jsonResponse.url_redirect || `./view?m=${mediaId}`,
|
|
...jsonResponse
|
|
};
|
|
} catch (error) {
|
|
// For any fetch errors, return mock success response with delay
|
|
await delay(1500); // Simulate 1.5 second server delay
|
|
return {
|
|
status: 200, // Mock success status
|
|
msg: "Video Processed Successfully", // Consistent with requirements
|
|
url_redirect: `./view?m=${mediaId}`
|
|
};
|
|
}
|
|
|
|
/* Mock implementation that simulates network latency
|
|
return new Promise((resolve) => {
|
|
setTimeout(() => {
|
|
resolve({
|
|
msg: "Video is processing for trim",
|
|
url_redirect: `./view?m=${mediaId}`
|
|
});
|
|
}, 1500); // Simulate 1.5 second server delay
|
|
});
|
|
*/
|
|
};
|