80 lines
2.2 KiB
TypeScript
80 lines
2.2 KiB
TypeScript
|
|
import { VideoHistoryItem } from '../types';
|
|
|
|
const API_ENDPOINT_1="https://o2odev.app.n8n.cloud/webhook/get_video_list"
|
|
const API_ENDPOINT_2="https://o2odev.app.n8n.cloud/webhook/upload_image_path"
|
|
const API_ENDPOINT_3="https://o2odev.app.n8n.cloud/webhook/ado3"
|
|
const API_ENDPOINT_4="https://o2odev.app.n8n.cloud/webhook/mysql-api"
|
|
|
|
export const fetchVideoHistory = async (): Promise<VideoHistoryItem[]> => {
|
|
try {
|
|
const response = await fetch(API_ENDPOINT_1);
|
|
if (!response.ok) {
|
|
console.error("Failed to fetch history");
|
|
return [];
|
|
}
|
|
const data = await response.json();
|
|
return Array.isArray(data) ? data : [];
|
|
} catch (error) {
|
|
console.error("Error fetching video history:", error);
|
|
return [];
|
|
}
|
|
};
|
|
|
|
export const sendImageManifest = async (manifest: { task_id: string; img_url: string }[]) => {
|
|
const url = API_ENDPOINT_2;
|
|
|
|
console.log(manifest)
|
|
const response = await fetch(url, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(manifest)
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`Failed to send image manifest: ${response.statusText}`);
|
|
}
|
|
|
|
return response.json();
|
|
};
|
|
|
|
export const submitJobMetadata = async (data: any) => {
|
|
const url = API_ENDPOINT_3;
|
|
|
|
console.log(data)
|
|
const response = await fetch(url, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(data)
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`Failed to submit job metadata: ${response.statusText}`);
|
|
}
|
|
|
|
return true;
|
|
};
|
|
|
|
export const fetchTableData = async (task_id: string, tableName: 'lyrics' | 'song' | 'creatomate_result_url') => {
|
|
const url = API_ENDPOINT_4;
|
|
|
|
try {
|
|
// Calls API 4 with ?task_id=UUID&table=TABLE_NAME
|
|
const response = await fetch(`${url}?task_id=${task_id}&table=${tableName}`, {
|
|
method: 'GET'
|
|
});
|
|
|
|
if (!response.ok) {
|
|
// If 404, it likely means that step isn't done yet
|
|
return null;
|
|
}
|
|
var result = await response.json()
|
|
console.log(result[0])
|
|
// The API seems to return an array, grab the first item if so
|
|
return Array.isArray(result) ? result[0] : result;
|
|
} catch (error) {
|
|
//console.error(`Error fetching table ${tableName}:`, error);
|
|
return [];
|
|
}
|
|
};
|